Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does perf lock profile user space mutexes?

Tags:

linux

perf

Summary: Does perf lock profile pthread_mutex?

Details:

The tool perf has an option perf lock. The man page says:

You can analyze various lock behaviours and statistics with this perf lock command.
   'perf lock record <command>' records lock events
    between start and end <command>. And this command
    produces the file "perf.data" which contains tracing
    results of lock events.

    'perf lock trace' shows raw lock events.

    'perf lock report' reports statistical data.

But when I tried running perf lock record I got an error saying: invalid or unsupported event: 'lock:lock_acquire'. I looked and it seems that error is probably because my kernel is not compiled with CONFIG_LOCKDEP or CONFIG_LOCK_STAT.

My question is: does perf lock report events related to user-space locks (like pthread_mutex) or only kernel locks? I'm more interested in profiling application that mostly run in user-space. I thought this option in perf looked interesting, but since I can't run it without compiling (or getting) a new kernel I'm interested in getting a better idea of what it does before I try.

like image 203
Gabriel Southern Avatar asked Jun 07 '13 20:06

Gabriel Southern


1 Answers

No. But maybe what you need can be done by recording sched_stat_sleep and sched_switch events:

$ perf record -e sched:sched_stat_sleep,sched:sched_switch -g -o perf.data.raw yourprog
$ perf inject -v -s -i perf.data.raw -o perf.data
$ perf report --stdio --no-children

Note: make sure your kernel is compiled with CONFIG_SCHEDSTATS=y and it is enabled at /proc/sys/kernel/sched_schedstats

See more at https://perf.wiki.kernel.org/index.php/Tutorial#Profiling_sleep_times.

like image 87
Andriy Avatar answered Sep 28 '22 07:09

Andriy