Parse a chrome trace and return aggregate scope durations (in cycles).
(path: Path)
| 17 | |
| 18 | |
| 19 | def parse_chrome_trace(path: Path) -> dict | None: |
| 20 | """Parse a chrome trace and return aggregate scope durations (in cycles).""" |
| 21 | path = Path(path) |
| 22 | if not path.exists(): |
| 23 | return None |
| 24 | data = json.load(path.open()) |
| 25 | events = data["traceEvents"] |
| 26 | if not events: |
| 27 | return None |
| 28 | |
| 29 | scope_dur: dict[str, float] = defaultdict(float) |
| 30 | scope_cnt: dict[str, int] = defaultdict(int) |
| 31 | for e in events: |
| 32 | scope_dur[e["name"]] += e["dur"] |
| 33 | scope_cnt[e["name"]] += 1 |
| 34 | |
| 35 | total = sum(scope_dur.values()) |
| 36 | if total == 0: |
| 37 | return None |
| 38 | return {"scopes": dict(scope_dur), "counts": dict(scope_cnt), "total_cycles": total} |
| 39 | |
| 40 | |
| 41 | def trace_phase_pcts(trace: dict) -> dict[str, float]: |
no outgoing calls
no test coverage detected