bcc-tools工具之profile

profile是用於追蹤程序執行調用流程的工具,類似於perf中的-g指令

相比perf -g而言,profile功能化更加細分,可以根據需要選擇追蹤層面,例如-U(用戶要調用流程) -K (內核態調用流程)

下面具體介紹該工具的使用

採用profile --help,我們可以看到如下介紹:

usage: profile [-h] [-p PID] [-U | -K] [-F FREQUENCY | -c COUNT] [-d] [-a]
               [-f] [--stack-storage-size STACK_STORAGE_SIZE] [-C CPU]
               [duration]

Profile CPU stack traces at a timed interval

positional arguments:
  duration              duration of trace, in seconds   # profile的持續時間

optional arguments:
  -h, --help            show this help message and exit
  -p PID, --pid PID     profile this PID only           # 只追蹤該pid的調用流程
  -U, --user-stacks-only                   # 查看用戶態函數調用流程
                        show stacks from user space only (no kernel space
                        stacks)
  -K, --kernel-stacks-only                  # 只查看內核態調用流程
                        show stacks from kernel space only (no user space
                        stacks)
  -F FREQUENCY, --frequency FREQUENCY                   # profile追蹤採樣頻率  例如: -F 99  表示按照99hz的頻率進行採樣,默認是採用的49hz
                        sample frequency, Hertz
  -c COUNT, --count COUNT                   # 選擇採樣次數 -c 5表示在週期內採樣5次,-c和-F兩者不能同時使用
                        sample period, number of events 
  -d, --delimited       insert delimiter between kernel/user stacks  # 在內核和用戶態之間插入分界符 “---”
  -a, --annotations     add _[k] annotations to kernel frames        # 在顯示的內核函數後面標記 '[k]'標識
  -f, --folded          output folded format, one line per stack (for flame #採用橫向線上模式 xxx;xxx_1;xxxxx_2
                        graphs)
  --stack-storage-size STACK_STORAGE_SIZE                 # 設置調用棧的使用空間和默認支持空間大小
                        the number of unique stack traces that can be stored
                        and displayed (default 16384)
  -C CPU, --cpu CPU     cpu number to run profile on           # 允許幾個cpu運行profile程序     

examples:
    ./profile             # profile stack traces at 49 Hertz until Ctrl-C
    ./profile -F 99       # profile stack traces at 99 Hertz
    ./profile -c 1000000  # profile stack traces every 1 in a million events
    ./profile 5           # profile at 49 Hertz for 5 seconds only
    ./profile -f 5        # output in folded format for flame graphs
    ./profile -p 185      # only profile threads for PID 185
    ./profile -U          # only show user space stacks (no kernel)
    ./profile -K          # only show kernel space stacks (no user)

下面對相關重要指令進行測試分析:

  1. profile -f

在沒有添加-f參數時,可看出是一行線上一個函數調用信息

加入-f參數後,採用每行遞增線上函數調用信息。

  1. profile -d :用於將內核態和用戶態函數通過"--"分割開來,如下圖紅色框框所示

  1. profile -F :用於設置該工具採樣頻率

  1. profile -K -a :用於僅顯示內核調用函數,並且在函數後面增加"_[K]"標識 (156標識進程id號)

  1. profile -c :在採樣週期內對每一個線程xx個event進行採樣

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章