perf scripts jiri olsa
play

perf scripts jiri olsa 1 PERF SCRIPTS | JIRI OLSA HI basics - PowerPoint PPT Presentation

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


  1. perf scripts jiri olsa 1 PERF SCRIPTS | JIRI OLSA

  2. HI ● basics ● perf in python ● post process scripts 2 PERF SCRIPTS | JIRI OLSA

  3. 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

  4. 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

  5. PERF INTERFACE IN NUTSHELL $ perf stat -e ' cycles ' WORKLOAD Performance counter stats for 'find ..': 104,142,555 cycles 5 PERF SCRIPTS | JIRI OLSA

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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

  15. PERF SCRIPTS ● 2 areas of script support ● use perf in python scripts ● post process perf data via python/perl 15 PERF SCRIPTS | JIRI OLSA

  16. PYTHON SCRIPTS ● use perf in python scripts ● perf module 16 PERF SCRIPTS | JIRI OLSA

  17. 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

  18. 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

  19. 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

  20. 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

  21. 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

  22. PYTHON PERF MODULE import perf def main(): cpus = perf.cpu_map() threads = perf.thread_map() if __name__ == '__main__': main() 22 PERF SCRIPTS | JIRI OLSA

  23. 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

  24. 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

  25. 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

  26. PYTHON PERF MODULE ● needs some love counting interface stabilize ● volunteers welcome ;-) $KERNEL/tools/perf/util/python.c 26 PERF SCRIPTS | JIRI OLSA

  27. POST PROCESS SCRIPTING ● interface for processing perf data from: perf record perf stat 27 PERF SCRIPTS | JIRI OLSA

  28. 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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend