代码之家  ›  专栏  ›  技术社区  ›  md.jamal

用于列出使用ftrace执行的所有内核函数的脚本

  •  0
  • md.jamal  · 技术社区  · 6 年前

    我编写了一个脚本,它将使用 :

    #!/bin/bash
    # Mount the tracefs
    mount -t tracefs nodev /sys/kernel/tracing
    # Disable tracing
    echo "0" > /sys/kernel/tracing/tracing_on
    # set the current tracer to nop
    echo "nop" > /sys/kernel/tracing/current_tracer
    # set the current shell PID as a filter
    echo $$ > /sys/kernel/tracing/set_ftrace_pid
    # set the current tracer to function_graph
    echo "function_graph" > /sys/kernel/tracing/current_tracer
    # Enable tracing
    echo "1" > /sys/kernel/tracing/tracing_on
    # Execute the command
    ls
    # Disable tracing
    echo "0" > /sys/kernel/tracing/tracing_on
    # Cat the trace file into temporary file
    cat /sys/kernel/tracing/trace > /tmp/mycommand_trace
    

    当我使用 function_graph 追踪器,而很多条目 function 示踪剂。

    功能 示踪剂:

    $ cat /tmp/mycommand_trace | head -n 20
    # tracer: function
    #
    #                              _-----=> irqs-off
    #                             / _----=> need-resched
    #                            | / _---=> hardirq/softirq
    #                            || / _--=> preempt-depth
    #                            ||| /     delay
    #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION
    #              | |       |   ||||       |         |
     kernel_function-31784 [003] ....  5769.020705: mutex_unlock <-rb_simple_write
     kernel_function-31784 [003] ....  5769.020706: __fsnotify_parent <-vfs_write
     kernel_function-31784 [003] ....  5769.020706: fsnotify <-vfs_write
     kernel_function-31784 [003] ....  5769.020707: __sb_end_write <-vfs_write
     kernel_function-31784 [003] d...  5769.020730: do_syscall_64 <-entry_SYSCALL_64_after_hwframe
     kernel_function-31784 [003] ....  5769.020730: __x64_sys_dup2 <-do_syscall_64
     kernel_function-31784 [003] ....  5769.020730: ksys_dup3 <-__x64_sys_dup2
     kernel_function-31784 [003] ....  5769.020730: _raw_spin_lock <-ksys_dup3
     kernel_function-31784 [003] ....  5769.020731: expand_files <-ksys_dup3
     kernel_function-31784 [003] ....  5769.020731: do_dup2 <-__x64_sys_dup2
     kernel_function-31784 [003] ....  5769.020732: filp_close <-do_dup2
    

    函数图 示踪剂:

    $ cat /tmp/mycommand_trace 
    # tracer: function_graph
    #
    # CPU  DURATION                  FUNCTION CALLS
    # |     |   |                     |   |   |   |
      3) # 1485.764 us |          } /* schedule */
      3) # 1494.689 us |        } /* do_wait */
      3) # 1495.325 us |      } /* kernel_wait4 */
      3) # 1495.565 us |    } /* __x64_sys_wait4 */
      3) # 1495.848 us |  } /* do_syscall_64 */
    

    但据我所知 痕迹 , 函数图 tracer应该同时跟踪内核函数调用的退出和进入,但在上面的输出中看不到它。

    我的剧本有什么问题吗?

    0 回复  |  直到 6 年前