Add a callable library function to parse_trace.py#2712
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR makes python/utils/parse_trace.py importable as a library and adds a callable parse_trace() function that can process trace data programmatically. The command-line interface is preserved by refactoring the script execution code into a main() function.
Key changes:
- Adds
parse_trace()library function that accepts numpy arrays and MLIR strings, returning trace events in Chrome Trace Event Format - Refactors existing script logic into
main()function to enable library usage while preserving CLI functionality - Adds integration test demonstrating the API usage with event trace validation
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| python/utils/parse_trace.py | Adds library API parse_trace() function and refactors command-line logic into main() function; updates helper functions to accept optional of and debug parameters |
| test/npu-xrt/vec_mul_event_trace/test.py | Integration test that uses the new parse_trace() API to validate trace events from NPU execution |
| test/npu-xrt/vec_mul_event_trace/vector_scalar_mul.cc | AIE kernel implementation for vector-scalar multiplication with event markers |
| test/npu-xrt/vec_mul_event_trace/aie.mlir | MLIR configuration defining trace packet flows, control registers, and buffer descriptors |
Comments suppressed due to low confidence (1)
python/utils/parse_trace.py:57
- [nitpick] When
parse_traceis called as a library function, printing error messages to stderr and returning False fromcheck_for_valid_tracecauses the calling code to raise a ValueError on line 971. However, the error messages on lines 47-55 are still printed to stderr before the ValueError is raised. Consider removing these print statements from the library path since the exception message should be sufficient, or make the error messages conditional on whether this is being called from the library API vs command line.
def check_for_valid_trace(filename, trace_pkts, of=None, debug=False):
if debug and of:
print("len(trace_pkts): ", str(len(trace_pkts)), file=of)
print("trace_pkts[0]:", trace_pkts[0], file=of)
if len(trace_pkts) < 2 or trace_pkts[0] == "00000000":
print(
"[ERROR] Empty trace file. Valid trace was not written to",
filename,
file=sys.stderr,
)
print(
"See https://github.com/Xilinx/mlir-aie/tree/main/programming_guide/section-4/section-4b#Additional-Debug-Hints for additional trace debug tips.",
file=sys.stderr,
)
return False
return True
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
93f60dd to
733652a
Compare
fifield
commented
Nov 18, 2025
2665c2c to
5504d5e
Compare
5504d5e to
f10e518
Compare
fifield
commented
Nov 18, 2025
jgmelber
approved these changes
Nov 23, 2025
kurtis-b
pushed a commit
to kurtis-b/mlir-aie
that referenced
this pull request
Dec 20, 2025
Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR:
python/utils/parse_trace.pyimportable andparse_tracethat operates similar to the command line. The command line version is unchanged.test/npu-xrt/vec_mul_event_tracewhich generates trace then callsparse_traceand checks the trace from the python host code.