Skip to content

Commit d916578

Browse files
authored
Rollup merge of #69220 - wesleywiser:doc_self_profile_unstable_book, r=nikomatsakis
Add documentation for the `-Zself-profile` flag
2 parents 834bc56 + 5b7e6c0 commit d916578

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# `self-profile-events`
2+
3+
---------------------
4+
5+
The `-Zself-profile-events` compiler flag controls what events are recorded by the self-profiler when it is enabled via the `-Zself-profile` flag.
6+
7+
This flag takes a comma delimited list of event types to record.
8+
9+
For example:
10+
11+
```console
12+
$ rustc -Zself-profile -Zself-profile-events=default,args
13+
```
14+
15+
## Event types
16+
17+
- `query-provider`
18+
- Traces each query used internally by the compiler.
19+
20+
- `generic-activity`
21+
- Traces other parts of the compiler not covered by the query system.
22+
23+
- `query-cache-hit`
24+
- Adds tracing information that records when the in-memory query cache is "hit" and does not need to re-execute a query which has been cached.
25+
- Disabled by default because this significantly increases the trace file size.
26+
27+
- `query-blocked`
28+
- Tracks time that a query tries to run but is blocked waiting on another thread executing the same query to finish executing.
29+
- Query blocking only occurs when the compiler is built with parallel mode support.
30+
31+
- `incr-cache-load`
32+
- Tracks time that is spent loading and deserializing query results from the incremental compilation on-disk cache.
33+
34+
- `query-keys`
35+
- Adds a serialized representation of each query's query key to the tracing data.
36+
- Disabled by default because this significantly increases the trace file size.
37+
38+
- `function-args`
39+
- Adds additional tracing data to some `generic-activity` events.
40+
- Disabled by default for parity with `query-keys`.
41+
42+
- `llvm`
43+
- Adds tracing information about LLVM passes and codegeneration.
44+
- Disabled by default because this only works when `-Znew-llvm-pass-manager` is enabled.
45+
46+
## Event synonyms
47+
48+
- `none`
49+
- Disables all events.
50+
Equivalent to the self-profiler being disabled.
51+
52+
- `default`
53+
- The default set of events which stikes a balance between providing detailed tracing data and adding additional overhead to the compilation.
54+
55+
- `args`
56+
- Equivalent to `query-keys` and `function-args`.
57+
58+
- `all`
59+
- Enables all events.
60+
61+
## Examples
62+
63+
Enable the profiler and capture the default set of events (both invocations are equivalent):
64+
65+
```console
66+
$ rustc -Zself-profile
67+
$ rustc -Zself-profile -Zself-profile-events=default
68+
```
69+
70+
Enable the profiler and capture the default events and their arguments:
71+
72+
```console
73+
$ rustc -Zself-profile -Zself-profile-events=default,args
74+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# `self-profile`
2+
3+
--------------------
4+
5+
The `-Zself-profile` compiler flag enables rustc's internal profiler.
6+
When enabled, the compiler will output three binary files in the specified directory (or the current working directory if no directory is specified).
7+
These files can be analyzed by using the tools in the [`measureme`] repository.
8+
9+
To control the data recorded in the trace files, use the `-Zself-profile-events` flag.
10+
11+
For example:
12+
13+
First, run a compilation session and provide the `-Zself-profile` flag:
14+
15+
```console
16+
$ rustc --crate-name foo -Zself-profile`
17+
```
18+
19+
This will generate three files in the working directory such as:
20+
21+
- `foo-1234.events`
22+
- `foo-1234.string_data`
23+
- `foo-1234.string_index`
24+
25+
Where `foo` is the name of the crate and `1234` is the process id of the rustc process.
26+
27+
To get a summary of where the compiler is spending its time:
28+
29+
```console
30+
$ ../measureme/target/release/summarize summarize foo-1234
31+
```
32+
33+
To generate a flamegraph of the same data:
34+
35+
```console
36+
$ ../measureme/target/release/inferno foo-1234
37+
```
38+
39+
To dump the event data in a Chromium-profiler compatible format:
40+
41+
```console
42+
$ ../measureme/target/release/crox foo-1234
43+
```
44+
45+
For more information, consult the [`measureme`] documentation.
46+
47+
[`measureme`]: https://github.com/rust-lang/measureme.git

0 commit comments

Comments
 (0)