Add support for collecting time trace in the LLVM part #8546
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.
LLVM time profiler can collect time traces and present them in a hierarchical view. Which breakdowns the time spent in each Pass or even IR unit (e.g. how many time did we spent on optimizing & compiling a function). The result is also exported into a format that can be easily visualized by the Chrome browser.
Currently this features is only used for collecting time trace in the LLVM part and controlled by the following environment variables:
ZIG_ENABLE_LLVM_TIME_TRACE
toggles this featureZIG_LLVM_TIME_TRACE_FILE
specifies the output time trace file. Otherwise the result will be put in ".o.time-trace" or ".s.time-trace".ZIG_LLVM_TIME_TRACE_GRANULARITY
controls the time granularity in ms (default to 500).Here is an example usage:
$ env ZIG_ENABLE_LLVM_TIME_TRACE=1 ZIG_LLVM_TIME_TRACE_FILE=foo.time-trace.json zig build-exe foo.zig
foo.time-trace.json
.Then you'll get a nice breakdown on the time spent on each Pass and each function LLVM compiled. Alternatively you can also visualize the time trace file using this website: https://www.speedscope.app
The only thing I would like to discuss with everyone here is that should we use command line flag to toggle this feature rather than environment variable?