So I have this tool perf-focus
that I use to analyze perf results. It’s kind of handy, though probably it duplicates a bunch of other, better tools that I’m not aware of. But I just added a feature that probably does make it of interest to everyone: it now has the ability to profile rustc queries, letting us unintrusively gather statistical data about where rustc is spending its time.
To use it, you would first want to install the tool:
> cargo install perf-focus
You also want to configure your config.toml
to include debuginfo-lines
at least, I think, since that will give us the frame pointers that perf
needs. Then you want to gather some data:
> perf record -F 99 -g rustc ...
Finally, you can analyze the data. The [README] for perf-focus describes its various options, but a command like this is probably what you want:
> perf focus '{main}' --rustc-query --tree-callees
For me, this gives a lot of output, so you may want to filter it down to interesting stuff, like anything that takes at least 5% of the total time:
> perf focus '{main}' --rustc-query --tree-callees --tree-min-percent 5
Matcher : {main}
Matches : 2690
Not Matches: 0
Percentage : 100%
Tree
| matched `{main}` (100% total, 25% self)
: | mir_borrowck<'tcx> (35% total, 35% self)
: | typeck_item_bodies<'tcx> (11% total, 0% self)
: : | typeck_tables_of<'tcx> (11% total, 11% self)
: | compile_codegen_unit<'tcx> (9% total, 8% self)
: | borrowck<'tcx> (6% total, 0% self)
: : | mir_validated<'tcx> (5% total, 0% self)
Note here that the “self” measurements are most meaningful – i.e., the mir_borrowck
accounts for 35% of this run. The typeck_item_bodies
query, otoh, invoked queries that accounted for 11%, though it itself only accounted for 0%.