The `perfetto` Python library provides APIs and bindings for Perfetto (perfetto.dev), an open-source system profiling, app tracing, and trace analysis platform. It allows users to interact with the Perfetto Trace Processor, enabling the use of Python's rich data analysis ecosystem for processing traces. Currently, the library is in an 'Alpha' development stage (v0.16.0), indicating ongoing development and potential API changes. Releases are made periodically to introduce new features and address issues.
pip install perfettoVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `TraceProcessor` with a Perfetto trace file and query for basic slice events. It uses a `with` statement for proper resource management. Ensure you replace the placeholder trace file path with a valid Perfetto trace.
Review SQL queries involving `thread`, `slice`, and `TrackEvent` tables. For `thread.arg_set_id`, qualify the column name. For stack IDs, migrate to functions in `slices.stack` stdlib module. Adjust queries for `machine_id` nullability. Refer to the Perfetto SQL backcompat documentation for migration guidance.
Update `TraceConfig` usage to use `write_flush_mode`. For `traced_relay`, explicitly set `TraceConfig.trace_all_machines = True` if remote producer matching is desired.
Adjust parsing logic for `TrackEvent` log messages to access the message under the `.message` sub-field.
Be prepared for API changes and regularly check the official documentation and GitHub changelog for updates. Pin your dependency to a specific minor version if stability is critical.
Ensure Python 3.9.1 or a later version is installed and used on ARM-based macOS systems.
Process traces in smaller batches or utilize systems with ample RAM when working with a large number of traces. Consult the documentation on managing trace loading for details.
Install the perfetto library using pip: `pip install perfetto`
Increase the startup timeout for the trace processor by setting `load_timeout` in `TraceProcessorConfig` (e.g., `TraceProcessor(trace='trace.perfetto-trace', config=TraceProcessorConfig(load_timeout=10))`). Ensure there are no connectivity issues preventing the download of the pre-built binary, or specify a local `bin_path` if you have a custom-built trace processor.
Iterate directly over the `QueryResultIterator` or convert it to a different data structure (like a Pandas DataFrame) instead of trying to call it. Example: `for row in qr_it: print(row.ts)` or `df = qr_it.as_pandas_dataframe()`.