profiling.txt 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. Profiling (from the Akaros document)
  2. ===========================
  3. 2015-07-15 Barret Rhoden (brho)
  4. Contents
  5. ---------------------------
  6. "Oprofile"
  7. "Oprofile"
  8. ---------------------------
  9. Akaros has a very basic sampling profiler, similar to oprofile. The kernel
  10. generates traces, which you copy off the machine and process on Linux.
  11. To get started, make sure #K is mounted.
  12. / $ bind -a \#K /dev/
  13. You control the profiler with the kpctl file. The general style is to start
  14. the events that trigger a sample, such as a timer tick, then you start and stop
  15. the profiling. The distinction between the two steps is that one actually
  16. fires the events (e.g. the timer IRQ), and the other enables *collection* of profiling info when those events occur.
  17. TODO from Akaros:
  18. The optimer command takes the core id (or "all"), followed by "on" or "off".
  19. As with all good devices, if you echo garbage, in, you should get the usage as
  20. an errstr. That'll be kept up to date more than documentation.
  21. / $ echo garbage > /dev/kpctl
  22. echo failed: Unspecified, startclr|start|stop|clear|opstart|opstop|optimer
  23. / $ echo optimer garbage > /dev/kpctl
  24. echo failed: Unspecified, optimer [<0|1|..|n|all> <on|off>] [period USEC]
  25. Let's set up the timer on core 0:
  26. / $ echo optimer 0 on > /dev/kpctl
  27. And then start oprofile system-wide.
  28. / $ echo opstart > /dev/kpctl
  29. Enable tracing on 0
  30. Enable tracing on 1
  31. Enable tracing on 2
  32. Enable tracing on 3
  33. Enable tracing on 4
  34. Enable tracing on 5
  35. Enable tracing on 6
  36. Enable tracing on 7
  37. Run whatever command you want, then stop the profiler.
  38. / $ foo
  39. / $ echo opstop > /dev/kpctl
  40. TODO
  41. Might as well turn off the timers:
  42. / $ echo optimer all off > /dev/kpctl
  43. Now we need to extract the trace. The easiest way is via 9p.
  44. / $ cat /dev/kpoprofile > /mnt/trace
  45. Once the trace has been read from kpoprofile, it cannot be read again. The
  46. read drains the kernel's trace buffer.
  47. The trace that the kernel generates is in an Akaros-specific format. There is
  48. a go program at tools/profile/op2.go that translates from the Akaros format to
  49. pprof format. You could run this on Harvey, since we support Go programs, but
  50. since we don't have a port of pprof, it's easier to do it all in Linux.
  51. So now we're in linux, and say our 9p ufs server is rooted at mnt/netroot/. Run op2:
  52. (linux) $ op2 < mnt/netroot/trace > trace-pp
  53. To get a sense for what the trace holds, you might want to start with looking at the raw addresses to distinguish between the kernel and the user.
  54. (linux) $ pprof --addresses trace-pp
  55. PPROF> top
  56. (shows some addresses)
  57. Say the majority of the addresses are user addresses:
  58. (linux) $ pprof obj/tests/foo trace-pp
  59. PPROF> top
  60. (shows some functions)
  61. Or you can visualize things:
  62. (linux) $ pprof --evince obj/tests/foo trace-pp
  63. The visualization is not of much user for user programs, since the kernel does
  64. not record backtraces for userspace by default. It's a little dangerous at the
  65. moment. In the future, we may have an op option to control whether or not the
  66. kernel attempts a backtrace.
  67. For more info on pprof, check out:
  68. http://gperftools.googlecode.com/svn/trunk/doc/cpuprofile.html