天天看點

pprof搭配ceph tell指令分析ceph記憶體

文章目錄

  • ​​安裝​​
  • ​​使用​​
  • ​​使用`ceph tell`産生堆棧資訊文​​
  • ​​使用`pprof`工具分析記憶體及`ceph tell`釋放記憶體​​
  • ​​火焰圖`FlameGraph`可視化程序堆棧資訊​​
pprof是一個google開發的支援可視化、且可分析profile檔案而達到對記憶體的分析。并且能夠輸出文本和圖像來支援分析過程,​​pprof源碼​​

安裝

可以直接通過​

​gperftools​

​工具集來安裝pprop工具

配置海康yum源,然後執行:

​yum install gperftools​

​yum install gperftools-devel​

使用

該分析過程同樣适用于其他二進制檔案

使用​

​ceph tell​

​産生堆棧資訊文
  • 啟動Ceph預設的記憶體分析器

    ​​

    ​ceph tell mon.node1 heap start_profiler​

  • 列印記憶體分析器收集到的堆棧占用資料

    ​​

    ​ceph tell mon.node1 heap stats​

  • 将統計資訊導出到檔案

    ​​

    ​ceph tell mon.node1 heap dump​

    ​​預設導出到​

    ​/var/log/ceph/mon.node1.profile.0001.heap​

使用​

​pprof​

​​工具分析記憶體及​

​ceph tell​

​釋放記憶體
  • 分析一個檔案:

    ​pprof --text /usr/bin/ceph-mon /var/log/ceph/mon.node1.profile.0001.heap​

    ​産生如下輸出:
(pprof) top10
Total: 2525 samples
298  11.8%  11.8%  345  13.7% runtime.mapaccess1_fast64
268  10.6%  22.4% 2124  84.1% main.FindLoops
251   9.9%  32.4%  451  17.9% scanblock
178   7.0%  39.4%  351  13.9% hash_insert
131   5.2%  44.6%  158   6.3% sweepspan
119   4.7%  49.3%  350  13.9% main.DFS
 96   3.8%  53.1%   98   3.9% flushptrbuf
 95   3.8%  56.9%   95   3.8% runtime.aeshash64
 95   3.8%  60.6%  101   4.0% runtime.settype_flush
 88   3.5%  64.1%  988  39.1% runtime.mallocgc      
  • The first column contains the direct memory use in MB. 函數本身使用的記憶體
  • The fourth column contains memory use by the procedure and all of its callees.函數本身記憶體+調用函數記憶體
  • The second and fifth columns are just percentage representations of the numbers in the first and fourth columns. 第二第五列分别為第一列,第四列與total的比值
  • The third column is a cumulative sum of the second column.第三列為(到目前行數為止)第二列所有的和
  • 對比堆檔案:

    ​​

    ​pprof --text --base /var/log/ceph/mon.node1.profile.0001.heap /usr/bin/ceph-mon /var/log/ceph/mon.node1.profile.0003.heap​

  • 釋放已經被​

    ​tcmalloc​

    ​​占用但是沒有被ceph占用的記憶體

    ​​

    ​ceph tell osd.0 heap release​

  • 一旦完成停止分析器

    ​​

    ​ceph tell osd.0 heap stop_profiler​

火焰圖​

​FlameGraph​

​可視化程序堆棧資訊
  • 安裝

    下載下傳​​​FlameGraph​​到自己裝置

  • 進入該目錄下擷取目前程序堆棧資訊 ​​perf工具​​​

    ​perf record -F 99 -p 181 -g --sleep 60​

  • 對生成的資訊進行解析

    ​​

    ​perf script > out.perf​

  • 對解析出來的符号進行折疊

    進入​​

    ​FlamGraph​

    ​​目錄,增加以下檔案的運作權限

    ​​

    ​./stackcollapse-perf.pl out.perf > out.folded​

  • 生成火焰圖

    同樣要增加該檔案的運作權限,生成如下檔案

    ​​

    ​./flamegraph.pl out.folded > kernel.svg​