# scope_profiler.chrome_trace_export

*module*

Export profiling runs to the Chrome Trace Event format.

The format is understood by ``chrome://tracing`` and Perfetto. Each rank is a
process and each recorded thread or asyncio task is a lane in that process.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/chrome_trace_export.py#L1-L1)

## scope_profiler.chrome_trace_export.build_chrome_trace_document

*function*

```python
def build_chrome_trace_document(run: ProfilingResults, label: str | None = None, ranks: list[int] | int | None = None, include: list[str] | str | None = None, exclude: list[str] | str | None = None) -> dict
```

Build one Chrome Trace Event document from a profiling run.

Region durations are emitted in microseconds, as required by the Chrome
Trace Event format. GPU and await measurements are preserved in event
arguments. Aggregate perf counters are emitted as counter events at the
end of their rank timeline.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/chrome_trace_export.py#L38-L152)

## scope_profiler.chrome_trace_export.export_chrome_trace

*function*

```python
def export_chrome_trace(profiling_data: ProfilingResults | Sequence[ProfilingResults], filepath: str | Path, ranks: list[int] | int | None = None, include: list[str] | str | None = None, exclude: list[str] | str | None = None, verbose: bool = True) -> list[Path]
```

Write Chrome Trace JSON files, one per input profiling run.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/chrome_trace_export.py#L164-L196)

## scope_profiler.chrome_trace_export.write_chrome_trace_file

*function*

```python
def write_chrome_trace_file(filepath: str | Path, document: dict) -> Path
```

Write a Chrome Trace Event document to ``filepath``.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/chrome_trace_export.py#L155-L161)
