-
Notifications
You must be signed in to change notification settings - Fork 7
trace: add CTF to Perfetto protobuf conversion tools #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @adamgreloch, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
Hello! Gemini here, providing a summary of this pull request. This PR introduces new tools to convert Common Trace Format (CTF) traces into formats compatible with modern tracing visualization tools, specifically the Chrome Trace Event Format (JSON) and the Perfetto trace protobuf format. This conversion is achieved using the babeltrace2 library to read the CTF traces and then mapping the events to the respective output formats. This will significantly improve the ability to analyze and visualize trace data generated by the system.
Highlights
- CTF to JSON Conversion: A new Python script (
trace/json/ctf_to_json.py) is added to convert CTF traces into a JSON format that is compatible with tools like Chrome'schrome://tracing. It parses CTF events, identifies synthetic events (like syscalls, scheduling, locking), and outputs them as JSON objects with appropriate phases (BEGIN, END, INSTANT) and metadata (process/thread IDs, timestamps, arguments). - CTF to Perfetto Protobuf Conversion: A second new Python script (
trace/protobuf/src/ctf_to_proto.py) is introduced to convert CTF traces into the Perfetto trace protobuf format. This script utilizes the Perfetto protobuf definition (downloaded and compiled by a helper script) and maps CTF events to Perfetto'sTracePacketandTrackEventstructures, including managing track descriptors for processes, threads, and CPUs. - Perfetto Protobuf Setup Script: A shell script (
trace/protobuf/proto_gen.sh) is added to automate the setup required for the Perfetto protobuf conversion tool. This script downloads the necessaryperfetto_trace.protofile from the Perfetto repository and compiles it into Python code usingprotoc.
Changelog
Click here to see the changelog
- trace/json/ctf_to_json.py
- Added new Python script for converting CTF traces to JSON (Chrome Trace Event Format).
- Implements parsing of CTF events using
babeltrace2. - Defines mappings for Phoenix-RTOS syscalls and synthetic events.
- Generates JSON output with event phases (BEGIN, END, INSTANT) and associated metadata.
- trace/protobuf/proto_gen.sh
- Added new shell script to download the Perfetto trace protobuf definition.
- Compiles the
.protofile into Python code usingprotoc.
- trace/protobuf/src/ctf_to_proto.py
- Added new Python script for converting CTF traces to Perfetto trace protobuf format.
- Uses
babeltrace2to read CTF and the generated Perfetto protobuf classes. - Maps CTF events to Perfetto
TracePacketandTrackEventstructures. - Manages track descriptors for processes, threads, and CPUs.
- Outputs serialized Perfetto trace data to a binary file (
out.pftrace).
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Traces flow like streams,
Events captured, kernel dreams.
JSON, Proto bright,
Visualize the system's light,
Performance takes its flight.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
b32c3c9 to
3765ca3
Compare
3765ca3 to
2ee444d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces two new Python scripts for converting CTF (Common Trace Format) traces: one to JSON (ETF-like format) and another to Perfetto protobuf format. A shell script for generating Python protobuf stubs is also included. The initiative to support these formats is valuable for trace analysis.
The scripts are generally well-structured and follow a similar pattern for processing events. However, there are a few areas that could be improved for robustness and usability, particularly concerning metadata handling, potential KeyErrors, and I/O efficiency in the protobuf converter.
Please also ensure the PR description (JIRA link, motivation, testing, checklist) is filled out to provide complete context for the changes.
Summary of Findings
- Metadata Handling Fragility: Both
ctf_to_json.pyandctf_to_proto.pyrely on the first processed event containing a specific["threads"]array in its stream context for initial metadata. This could be fragile if the first event lacks this context, potentially leading to runtime errors or incomplete traces. - Potential KeyError for TID 0: Both scripts use
tid_or_zerowhich can return0. If TID0is not explicitly part of the initial metadata or created via athread_createevent, subsequent lookups in dictionaries keyed bytid(e.g.,tid_to_pid,tid_to_events_track_uid) will cause aKeyError. - Inefficient Protobuf Serialization:
ctf_to_proto.pyrepeatedly creates, serializes, and writesTraceobjects containing very few packets inupdate_running_thread. Batching packets for a single serialization at the end would likely be more performant. - Hardcoded Output Filename:
ctf_to_proto.pyuses a hardcoded output filename (out.pftrace), which reduces flexibility. Making this a command-line argument is recommended. - PR Description: The pull request description template (JIRA, motivation, testing, etc.) should be filled out to provide full context for the changes.
Merge Readiness
The pull request introduces useful conversion tools. However, there are several medium-severity issues related to robustness, efficiency, and usability that should be addressed before merging. Specifically, improving metadata loading, handling potential KeyErrors for TIDs, optimizing protobuf serialization, and allowing a configurable output path for the protobuf script would significantly enhance the quality of these tools. I am unable to approve the pull request myself; please ensure these changes are reviewed and approved by others before merging once the suggested changes are made.
ab051f7 to
b85d46a
Compare
b85d46a to
d16d93b
Compare
b5be1c9 to
b9c7b98
Compare
ae08b2f to
f933469
Compare
f933469 to
8b55522
Compare
a801889 to
8361138
Compare
6cd8073 to
48a913c
Compare
71a43ba to
8cee11c
Compare
8cee11c to
8d0748f
Compare
9d19f75 to
2a2bc7f
Compare
b06cf21 to
61bb4d2
Compare
61bb4d2 to
792c638
Compare
This change adds the following utils: * ctf_to_proto.py - utility script for converting CTF trace to perfetto * trim_event_stream.subr - event stream trimmer/fixer in case of rolling-window trace * ia32_convert.sh - end-user utility that pulls out the trace directory from ia32 qemu disk image and invokes convert.sh * collect_rtt_trace.py - Trace-over-RTT collector that runs OpenOCD with a given config and collects data from its RTT channel sockets * convert.sh - end-user utility that prepares raw CTF trace for babeltrace parsing, uses the above utils underneath JIRA: RTOS-1061
792c638 to
a7d996d
Compare
JIRA: RTOS-1061
Description
Motivation and Context
Types of changes
How Has This Been Tested?
Checklist:
Special treatment
perf: adapt to new perf subsystem phoenix-rtos-utils#238