Flame Graph

常看到這種圖,但卻不知道這種圖是用什麼做出來的,或是他的名字:

剛剛在「Igniting Node.js Flames」這邊看到這叫做 Flame Graph,出自「brendangregg/FlameGraph」這邊。

Linux 上可以用 perf 產生資料檔案,在 FreeBSD 或是 Solaris 上可以用 DTrace 產生... 是個來理解效能瓶頸的好工具 :o

用 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 那篇文章裡面有說明。

Netflix 在 USENIX/LISA2014 上講「Linux 效能調校」

NetflixBrendan Gregg 在「Linux Performance Analysis: New Tools and Old Secrets」這份投影片裡面給了很多有用的工具。

「先找出問題」一向是解決問題的大前提,在投影片裡提到了很多工具,像是這兩個看起來就很有用: