Skip to content
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

Add support for collecting time trace in the LLVM part #8546

Merged
merged 1 commit into from
Jun 4, 2021

Conversation

mshockwave
Copy link
Contributor

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 feature
  • ZIG_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:

  1. $ env ZIG_ENABLE_LLVM_TIME_TRACE=1 ZIG_LLVM_TIME_TRACE_FILE=foo.time-trace.json zig build-exe foo.zig
  2. Open Chrome and type "chrome://tracing" in the URL bar.
  3. Click the "Load" button at the top-left corner to load 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?

@jedisct1
Copy link
Contributor

jedisct1 commented May 1, 2021

This is very nice, thank you!

Since this is mainly useful for optimizing the compiler itself, enabling it via environment variables looks like a good choice to me, but others may have a different opinion :)

Are two environment variables required, though? Why not just enable this if ZIG_LLVM_TIME_TRACE_FILE is defined?

@jedisct1
Copy link
Contributor

jedisct1 commented Jun 3, 2021

Are two environment variables required, though? Why not just enable this if ZIG_LLVM_TIME_TRACE_FILE is defined?

Ping :)

@mshockwave
Copy link
Contributor Author

Are two environment variables required, though? Why not just enable this if ZIG_LLVM_TIME_TRACE_FILE is defined?

Ping :)

I’m so sorry, somehow I didn’t get notified of your reply.
I’m glad people find this useful. And I agree it will be better to consolidate the first two env vars into one. I’ll push my changes 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. The result is also exported into a format that can be easily
visualized by the Chrome browser.

Currently this features is controlled by the following environment
variables:
 - `ZIG_LLVM_TIME_TRACE_FILE` toggles this feature and specifies the
   output time trace file.
 - `ZIG_LLVM_TIME_TRACE_GRANULARITY` controls the time granularity in
   ms (default to 500).
@mshockwave
Copy link
Contributor Author

Alright I've merged ZIG_LLVM_ENABLE_TIME_TRACE into ZIG_LLVM_TIME_TRACE_FILE. Now one only needs to do something like this:

env ZIG_LLVM_TIME_TRACE_FILE=foo.time-trace.json zig build-exe foo.zig

@jedisct1 jedisct1 merged commit 83e0a49 into ziglang:master Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants