Linux perf events profiling in Google Compute Engine not working

1.4k Views Asked by At

I'm new to using Google Compute Engine. I'd like to use the Linux perf tool to do some various perf events measurements of my application and eventually sample profiling. I've installed the linux perf tool on my Ubuntu 16.04 LTS VM. However even basic events like cycles show up as "not supported". I'm guessing that the underlying KVM hypervisor does not have virtual PMU support enabled, although I believe KVM does support this with a non-default flag setting. Is there any way to get this working?

# perf stat -e cycles -a sleep 10

Performance counter stats for 'system wide':

<not supported>      cycles                   

  10.000598339 seconds time elapsed
1

There are 1 best solutions below

1
On

Linux perf tool by default tries to use hardware performance monitoring counters. When your OS is virtualized, you have no direct access to all counters; several virtualization solutions may allow access to some basic counters, if configured.

In your case it seems that GCE virtualization give no such access. (Ask support of your GCE? If it was disabled outside of your VM, you cant change this.)

You may use perf with some software events, for example -e task-clock to get basic profiling. Check perf stat output for supported events and perf list for Software events.

perf stat -e task-clock ...
perf record -e task-clock ...