perfetto icon indicating copy to clipboard operation
perfetto copied to clipboard

Add cpu cycles stolen by host in perfetto traces (in case of emulator)

Open vsharda opened this issue 9 months ago • 1 comments

I am running some perf tests on emulator and see variable results on the same host. I have fixed frequencies of host, so that isn't a variable. But one other thing, that I see causing variability in wall clock time is when host steals cycles from guest. In other words, when vcpu is ready to run but was not allowed to run In the host. If I take trace and can capture cpu stats from /proc/stat with 'steal' cycles, would help clarify this situation. In /proc/stat 8th column is called 'steal' time.

Changes are pretty straight forward: a) in sys_stats.proto, we need to add one more field after softirq_ns: optional uint64 steal_ns = 9; b) same in perfetto_trace.proto c) in sys_stats_data_source.cc, add this after set_softirq_ns: cpu_stat->set_steal_ns(cpu_times[7] * ns_per_user_hz_); (and change vector cpu_times size to 8)

And then in tarce processor: d) in system_probes_parser.cc: push counter after softirq_ns: context_->event_tracker->PushCounter(ts, static_cast(ct.steal_ns()), intern_track("steal_ns"));

That is it and then these show up in perfetto UI, when run new binaries on device and tarce_processor_shell on host.

I can submit CL as well. Pls let me know.

vsharda avatar Mar 27 '25 19:03 vsharda

Hi, This is indeed a very nice to have feature. Could you please send a Pull Request for us to review and merge? Thanks

KirillTim avatar Mar 28 '25 14:03 KirillTim

https://github.com/google/perfetto/pull/1141

vsharda avatar Apr 03 '25 17:04 vsharda

LGTM.

LalitMaganti avatar Apr 03 '25 17:04 LalitMaganti

Cl has landed thanks for the contribution!

LalitMaganti avatar Apr 05 '25 11:04 LalitMaganti