用 perf 追蹤系統狀態

在「Make Your Program Slower With Threads」這邊看到的工具:「Linux kernel profiling with perf」。

Ubuntu 上的安裝方式是安裝 linux-tools,不過我的機器上是安裝 linux-tools-lts-raring

先從比較簡單的 stat,基本的用法很簡單,後面接指令就可以了:

perf stat ls -al

這樣會出現基本的執行狀況,像是這樣:

 Performance counter stats for 'ls -al':

         11.236723 task-clock                #    0.703 CPUs utilized          
               341 context-switches          #    0.030 M/sec                  
                 0 cpu-migrations            #    0.000 K/sec                  
               453 page-faults               #    0.040 M/sec                  
         8,186,524 cycles                    #    0.729 GHz                    
    stalled-cycles-frontend 
    stalled-cycles-backend  
        10,366,309 instructions              #    1.27  insns per cycle        
         2,122,560 branches                  #  188.895 M/sec                  
            36,979 branch-misses             #    1.74% of all branches        

       0.015977493 seconds time elapsed

更複雜的用法在 Tutorial 那篇文章裡面有說明。

Leave a Reply

Your email address will not be published. Required fields are marked *