Perf

From Wikitech
This article needs improvements to better conform to style guidelines.
It has been suggested that this page should be merged with Varnish


Observe $pid behavior

 $ sudo perf record -F 99 -a -g -p $pid -- sleep 5
 $ sudo perf report -n [--stdio]

Probes Cheatsheet

List available functions:

 $ sudo perf probe -F -x /usr/sbin/varnishd

Define a probe event for each function named "smf_*":

 $ sudo perf probe -x /usr/sbin/varnishd --add 'smf_*'
 

List defined probes:

 $ sudo perf probe -l
 probe_varnishd:smf_alloc (on smf_alloc@storage/storage_file.c in /usr/sbin/varnishd)
 probe_varnishd:smf_free (on smf_free@storage/storage_file.c in /usr/sbin/varnishd)
 probe_varnishd:smf_init (on smf_init@storage/storage_file.c in /usr/sbin/varnishd)
 probe_varnishd:smf_open (on smf_open@storage/storage_file.c in /usr/sbin/varnishd)
 probe_varnishd:smf_open_chunk (on smf_open_chunk@storage/storage_file.c in /usr/sbin/varnishd)
 probe_varnishd:smf_trim (on smf_trim@storage/storage_file.c in /usr/sbin/varnishd)

Trace smf_* function calls:

 $ sudo perf trace --no-syscalls --ev 'probe_varnishd:smf_*'
    0.000 probe_varnishd:smf_alloc:(461af0))
    0.038 probe_varnishd:smf_alloc:(461af0))
    0.194 probe_varnishd:smf_free:(461630))
    [...]

Trace smf_alloc duration:

 $ sudo perf probe -x /usr/sbin/varnishd --add 'smf_alloc_exit=smf_alloc%return'
 $ sudo perf trace --no-syscalls --ev 'probe_varnishd:smf_alloc*'
    0.000 probe_varnishd:smf_alloc:(461af0))
    0.022 probe_varnishd:smf_alloc_exit:(461af0 <- 45fc36))

Print function parameters:

 $ sudo perf probe -x /usr/sbin/varnishd --add 'smf_alloc_params=smf_alloc $params'
 $ sudo perf trace --no-syscalls --ev 'probe_varnishd:smf_alloc_params'
    0.000 probe_varnishd:smf_alloc_params:(461af0) st=0x7f24910b43c0 size=0x118)
    0.024 probe_varnishd:smf_alloc_params:(461af0) st=0x7f24910b43c0 size=0x11e)