tcmalloc編譯使用

一、編譯

https://github.com/gperftools/gperftools/releases
如上鍊接頁面下載需要版本的代碼;

cd /home/code/;
tar -zxvf gperftools-2.7.90.tar.gz;
cd gperftools-2.7.90;
../configure --prefix=/usr/local/lib --disable-cpu-profiler --disable-heap-profiler --disable-heap-checker --disable-debugalloc --enable-minimal 
make && make install
可根據需求打開關閉指定的模塊。 google-perftools的組件,包括TCMalloc、heap-checker、heap-profiler和cpu-profiler共4個組件。

編譯完成生成lib庫在–prefix指定的路徑,文件名:libtcmalloc_minimall.so

二、使用

1)靜態鏈接
在編譯選項的最後加入 /usr/local/lib/libtcmalloc_minimal.a 即可鏈接靜態庫
2)動態鏈接
在編譯選項這裏插入 -L/usr/local/lib -ltcmalloc_minimal 即可;
3)、重啓進程即可使用
啓動進程前執行 export LD_PRELOAD=/usr/local/lib/libtcmalloc_minimal.so即可;

三、其他用途

1)內存泄漏檢測
xxxxxx

四、排障

參考資料:
tcmalloc簡介:https://zhuanlan.zhihu.com/p/29216091

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