Use ftrace

perf ftrace is a simple wrapper for kernel’s ftrace functionality, and only supports single thread tracing now. Check following example:

  1. # perf ftrace ./lock
  2. 2) | switch_mm_irqs_off() {
  3. 2) 1.792 us | load_new_mm_cr3();
  4. 2) 9.157 us | }
  5. ------------------------------------------
  6. 2) <idle>-0 => <...>-5785
  7. ------------------------------------------
  8. 2) | finish_task_switch() {
  9. 2) | _raw_spin_unlock_irq() {
  10. 2) ==========> |
  11. 2) | smp_irq_work_interrupt() {
  12. 2) | irq_enter() {
  13. 2) 0.612 us | rcu_irq_enter();
  14. 2) 0.631 us | irqtime_account_irq();
  15. 2) 0.457 us | preempt_count_add();
  16. 2) 3.818 us | }
  17. 2) | __wake_up() {
  18. ......

-T option can be used to specify only tracing interested functions:

  1. # perf ftrace -T __kmalloc ./lock
  2. 20) + 17.698 us | __kmalloc();
  3. 20) 3.167 us | __kmalloc();
  4. 20) 0.952 us | __kmalloc();