Visualizing external trace formats with Perfetto

In this guide, you'll learn about:

Perfetto is capable of opening and analyzing trace files generated by a variety of external tools and systems, not just its own native protobuf format. You might have existing traces in these formats if:

The main advantages of using Perfetto to examine these external traces are its powerful analysis and visualization capabilities:

Below, we detail the supported formats, provide context on their typical use cases, and outline what to expect when loading them into Perfetto.

Chrome JSON format

Description: The Chrome JSON trace format consists of a JSON array of event objects. Each object represents a single trace event and typically includes fields like pid (process ID), tid (thread ID), ts (timestamp in microseconds), ph (phase, indicating event type like begin, end, instant, counter, etc.), name (event name), cat (category), and args (event-specific arguments). This format was originally developed for Chrome's about:tracing (now chrome://tracing) tool.

Common Scenarios: While Chromium browser developers now primarily use Perfetto's native protobuf format for trace collection, the Chrome JSON format is still encountered in several situations:

Perfetto Support:

How to Generate:

External Resources:

Firefox Profiler JSON format

Description: The Firefox Profiler JSON format is primarily known for its use by the Firefox Profiler, a web-based tool for performance analysis. While the format can describe various types of timeline data including "markers" (similar to trace events), its main strength, and Perfetto's primary interest in it, lies in representing CPU profiling data, especially sampled call stacks. This makes it an excellent target format for visualizing flamegraphs and call trees from various profiling sources.

Common Scenarios: The most common reason Perfetto users encounter this format is for:

Perfetto Support:

How to Generate: The most relevant generation path for Perfetto users involves converting native CPU profiles from Linux perf or Android simpleperf.

  1. Record a profile with perf record: Capture CPU samples for a specific command/process or system-wide, generating a perf.data file.

    # Example: Profile at 99Hz for 1 seconds with DWARF call graphs sudo perf record -F 99 -g --call-graph dwarf --output perf.data -- find ~ -name 'foo'

    Refer to man perf-record for detailed command options. Ensure debug symbols for your binaries are accessible for proper symbolization.

  2. Convert perf.data to Firefox Profiler JSON: Use the gecko report script with perf script.

    sudo perf script report gecko --save-only my_linux_profile.json

    This command processes the perf.data file and outputs my_linux_profile.json in a format compatible with the Firefox Profiler. If report gecko is not available in your perf version, consult your distribution's documentation for alternatives or additional perf scripting packages.

  3. Open this trace in ui.perfetto.dev

    Navigate to ui.perfetto.dev and upload the my_linux_profile.json file into the UI. Once the trace opens, you should be able select either individual CPU samples or ranges of time containing CPU samples to get a flamegraph of all the samples in that region.

    Here's an example of what that looks like

On Android, simpleperf is used for CPU profiling. The necessary Python scripts (app_profiler.py, gecko_profile_generator.py) can be obtained by cloning them directly from the Android Open Source Project (AOSP).

  1. Clone the simpleperf scripts from AOSP: This command performs a shallow clone of the platform/system/extras repository, which contains simpleperf and its scripts. This helps to minimize the download size.

    git clone https://android.googlesource.com/platform/system/extras --depth=1

    After cloning, the scripts will be located in the extras/simpleperf/ subdirectory (e.g., ./extras/simpleperf/app_profiler.py). Note: This method provides the scripts. You will also need a compatible simpleperf binary. This binary is typically available on your Android device (if it supports profiling) and app_profiler.py will attempt to use it. Ensure any Python dependencies for the scripts are also met in your host environment.

  2. Record a profile using app_profiler.py: This script automates profiling a specific app.

    # Path to the simpleperf directory from your AOSP clone SIMPLEPERF_SCRIPT_DIR=./extras/simpleperf # Replace <your.app.package.name> python ${SIMPLEPERF_SCRIPT_DIR}/app_profiler.py \ --app <your.app.package.name> \ -r "-g --duration 10" \ -o ./simpleperf_output
    • This command profiles the specified app for 10 seconds with DWARF call graphs (-g).
    • It saves perf.data and a binary_cache (for symbols) into the ./simpleperf_output directory on your host machine.
    • For more details, run python ${SIMPLEPERF_SCRIPT_DIR}/app_profiler.py --help and consult the Simpleperf documentation.
  3. Convert simpleperf data to Firefox Profiler JSON: Use the gecko_profile_generator.py script from the same AOSP checkout.

    # Path to the simpleperf directory from your AOSP clone SIMPLEPERF_SCRIPT_DIR=./extras/simpleperf python ${SIMPLEPERF_SCRIPT_DIR}/gecko_profile_generator.py \ -i ./simpleperf_output/perf.data \ --symfs ./simpleperf_output/binary_cache \ -o my_android_profile.json
    • This converts the simpleperf data, using symbols from the binary_cache, into the Firefox Profiler JSON format.
  4. Open this trace in ui.perfetto.dev

    Navigate to ui.perfetto.dev and upload the my_android_profile.json file into the UI. Once the trace opens, you should be able select either individual CPU samples or ranges of time containing CPU samples to get a flamegraph of all the samples in that region.

    Here's an example of what that looks like

Other methods (less common for Perfetto import scenarios):

External Resources:

Android systrace format

Description: Android Systrace was the legacy system-wide tracing tool for Android, used primarily before the introduction of Perfetto with Android 9 (Pie). It captures kernel activity via ftrace (e.g., CPU scheduling, I/O) and userspace annotations via ATrace (e.g., android.os.Trace). Systrace typically produces an interactive HTML file embedding trace data in a text-based format.

Common Scenarios (Primarily Legacy): You will typically only encounter the Android Systrace format when dealing with older data or legacy workflows, such as:

For any current or new tracing on Android (version 9 Pie and newer), Perfetto is the standard and strongly recommended tool.

Perfetto Support:

How to Generate (Legacy Methods): The methods below describe how Systrace files were historically created and are provided for context when dealing with older traces. These methods are deprecated and should not be used for new trace collection on Android 9 (Pie) or newer.

External Resources:

Perf textual format (from perf script)

Description: The "Perf textual format" typically refers to the human-readable textual output generated by the perf script command on Linux. This command processes a perf.data file (created by perf record) and prints a chronological log of the recorded events. The output is highly configurable via perf script options but commonly includes CPU samples with their call stacks, timestamps, process/thread identifiers, CPU number, and event names.

Common Scenarios: This format is often used for:

Perfetto Support:

How to Generate:

  1. Record a profile with perf record: First, capture profiling data using perf record. This creates a perf.data file.

    # Example: Profile at 99Hz for 1 seconds with DWARF call graphs sudo perf record -F 99 -g --call-graph dwarf --output perf.data -- find ~ -name 'foo'

    Refer to man perf-record for detailed command options. Ensure debug symbols for your binaries are accessible for proper symbolization by perf script.

  2. Generate textual output with perf script: Process the perf.data file to produce the textual output.

    # Default output sudo perf script -i perf.data > my_perf_output.txt

    For more detailed output that is often useful for other tools (and potentially for Perfetto's parser if it looks for specific fields), you might specify the fields:

    perf script -i perf.data -F comm,pid,tid,cpu,time,event,ip,sym,dso,trace > my_perf_output_detailed.txt

    Refer to man perf-script for its extensive formatting options.

  3. Open this trace in ui.perfetto.dev

    Navigate to ui.perfetto.dev and upload the my_perf_output.txt file into the UI. Once the trace opens, you should be able select either individual CPU samples or ranges of time containing CPU samples to get a flamegraph of all the samples in that region.

    Here's an example of what that looks like

Linux ftrace textual format

Description: The Linux ftrace textual format is the raw, human-readable output generated by the Linux kernel's ftrace tracing infrastructure. Each line in this text-based format typically represents a single trace event and follows a common structure: TASK-PID CPU# [MARKERS] TIMESTAMP FUNCTION --- ARGS. For example, a sched_switch event might look like: bash-1234 [002] ...1 5075.958079: sched_switch: prev_comm=bash prev_pid=1234 prev_prio=120 prev_state=R ==> next_comm=trace-cmd next_pid=5678 next_prio=120. This format can be quite verbose but is fundamental to how ftrace operates and is exposed via the tracefs filesystem (usually mounted at /sys/kernel/tracing).

Common Scenarios: You are likely to encounter or use this format when:

Perfetto Support: Perfetto's support for the ftrace textual format is primarily for legacy compatibility and is maintained on a best-effort basis.

How to Generate (for context on existing logs): These methods describe how ftrace textual logs are typically created using tracefs (usually mounted at /sys/kernel/tracing). For new tracing, prefer using Perfetto's ftrace data source directly.

External Resources:

ART method tracing format

Description: The Android Runtime (ART) method tracing format (commonly found in .trace files) is a binary format specific to Android. It captures detailed information about the execution of Java and Kotlin methods within an Android application, essentially logging the entry and exit points of each called method. This allows for a fine-grained analysis of an app's runtime behavior at the method level.

Common Scenarios: This format is typically used when:

Perfetto Support:

How to Generate:

External Resources:

macOS Instruments format (XML export)

Description: Apple's Instruments tool, part of Xcode, is used for performance analysis on macOS and iOS. While Instruments saves its full data in a proprietary .trace package format, Perfetto's support focuses on an XML format that can be exported from these Instruments traces. This XML export is primarily useful for extracting CPU profiling data (stack samples).

Common Scenarios: This import path is relevant when:

Perfetto Support:

How to Generate: Traces are originally collected using the Instruments application in Xcode or the xctrace command-line utility, which produce a .trace package. The XML file that Perfetto ingests is an export from such a trace. (The specific steps for exporting to this XML format from Instruments would need to be followed within the Instruments tool itself; Perfetto then consumes the resulting XML file).

External Resources:

External Resources:

Ninja logs format (.ninja_log)

Description: The Ninja build system, known for its speed and use in projects like Chromium and Android, generates a log file typically named .ninja_log. This file is a tab-separated text file that records metadata about each command (build step) executed during the build process. Key information for each entry includes the start time (in milliseconds), end time (in milliseconds), the restat mtime (in milliseconds), the primary output file path of the build step, and a hash of the command itself. The format is versioned, with new versions occasionally adding fields.

Common Scenarios: This format is used when:

Perfetto Support:

How to Generate:

External Resources:

Android logcat textual format

Description: Android logcat is the command-line tool used to access messages from Android's system-wide logging service, logd. The textual output from adb logcat is what Perfetto can import. This output can vary significantly based on the formatting options specified (e.g., via adb logcat -v <format>), but typically includes a timestamp, log priority (Verbose, Debug, Info, Warn, Error, Fatal/Assert), a tag identifying the source of the log, the Process ID (PID), often the Thread ID (TID), and the log message itself.

Common Scenarios: You might work with textual logcat files when:

Perfetto Support:

How to Generate Textual Logcat Files:

External Resources:

Android bugreport zip format (.zip)

Description: An Android bugreport is a .zip archive generated by Android devices, containing a comprehensive snapshot of diagnostic information from an Android device at a particular point in time. This archive bundles various logs (like logcat), system properties, process information, stack traces for ANRs and crashes, and importantly, a system trace (typically a Perfetto trace on modern Android versions). It also contains detailed dumpstate output, which includes board-level information and specific service dumps like batterystats.

Common Scenarios: Bugreport zip files are primarily used for:

Perfetto Support:

How to Generate:

External Resources:

Fuchsia tracing format (.fxt)

Description: The Fuchsia trace format (typically found in .fxt files) is a binary format used by the Fuchsia operating system. It's designed for high-performance, low-overhead recording of diagnostic information from both userspace components and the Zircon kernel. The format features compact, memory-aligned records and is extensible, with trace data often written directly into Zircon Virtual Memory Objects (VMOs) for efficiency.

Common Scenarios: This format is primarily encountered when:

Perfetto Support:

How to Generate:

External Resources: