Skip to content

Commit 38bec7b

Browse files
committed
Add comment explaining how the PMC collection works
1 parent 5e49954 commit 38bec7b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

collector/src/rustc-fake.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ fn main() {
8383
}
8484

8585
"xperf-stat" | "xperf-stat-self-profile" => {
86+
// For Windows, we use a combination of xperf and tracelog to capture ETW events including hardware performance counters.
87+
// To do this, we start an ETW trace using tracelog, telling it to include the InstructionRetired and TotalCycles PMCs
88+
// for each CSwitch event that is recorded. Then when ETW records a context switch event, it will be preceeded by a
89+
// PMC event which contains the raw counters at that instant. After we've finished compilation, we then use xperf
90+
// to stop the trace and dump the results to a plain text file. This file is then processed by the `etw_parser` module
91+
// which finds events related to the rustc process and calculates the total values for those performance counters.
92+
// Conceptually, this is similar to how `perf` works on Linux except we have to do more of the work ourselves as there
93+
// isn't an out of the box way to get the data we care about.
94+
8695
// Read the path to xperf.exe and tracelog.exe from an environment variable, falling back to assuming it's on the PATH.
8796
let xperf = std::env::var("XPERF").unwrap_or("xperf.exe".to_string());
8897
let mut cmd = Command::new(&xperf);

0 commit comments

Comments
 (0)