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參數后,采用每行遞增線上函數調用信息。

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

                     

      3.profile -F  :用於設置該工具采樣頻率

      

 

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

      

 

       5. profile -c :在采樣周期內對每一個線程xx個event進行采樣

      

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM