perf: 'sched' is not a perf-command with perf 6.5.3 on Ubuntu 22.04

147 Views Asked by At

I am trying to find which processes are causing context switches within my application. Google returned this guide:

https://www.brendangregg.com/perf.html#SchedulerAnalysis

enter image description here

Great? I run it, but it doesn't work:

sudo perf record ./Test
[ perf record: Captured and wrote 1.438 MB perf.data (37217 samples) ]
perf sched latency
perf: 'sched' is not a perf-command. See 'perf --help'.

What's going wrong?

1

There are 1 best solutions below

0
ThinkOpenly On

I think Ubuntu doesn't build perf with many dependencies included. For example, perf sched and perf record -e [software tracepoint] require libtraceevent. Ubuntu has chose to disable those features rather than adopt the dependency.

I'm also on Ubuntu 22.04, and perf sched does not work, nor does my earlier suggestion perf record -e sched:sched_switch.

That being said, you can download the kernel source and build perf yourself. I had to install libelf-dev and libtraceevent-dev in order for perf to be able to provide the above two functions.

  1. Install kernel source
    $ /usr/bin/sudo apt install linux-source
    
    Source shows up as a tarball in /usr/src/.
  2. Untar kernel source somewhere
    $ cd [some-working-directory]
    $ tar -xf /usr/src/linux-source*
    $ cd linux-source-*
    
  3. Copy in the current kernel config file
    $ cp /boot/config-$(uname -r) ./.config
    
  4. Validate the config file against the linux source tree
    $ make oldconfig
    
  5. Build and install perf to a local directory
    $ cd tools/perf
    $ make prefix=[some-working-directory]/install install
    

Afterwards, you should have a new perf binary in [some-working-directory]/install/bin. There are probably some caveats for how to make use of it properly from that location, but just running it seems to work for basic use.