perf scripts jiri olsa 1 PERF SCRIPTS | JIRI OLSA
HI ● basics ● perf in python ● post process scripts 2 PERF SCRIPTS | JIRI OLSA
COUNTING ● perf stat CPU 0 CPU 1 CPU 2 start $ perf stat -e ' cycles,instructions ' WORKLOAD WORKLOAD Performance counter stats for 'find ..': 104,142,555 cycles WORKLOAD 64,785,445 instructions WORKLOAD WORKLOAD WORKLOAD stop 3 PERF SCRIPTS | JIRI OLSA
SAMPLING ● perf record CPU 0 CPU 1 CPU 2 start $ perf record -e ' cycles ' WORKLOAD WORKLOAD [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.048 MB perf.data WORKLOAD perf.data sample ID WORKLOAD PID CPU ADDRESS WORKLOAD CALLCHAIN SAMPLE BRANCHES MEMORY WORKLOAD SAMPLE TRACEPOINT SAMPLE stop SAMPLE 4 PERF SCRIPTS | JIRI OLSA
PERF INTERFACE IN NUTSHELL $ perf stat -e ' cycles ' WORKLOAD Performance counter stats for 'find ..': 104,142,555 cycles 5 PERF SCRIPTS | JIRI OLSA
PERF INTERFACE IN NUTSHELL user kernel $ perf stat -e ' cycles ' WORKLOAD Performance counter stats for 'find ..': 104,142,555 cycles 6 PERF SCRIPTS | JIRI OLSA
PERF INTERFACE IN NUTSHELL user kernel $ perf stat -e ' cycles ' WORKLOAD Performance counter stats for 'find ..': 104,142,555 cycles SYS_PERF_EVENT_OPEN 7 PERF SCRIPTS | JIRI OLSA
PERF INTERFACE IN NUTSHELL user kernel $ perf stat -e ' cycles ' WORKLOAD Performance counter stats for 'find ..': 104,142,555 cycles SYS_PERF_EVENT_OPEN EVENT 8 PERF SCRIPTS | JIRI OLSA
PERF INTERFACE IN NUTSHELL user kernel $ perf stat -e ' cycles ' WORKLOAD Performance counter stats for 'find ..': CPU 0 CPU 1 104,142,555 cycles SYS_PERF_EVENT_OPEN EVENT TASK 1 CGROUP 9 PERF SCRIPTS | JIRI OLSA
PERF INTERFACE IN NUTSHELL user kernel $ perf stat -e ' cycles ' WORKLOAD Performance counter stats for 'find ..': CPU 0 CPU 1 104,142,555 cycles SYS_PERF_EVENT_OPEN EVENT TASK 1 SYS_READ CGROUP 10 PERF SCRIPTS | JIRI OLSA
PERF INTERFACE IN NUTSHELL user kernel $ perf stat -e ' cycles ' WORKLOAD Performance counter stats for 'find ..': CPU 0 CPU 1 104,142,555 cycles SYS_PERF_EVENT_OPEN EVENT TASK 1 SYS_READ $ perf record -e ' cycles ' WORKLOAD [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.048 MB CGROUP 11 PERF SCRIPTS | JIRI OLSA
PERF INTERFACE IN NUTSHELL user kernel $ perf stat -e ' cycles ' WORKLOAD Performance counter stats for 'find ..': CPU 0 CPU 1 104,142,555 cycles SYS_PERF_EVENT_OPEN EVENT TASK 1 SYS_READ $ perf record -e ' cycles ' WORKLOAD [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.048 MB CGROUP 12 PERF SCRIPTS | JIRI OLSA
PERF INTERFACE IN NUTSHELL user kernel $ perf stat -e ' cycles ' WORKLOAD Performance counter stats for 'find ..': CPU 0 CPU 1 104,142,555 cycles SYS_PERF_EVENT_OPEN EVENT TASK 1 SYS_READ SYS_MMAP $ perf record -e ' cycles ' WORKLOAD [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.048 MB CGROUP 13 PERF SCRIPTS | JIRI OLSA
PERF INTERFACE IN NUTSHELL user kernel $ perf stat -e ' cycles ' WORKLOAD Performance counter stats for 'find ..': CPU 0 CPU 1 104,142,555 cycles SYS_PERF_EVENT_OPEN EVENT TASK 1 SYS_READ SYS_MMAP $ perf record -e ' cycles ' WORKLOAD [ perf record: Woken up 1 times to write data ] sample [ perf record: Captured and wrote 0.048 MB ID PID CGROUP CPU perf.data ADDRESS CALLCHAIN BRANCHES MEMORY SAMPLE SAMPLE SAMPLE SAMPLE TRACEPOINT 14 PERF SCRIPTS | JIRI OLSA
PERF SCRIPTS ● 2 areas of script support ● use perf in python scripts ● post process perf data via python/perl 15 PERF SCRIPTS | JIRI OLSA
PYTHON SCRIPTS ● use perf in python scripts ● perf module 16 PERF SCRIPTS | JIRI OLSA
PYTHON SCRIPTS user kernel $ perf stat -e ' cycles ' WORKLOAD Performance counter stats for 'find ..': CPU 0 CPU 1 104,142,555 cycles SYS_PERF_EVENT_OPEN EVENT TASK 1 SYS_READ SYS_MMAP $ perf record -e ' cycles ' WORKLOAD [ perf record: Woken up 1 times to write data ] sample [ perf record: Captured and wrote 0.048 MB ID PID CGROUP CPU perf.data ADDRESS CALLCHAIN BRANCHES MEMORY SAMPLE SAMPLE SAMPLE SAMPLE TRACEPOINT 17 PERF SCRIPTS | JIRI OLSA
PYTHON SCRIPTS user kernel CPU 0 CPU 1 SYS_PERF_EVENT_OPEN EVENT TASK 1 SYS_READ SYS_MMAP sample ID PID CGROUP CPU ADDRESS CALLCHAIN BRANCHES MEMORY TRACEPOINT 18 PERF SCRIPTS | JIRI OLSA
PYTHON SCRIPTS #!/usr/bin/python user kernel import perf CPU 0 CPU 1 def main(): cpus = perf.cpu_map() SYS_PERF_EVENT_OPEN threads = perf.thread_map() evsel = perf.evsel(task = 1, EVENT wakeup_eve.. TASK 1 sample_id_ SYS_READ evsel.open(cpus = cpus, threads ..) SYS_MMAP while True: evlist.poll(timeout = -1) sample for cpu in cpus: event = evlist.read_on_cpu(cpu) ID if not event: PID CGROUP continue CPU ADDRESS print event CALLCHAIN BRANCHES while True: MEMORY print "nobody likes python anyway.." TRACEPOINT 19 PERF SCRIPTS | JIRI OLSA
PYTHON SCRIPTS #!/usr/bin/python user kernel import perf CPU 0 CPU 1 def main(): cpus = perf.cpu_map() SYS_PERF_EVENT_OPEN threads = perf.thread_map() evsel = perf.evsel(task = 1, EVENT wakeup_eve.. TASK 1 sample_id_ perf.so SYS_READ evsel.open(cpus = cpus, threads ..) SYS_MMAP while True: evlist.poll(timeout = -1) sample for cpu in cpus: event = evlist.read_on_cpu(cpu) ID if not event: PID CGROUP continue CPU ADDRESS print event CALLCHAIN BRANCHES while True: MEMORY print "every1 likes python anyway.." TRACEPOINT python extension # yum install python-perf 20 PERF SCRIPTS | JIRI OLSA
PYTHON PERF MODULE ● only sampling interface atm ● quite simple one: cpu_map thread_map evsel (open) evlist (open, mmap, poll, add, read_on_cpu) (mmap|task|comm|lost|read|sample|throttle)_event 21 PERF SCRIPTS | JIRI OLSA
PYTHON PERF MODULE import perf def main(): cpus = perf.cpu_map() threads = perf.thread_map() if __name__ == '__main__': main() 22 PERF SCRIPTS | JIRI OLSA
PYTHON PERF MODULE import perf def main(): cpus = perf.cpu_map() threads = perf.thread_map() evsel = perf.evsel(task = 1, comm = 1, mmap = 0, wakeup_events = 1, watermark = 1, sample_id_all = 1, sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU) evsel.open(cpus = cpus, threads = threads) if __name__ == '__main__': main() 23 PERF SCRIPTS | JIRI OLSA
PYTHON PERF MODULE import perf def main(): cpus = perf.cpu_map() threads = perf.thread_map() evsel = perf.evsel(task = 1, comm = 1, mmap = 0, wakeup_events = 1, watermark = 1, sample_id_all = 1, sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU) evsel.open(cpus = cpus, threads = threads) evlist = perf.evlist(cpus, threads) evlist.add(evsel) evlist.mmap() if __name__ == '__main__': main() 24 PERF SCRIPTS | JIRI OLSA
PYTHON PERF MODULE import perf def main(): cpus = perf.cpu_map() threads = perf.thread_map() evsel = perf.evsel(task = 1, comm = 1, mmap = 0, wakeup_events = 1, watermark = 1, sample_id_all = 1, sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU) evsel.open(cpus = cpus, threads = threads) evlist = perf.evlist(cpus, threads) evlist.add(evsel) evlist.mmap() while True: evlist.poll(timeout = -1) for cpu in cpus: event = evlist.read_on_cpu(cpu) if not event: continue print event if __name__ == '__main__': main() 25 PERF SCRIPTS | JIRI OLSA
PYTHON PERF MODULE ● needs some love counting interface stabilize ● volunteers welcome ;-) $KERNEL/tools/perf/util/python.c 26 PERF SCRIPTS | JIRI OLSA
POST PROCESS SCRIPTING ● interface for processing perf data from: perf record perf stat 27 PERF SCRIPTS | JIRI OLSA
POST PROCESS SCRIPTING - SAMPLING # Children Self Command Shared Object Symbol # ........ ........ ....... ................ ............................... perf.data # 51.40% 0.00% ls [kernel.vmlinux] [k] system_call 9.71% 0.00% ls [kernel.vmlinux] [k] __alloc_pages_nodemask 9.71% 9.71% ls [kernel.vmlinux] [k] clear_page | ---clear_page SAMPLE __alloc_pages_nodemask perf report SAMPLE alloc_pages_vma handle_mm_fault SAMPLE __do_page_fault do_page_fault SAMPLE page_fault _int_malloc SAMPLE SAMPLE 8.73% 8.30% ls [kernel.vmlinux] [k] perf_event_context_sched_in | SAMPLE ---perf_event_context_sched_in | SAMPLE |--95.07%-- __perf_event_task_sched_in | finish_task_switch | __schedule | _cond_resched | sys_write | system_call | __GI___libc_write | 0x2d646c6975622d66 | --4.93%-- perf_event_exec setup_new_exec 28 PERF SCRIPTS | JIRI OLSA
Recommend
More recommend