rustc-perf icon indicating copy to clipboard operation
rustc-perf copied to clipboard

[Windows] Implement support for the `cpu-clock` perf pseudo-counter

Open wesleywiser opened this issue 4 years ago • 2 comments

The Linux perf tool has a counter called cpu-clock which is basically just the total time the process was running on each thread. (As a simple example, suppose a process runs for 3 seconds on 1 core and, at the same time, 1 second on another core, then the cpu-clock would read 4 seconds)

This counter isn't backed by a hardware performance counter, rather it is a metric derived from some hardware performance counters and as such, doesn't exist on Windows. However, we can replicate the counter ourselves.

To do that, we'll need to keep track of the times each thread we care about spends active on a core and sum the total times together. We may be able to use the Timestamp data already collected in the trace file for this purpose or we may need to use the Time (or TimerFixed?) PMC.

https://github.com/rust-lang/rustc-perf/blob/c648f394e7228a9676b9cbc4b46974fea7f9c14d/collector/src/etw_parser.rs#L384-L388

https://github.com/rust-lang/rustc-perf/blob/c648f394e7228a9676b9cbc4b46974fea7f9c14d/collector/src/etw_parser.rs#L398-L399

After this is implemented, the detailed self-profile query results page should show reasonable numbers in the total "Time %" cell.

image

wesleywiser avatar Jul 08 '21 19:07 wesleywiser

FWIW it was my perspective when implementing this to explicitly not use trace data from the self-profile data because I wanted to expose disparity in what the kernel(?) thought and what the profiling data thought. However, this may not be the best way to get that exposed, and we may not care.

Mark-Simulacrum avatar Jul 08 '21 20:07 Mark-Simulacrum

To clarify, by "the trace file" I meant the results of tracelog/xperf not the self-profile data which should be conceptually equivalent to the perf data on Linux.

wesleywiser avatar Jul 08 '21 21:07 wesleywiser