【linux内核】使用ftrace追踪函数调用


前言

Ftrace是Linux内核中的一种跟踪工具,用于分析和调试内核代码的执行过程和性能。它可以帮助开发人员识别性能瓶颈、系统调用和函数调用路径,从而优化系统的运行。Ftrace提供了多种跟踪事件和功能,使开发人员能够深入了解内核的运行情况。

以下是Ftrace的一些主要组件和功能:

  1. Tracepoints: 这是内核中一些关键点的预定义位置,用于在代码执行时插入跟踪事件。开发人员可以选择在特定的tracepoints上收集跟踪数据,以便分析内核的行为。

  2. Function Tracing: Ftrace可以跟踪函数调用和返回,提供了一种了解代码执行路径的方式。这对于理解代码流程、检测调用路径中的延迟以及找到性能瓶颈非常有用。

  3. Event Tracing for Linux (LTTng): Ftrace支持LTTng,这是一个功能强大的事件跟踪框架,用于收集各种内核和用户空间事件。开发人员可以定义自己的事件,并在需要时收集这些事件的数据。

  4. Kernelshark: 这是Ftrace的图形化前端工具,可以帮助用户可视化和分析跟踪数据。Kernelshark能够以图表和时间线的形式显示事件,使开发人员更容易理解跟踪数据。

  5. Dynamic Tracing (BPF): Ftrace结合BPF(Berkeley Packet Filter)可以实现动态跟踪,允许开发人员编写自定义的跟踪脚本。这些脚本可以在运行时注入内核,以捕获特定事件或条件下的跟踪数据。

  6. Tracing Hooks: 内核中的一些关键函数也可以添加跟踪钩子,使开发人员可以收集这些函数的调用信息,进一步分析内核的行为。


使能ftrace功能

make menuconfigKernel hacking ---> Tracers --->

Kernel Function Tracer 
Kernel Function Graph Tracer 
enable/disable function tracing dynamically 

Ftrace依赖内核开关使能:

CONFIG_FUNCTION_TRACER
CONFIG_FUNCTION_GRAPH_TRACER
CONFIG_STACK_TRACER
CONFIG_DYNAMIC_FTRACE

编译后内核即打开ftrace功能

使用ftrace

相关内容在如下目录中:

/sys/kernel/debug/tracing

我们使用 ls 来看看目录下面到底有什么:

README                      current_tracer            hwlat_detector   per_cpu              set_event_pid       snapshot            trace_marker      tracing_max_latency
available_events            dyn_ftrace_total_info     instances        printk_formats       set_ftrace_filter   stack_max_size      trace_marker_raw  tracing_on
available_filter_functions  enabled_functions         kprobe_events    saved_cmdlines       set_ftrace_notrace  stack_trace         trace_options     tracing_thresh
available_tracers           events                    kprobe_profile   saved_cmdlines_size  set_ftrace_pid      stack_trace_filter  trace_pipe        uprobe_events
buffer_size_kb              free_buffer               max_graph_depth  saved_tgids          set_graph_function  trace               trace_stat        uprobe_profile
buffer_total_size_kb        function_profile_enabled  options          set_event            set_graph_notrace   trace_clock         tracing_cpumask

cat available_tracers 获取当前内核支持的跟踪器列表:

[tracing]# cat available_tracers 
function_graph function sched_switch irqsoff nop

Tracer有很多种,主要几大类:

函数类:function, stack, function_graph //可以用来追踪函数调用同时还可以把调用关系以及函数执行时间给获取到
延时类:irqsoff, preemptoff, preemptirqsoff, wakeup, wakeup_rt, waktup_dl
其他类:nop, mmiotrace, blk

工作中,主要使用 function 以及 function_graph 这两个跟踪器。

fucntion_graph的使用

 [tracing]# echo function_graph > current_tracer 
    [tracing]# cat trace | head -20
    # tracer: function_graph
    #
    # CPU  DURATION                  FUNCTION CALLS
    # |     |   |                     |   |   |   |
     1)   1.015 us    |        _spin_lock_irqsave();
     1)   0.476 us    |        internal_add_timer();
     1)   0.423 us    |        wake_up_idle_cpu();
     1)   0.461 us    |        _spin_unlock_irqrestore();
     1)   4.770 us    |      }
     1)   5.725 us    |    }
     1)   0.450 us    |    mutex_unlock();
     1) + 24.243 us   |  }
     1)   0.483 us    |  _spin_lock_irq();
     1)   0.517 us    |  _spin_unlock_irq();
     1)               |  prepare_to_wait() {
    
    
     1)   0.468 us    |    _spin_lock_irqsave();
     1)   0.502 us    |    _spin_unlock_irqrestore();
     1)   2.411 us    |  }
     1)   0.449 us    |  kthread_should_stop();
     1)               |  schedule() {
    
    

可以直接使用function.sh脚本来进行抓取

#!/bin/bash
debugfs=/sys/kernel/debug
echo nop > $debugfs/tracing/current_tracer
echo 0 > $debugfs/tracing/tracing_on
echo $$ > $debugfs/tracing/set_ftrace_pid
echo function_graph > $debugfs/tracing/current_tracer
echo test_proc_show > $debugfs/tracing/set_graph_function
echo 1 > $debugfs/tracing/tracing_on
exec "$@"

./function.sh ping 192.168.1.1 脚本后面跟着使用的命令

echo *icmp* > set_ftrace_filter 配置只追踪和icmp相关的函数
set_ftrace_pid 追踪哪个进程
set_graph_function 追踪特定函数
set_ftrace_notrace 屏蔽特定函数
tracing_on 该选项用来决定是否开启 tracer 功能
max_graph_depth 设置为5将显示内核函数的内部深度调用。
cat trace_pipe > /mnt/log & 将log在后台实时保存到指定的/mnt/log

trace-cmd

sudo apt-get install trace-cmd 安装 trace-cmd

trace-cmd start -p function_graph (跟踪函数类型)--max-graph-depth 5(函数调用追踪深度) -P (特定PID号)10885 很方便

具体ftrace日志分析

# tracer: function_graph
#
# CPU  DURATION                  FUNCTION CALLS
# |     |   |                     |   |   |   |
 0)   5.632 us    |        .__fsnotify_parent();
 0)   1.408 us    |        .fsnotify();
 0) # 1369.088 us |      } /* .vfs_write */
 0) # 1373.952 us |    } /* .ksys_write */
 0) # 1375.552 us |  } /* .__se_sys_write */
 0)               |  .schedule() {
    
    
 0)               |    .rcu_note_context_switch() {
    
    
 0)   0.448 us    |      .rcu_sched_qs();
 0)   1.664 us    |    }
 0)   0.512 us    |    ._raw_spin_lock();
 0)   0.448 us    |    .update_rq_clock();
 0)               |    .pick_next_task_fair() {
    
    
 0)               |      .put_prev_task_fair() {
    
    
 0)   0.448 us    |        .update_curr();
 0)   0.640 us    |        .__enqueue_entity();
 0)   0.512 us    |        .__update_load_avg_se();
 0)   0.512 us    |        .__update_load_avg_cfs_rq();
 0)   5.568 us    |      }
 0)   0.768 us    |      .clear_buddies();
 0)               |      .set_next_entity() {
    
    
 0)   0.448 us    |        .__update_load_avg_se();
 0)   0.512 us    |        .__update_load_avg_cfs_rq();
 0)   2.944 us    |      }
 0) + 13.184 us   |    }
 ------------------------------------------
 0)  iperf3-1545   =>   ksoftir-9
 ------------------------------------------

 0)   4.096 us    |  .switch_mm_irqs_off();
 0)               |  .__switch_to() {
    
    
 0)   0.640 us    |    .switch_booke_debug_regs();
 0)   0.512 us    |    .giveup_all();
 ------------------------------------------
 0)   ksoftir-9    =>  iperf3-1545
 ------------------------------------------

 0)               |    .finish_task_switch() {
    
    
 0)               |      .vtime_common_task_switch() {
    
    
 0)               |        .vtime_account_system() {
    
    
 0)   0.448 us    |          .vtime_delta.isra.5();
 0)   1.472 us    |        }
# tracer: function
#
# entries-in-buffer/entries-written: 102428/49009768   #P:2
#
#                              _-----=> irqs-off
#                             / _----=> need-resched
#                            | / _---=> hardirq/softirq
#                            || / _--=> preempt-depth
#                            ||| /     delay
#           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION
#              | |       |   ||||       |         |
          iperf3-1602  [001] ....  5236.506586: .stmmac_tx_timer_arm <-.stmmac_xmit
          iperf3-1602  [001] ....  5236.506586: .__usecs_to_jiffies <-.stmmac_tx_timer_arm
          iperf3-1602  [001] ....  5236.506586: .mod_timer <-.stmmac_tx_timer_arm
          iperf3-1602  [001] ....  5236.506587: .stmmac_xmit <-.dev_hard_start_xmit
          iperf3-1602  [001] ....  5236.506587: .ndesc_set_addr <-.stmmac_xmit
          iperf3-1602  [001] ....  5236.506588: .ndesc_prepare_tx_desc <-.stmmac_xmit
          iperf3-1602  [001] ....  5236.506588: .ndesc_set_tx_ic <-.stmmac_xmit
          iperf3-1602  [001] ....  5236.506588: .ndesc_set_addr <-.stmmac_xmit
          iperf3-1602  [001] ....  5236.506589: .ndesc_prepare_tx_desc <-.stmmac_xmit
          iperf3-1602  [001] ....  5236.506589: .dwmac_enable_dma_transmission <-.stmmac_xmit
                    <idle>-0     [001] d.h.  5236.525359: .hrtimer_update_next_event <-.hrtimer_interrupt
          <idle>-0     [001] d.h.  5236.525359: .__hrtimer_get_next_event <-.hrtimer_update_next_event
          <idle>-0     [001] d.h.  5236.525360: .__hrtimer_next_event_base.constprop.27 <-.__hrtimer_get_next_event
          <idle>-0     [001] d.h.  5236.525360: .__hrtimer_get_next_event <-.hrtimer_update_next_event
          <idle>-0     [001] d.h.  5236.525360: .__hrtimer_next_event_base.constprop.27 <-.hrtimer_update_next_event
          <idle>-0     [001] d.h.  5236.525361: ._raw_spin_unlock_irqrestore <-.hrtimer_interrupt
# tracer: irqsoff
#
# irqsoff latency trace v1.1.5 on 4.19.230
# --------------------------------------------------------------------
# latency: 521 us, #349/349, CPU#0 | (M:server VP:0, KP:0, SP:0 HP:0 #P:2)
#    -----------------
#    | task: iperf3-1546 (uid:0 nice:0 policy:0 rt_prio:0)
#    -----------------
#  => started at: .__check_irq_replay
#  => ended at:   .__check_irq_replay
#
#
#                  _------=> CPU#            
#                 / _-----=> irqs-off        
#                | / _----=> need-resched    
#                || / _---=> hardirq/softirq 
#                ||| / _--=> preempt-depth   
#                |||| /     delay            
#  cmd     pid   ||||| time  |   caller      
#     \   /      |||||  \    |   /         
  iperf3-1546    0d.s.    0us : .__check_irq_replay
  iperf3-1546    0d.s.    2us : .doorbell_exception <-fast_exc_return_irq
  iperf3-1546    0d.s.    3us : .irq_enter <-.doorbell_exception
  iperf3-1546    0d.s.    4us : .rcu_irq_enter <-.irq_enter
  iperf3-1546    0d.s.    5us : .rcu_nmi_enter <-.irq_enter
  iperf3-1546    0d.s.    6us : .vtime_account_irq_enter <-.irq_enter
  iperf3-1546    0d.s.    7us : .vtime_account_system <-.vtime_account_irq_enter
  iperf3-1546    0d.s.    8us : .vtime_delta.isra.5 <-.vtime_account_system
  iperf3-1546    0d.H.    9us : .smp_ipi_demux_relaxed <-.doorbell_exception
  iperf3-1546    0d.H.   11us : .generic_smp_call_function_single_interrupt <-.smp_ipi_demux_relaxed
  iperf3-1546    0d.H.   12us : .flush_smp_call_function_queue <-.smp_ipi_demux_relaxed
  iperf3-1546    0d.H.   16us : .__blk_mq_complete_request_remote <-.flush_smp_call_function_queue
  iperf3-1546    0d.H.   18us : .scsi_softirq_done <-.__blk_mq_complete_request_remote
  iperf3-1546    0d.H.   21us : .scsi_decide_disposition <-.scsi_softirq_done
  iperf3-1546    0d.H.   23us : .scsi_handle_queue_ramp_up <-.scsi_decide_disposition
  iperf3-1546    0d.H.   27us : .scsi_finish_command <-.scsi_softirq_done
  iperf3-1546    0d.H.   28us : .scsi_device_unbusy <-.scsi_finish_command
  iperf3-1546    0d.H.   29us : .scsi_dec_host_busy <-.scsi_device_unbusy
  iperf3-1546    0d.H.   34us : .sd_done <-.scsi_finish_command
  iperf3-1546    0d.H.   37us : .scsi_io_completion <-.scsi_finish_command
  iperf3-1546    0d.H.   39us : .scsi_end_request <-.scsi_io_completion
  iperf3-1546    0d.H.   40us : .blk_update_request <-.scsi_end_request
  iperf3-1546    0d.H.   43us : .blk_account_io_completion <-.blk_update_request
  iperf3-1546    0d.H.   47us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.   50us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.   52us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.   55us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.   57us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.   58us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.   60us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.   62us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.   63us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.   65us : .__wake_up <-.__wake_up_bit
  iperf3-1546    0d.H.   66us : .__wake_up_common_lock <-.__wake_up_bit
  iperf3-1546    0d.H.   67us : ._raw_spin_lock_irqsave <-.__wake_up_common_lock
  iperf3-1546    0d.H.   69us : .__wake_up_common <-.__wake_up_common_lock
  iperf3-1546    0d.H.   71us : .wake_bit_function <-.__wake_up_common
  iperf3-1546    0d.H.   73us : .autoremove_wake_function <-.wake_bit_function
  iperf3-1546    0d.H.   74us : .default_wake_function <-.autoremove_wake_function
  iperf3-1546    0d.H.   75us : .try_to_wake_up <-.autoremove_wake_function
  iperf3-1546    0d.H.   76us : ._raw_spin_lock_irqsave <-.try_to_wake_up
  iperf3-1546    0d.H.   82us : .select_task_rq_fair <-.try_to_wake_up
  iperf3-1546    0d.H.   85us : .available_idle_cpu <-.select_task_rq_fair
  iperf3-1546    0d.H.   89us : ._raw_spin_lock <-.try_to_wake_up
  iperf3-1546    0d.H.   90us : .update_rq_clock <-.try_to_wake_up
  iperf3-1546    0d.H.   93us : .ttwu_do_activate <-.try_to_wake_up
  iperf3-1546    0d.H.   94us : .activate_task <-.ttwu_do_activate
  iperf3-1546    0d.H.   97us : .enqueue_task_fair <-.activate_task
  iperf3-1546    0d.H.  100us : .update_curr <-.enqueue_task_fair
  iperf3-1546    0d.H.  102us : .update_min_vruntime <-.update_curr
  iperf3-1546    0d.H.  104us : .__update_load_avg_se <-.enqueue_task_fair
  iperf3-1546    0d.H.  106us : .decay_load <-.__update_load_avg_se
  iperf3-1546    0d.H.  108us : .decay_load <-.__update_load_avg_se
  iperf3-1546    0d.H.  109us : .decay_load <-.__update_load_avg_se
  iperf3-1546    0d.H.  110us : .__accumulate_pelt_segments <-.__update_load_avg_se
  iperf3-1546    0d.H.  111us : .decay_load <-.__accumulate_pelt_segments
  iperf3-1546    0d.H.  112us : .decay_load <-.__accumulate_pelt_segments
  iperf3-1546    0d.H.  114us : .__update_load_avg_cfs_rq <-.enqueue_task_fair
  iperf3-1546    0d.H.  115us : .decay_load <-.__update_load_avg_cfs_rq
  iperf3-1546    0d.H.  117us : .decay_load <-.__update_load_avg_cfs_rq
  iperf3-1546    0d.H.  118us : .decay_load <-.__update_load_avg_cfs_rq
  iperf3-1546    0d.H.  118us : .__accumulate_pelt_segments <-.__update_load_avg_cfs_rq
  iperf3-1546    0d.H.  119us : .decay_load <-.__accumulate_pelt_segments
  iperf3-1546    0d.H.  120us : .decay_load <-.__accumulate_pelt_segments
  iperf3-1546    0d.H.  123us : .__enqueue_entity <-.enqueue_task_fair
  iperf3-1546    0d.H.  127us : .hrtick_update <-.activate_task
  iperf3-1546    0d.H.  129us : .ttwu_do_wakeup <-.try_to_wake_up
  iperf3-1546    0d.H.  130us : .check_preempt_curr <-.ttwu_do_wakeup
  iperf3-1546    0d.H.  132us : .check_preempt_wakeup <-.check_preempt_curr
  iperf3-1546    0d.H.  133us : .update_curr <-.check_preempt_wakeup
  iperf3-1546    0d.H.  135us : .wakeup_gran <-.check_preempt_wakeup
  iperf3-1546    0d.H.  136us : .set_next_buddy <-.check_preempt_wakeup
  iperf3-1546    0d.H.  138us : .resched_curr <-.check_preempt_wakeup
  iperf3-1546    0d.H.  141us : ._raw_spin_unlock_irqrestore <-.try_to_wake_up
  iperf3-1546    0d.H.  142us : ._raw_spin_unlock_irqrestore <-.__wake_up_common_lock
  iperf3-1546    0d.H.  145us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  146us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  147us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  149us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  151us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  152us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  154us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  155us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  156us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  157us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  159us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  160us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  161us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  162us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  163us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  164us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  165us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  166us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  167us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  168us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  169us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  170us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  172us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  172us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  173us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  175us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  176us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  177us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  178us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  179us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  181us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  182us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  182us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  183us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  184us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  185us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  187us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  188us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  189us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  190us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  191us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  192us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  192us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  194us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  195us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  196us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  197us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  198us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  199us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  200us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  201us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  202us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  204us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  205us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  206us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  210us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  210us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  212us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  213us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  214us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  216us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  216us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  217us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  218us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  219us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  220us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  221us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  223us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  224us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  225us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  226us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  227us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  228us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  229us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  230us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  232us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  233us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  234us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  235us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  236us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  236us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  238us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  239us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  240us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  241us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  242us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  243us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  244us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  245us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  246us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  248us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  248us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  250us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  251us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  252us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  253us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  255us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  258us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  260us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  261us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  264us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  266us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  267us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  268us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  269us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  271us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  271us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  272us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  274us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  275us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  276us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  277us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  278us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  279us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  280us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  281us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  282us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  283us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  284us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  285us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  287us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  288us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  289us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  290us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  291us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  292us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  293us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  295us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  296us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  296us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  298us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  298us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  299us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  300us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  301us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  303us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  304us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  305us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  306us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  306us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  308us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  309us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  310us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  311us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  312us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  313us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  314us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  315us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  316us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  317us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  319us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  320us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  320us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  321us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  322us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  323us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  325us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  326us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  327us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  328us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  329us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  330us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  331us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  332us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  333us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  335us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  336us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  337us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  338us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  339us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  339us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  341us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  342us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  343us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  344us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  345us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  346us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  347us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  348us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  349us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  351us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  352us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  353us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  353us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  354us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  356us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  357us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  359us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  361us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  362us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  365us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  366us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  369us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  370us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  370us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  372us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  373us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  374us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  375us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  376us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  380us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  381us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  382us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  383us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  384us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  386us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  386us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  387us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  388us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  389us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  391us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  392us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  392us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  393us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  394us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  395us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  397us : .bio_advance <-.blk_update_request
  iperf3-1546    0d.H.  398us : .bio_endio <-.blk_update_request
  iperf3-1546    0d.H.  399us : .rq_qos_done_bio <-.bio_endio
  iperf3-1546    0d.H.  400us : .end_bio_bh_io_sync <-.bio_endio
  iperf3-1546    0d.H.  401us : .end_buffer_read_sync <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  402us : .__end_buffer_read_notouch <-.end_buffer_read_sync
  iperf3-1546    0d.H.  403us : .unlock_buffer <-.end_buffer_read_sync
  iperf3-1546    0d.H.  404us : .wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  405us : .__wake_up_bit <-.unlock_buffer
  iperf3-1546    0d.H.  406us : .bio_put <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  407us : .bio_free <-.end_bio_bh_io_sync
  iperf3-1546    0d.H.  408us : .mempool_free <-.bio_free
  iperf3-1546    0d.H.  409us : .mempool_free_slab <-.mempool_free
  iperf3-1546    0d.H.  410us : .kmem_cache_free <-.mempool_free_slab
  iperf3-1546    0d.H.  411us : .___cache_free <-.kmem_cache_free
  iperf3-1546    0d.H.  413us : .add_disk_randomness <-.scsi_end_request
  iperf3-1546    0d.H.  414us : .add_timer_randomness <-.add_disk_randomness
  iperf3-1546    0d.H.  416us : .mix_pool_bytes <-.add_timer_randomness
  iperf3-1546    0d.H.  417us : ._raw_spin_lock_irqsave <-.mix_pool_bytes
  iperf3-1546    0d.H.  418us : ._mix_pool_bytes <-.mix_pool_bytes
  iperf3-1546    0d.H.  423us : ._raw_spin_unlock_irqrestore <-.mix_pool_bytes
  iperf3-1546    0d.H.  426us : .credit_entropy_bits <-.add_timer_randomness
  iperf3-1546    0d.H.  429us : .scsi_mq_uninit_cmd <-.scsi_end_request
  iperf3-1546    0d.H.  430us : .scsi_mq_free_sgtables <-.scsi_mq_uninit_cmd
  iperf3-1546    0d.H.  432us : .scsi_uninit_cmd <-.scsi_mq_uninit_cmd
  iperf3-1546    0d.H.  434us : .sd_uninit_command <-.scsi_uninit_cmd
  iperf3-1546    0d.H.  435us : .scsi_del_cmd_from_list <-.scsi_end_request
  iperf3-1546    0d.H.  439us : .ktime_get <-.__blk_mq_end_request
  iperf3-1546    0d.H.  442us : .blk_account_io_done <-.__blk_mq_end_request
  iperf3-1546    0d.H.  445us : .part_round_stats <-.blk_account_io_done
  iperf3-1546    0d.H.  447us : .part_in_flight <-.part_round_stats
  iperf3-1546    0d.H.  451us : .blk_mq_in_flight <-.part_in_flight
  iperf3-1546    0d.H.  454us : .blk_mq_queue_tag_busy_iter <-.blk_mq_in_flight
  iperf3-1546    0d.H.  460us : .bt_for_each <-.blk_mq_queue_tag_busy_iter
  iperf3-1546    0d.H.  464us : .blk_mq_check_inflight <-.bt_for_each
  iperf3-1546    0d.H.  466us : .blk_queue_exit <-.blk_mq_queue_tag_busy_iter
  iperf3-1546    0d.H.  468us : .part_round_stats_single.isra.48 <-.part_round_stats
  iperf3-1546    0d.H.  470us : .part_dec_in_flight <-.blk_account_io_done
  iperf3-1546    0d.H.  472us : .blk_mq_free_request <-.scsi_end_request
  iperf3-1546    0d.H.  476us : .dd_finish_request <-.blk_mq_free_request
  iperf3-1546    0d.H.  480us : .rq_qos_done <-.blk_mq_free_request
  iperf3-1546    0d.H.  482us : .__blk_mq_free_request <-.scsi_end_request
  iperf3-1546    0d.H.  483us : .blk_mq_put_tag <-.__blk_mq_free_request
  iperf3-1546    0d.H.  490us : .blk_mq_put_tag <-.__blk_mq_free_request
  iperf3-1546    0d.H.  494us : .blk_mq_sched_restart <-.__blk_mq_free_request
  iperf3-1546    0d.H.  495us : .blk_queue_exit <-.__blk_mq_free_request
  iperf3-1546    0d.H.  497us : .blk_mq_run_hw_queues <-.scsi_end_request
  iperf3-1546    0d.H.  498us : .blk_mq_run_hw_queue <-.blk_mq_run_hw_queues
  iperf3-1546    0d.H.  503us : .dd_has_work <-.blk_mq_run_hw_queue
  iperf3-1546    0d.H.  505us : .put_device <-.scsi_end_request
  iperf3-1546    0d.H.  511us : .irq_exit <-.doorbell_exception
  iperf3-1546    0d.H.  512us : .vtime_account_system <-.irq_exit
  iperf3-1546    0d.H.  513us : .vtime_delta.isra.5 <-.vtime_account_system
  iperf3-1546    0d.s.  514us : .rcu_irq_exit <-.irq_exit
  iperf3-1546    0d.s.  515us : .rcu_nmi_exit <-.irq_exit
  iperf3-1546    0d.s.  520us : .__check_irq_replay
  iperf3-1546    0d.s.  524us+: .tracer_hardirqs_on <-.__check_irq_replay
  iperf3-1546    0d.s.  542us : <stack trace>
 => .arch_local_irq_restore
 => .__do_softirq
 => .irq_exit
 => .__do_irq
 => .call_do_irq
 => .do_IRQ
 => exc_0x500_common
 => .arch_local_irq_restore
 => ._raw_spin_unlock_irqrestore
 => .mod_timer
 => .sk_reset_timer
 => .tcp_rearm_rto
 => .tcp_event_new_data_sent
 => .tcp_write_xmit
 => .tcp_sendmsg_locked
 => .tcp_sendmsg
 => .inet_sendmsg
 => .sock_sendmsg
 => .sock_write_iter
 => .__vfs_write
 => .vfs_write
 => .ksys_write
 => system_call

延迟比较大的部分,会有+、#等特殊标号:

‘$’ - greater than 1 second
‘@’ - greater than 100 milisecond
‘*’ - greater than 10 milisecond
‘#’ - greater than 1000 microsecond
‘!’ - greater than 100 microsecond
‘+’ - greater than 10 microsecond
’ ’ - less than or equal to 10 microsecond.

hardirq/softirq
可以设置为以下值

H:表示在一次软中断中发生了硬件中断
h:表示硬件中断的发生
s:表示软件中断的发生
.:表示没有中断发生

delay
用特殊符号表示延时时间

$:大于1s
@:大于100ms
*:大于10ms
#:大于1000us
!:大于100us
+:大于10us

可以分析函数调用和相应函数耗时来分析代码流程。
irqsoff可以追踪系统调用中延时最大的函数并显示出调用流程
tracing_max_latency可以设置超过该数值的函数调用

猜你喜欢

转载自blog.csdn.net/qq_44710568/article/details/132456153
今日推荐