Created
July 19, 2022 15:27
-
-
Save ThomasParistech/c7765206bbb8da4240d54e169540912e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from typing import Dict | |
from typing import List | |
from typing import Union | |
def export_profiling_events(output_path: str): | |
""" | |
Dump profiling events into a JSON file that can be provided | |
to the Chrome Tracing Viewer | |
""" | |
if not PROFILE: | |
return | |
events: List[Dict[str, Union[str, int, float]]] = [] | |
while not PROFILING_EVENTS_QUEUE.empty(): | |
name, tid, t_begin, t_end = PROFILING_EVENTS_QUEUE.get() | |
events.append({"name": name, "ph": "B", | |
"ts": t_begin*1e6, "tid": tid, "pid": 0}) | |
events.append({"name": name, "ph": "E", | |
"ts": t_end*1e6, "tid": tid, "pid": 0}) | |
with open(output_path, "w", encoding="utf-8") as _f: | |
json.dump({"traceEvents": events}, _f) | |
print("Open Chrome, type chrome://tracing/ and " | |
f"load the file located at {os.path.abspath(output_path)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment