总结下gperftool的使用,写了个leveldb大量写数据的demo用来测试。
install libunwind
git clone git@github.com:libunwind/libunwind.git
cd libunwind/
autoreconf -i
./configure
make
make install
git clone https://github.com/gperftools/gperftools
cd gperftools/
./autogen.sh
./configure
make
make install prefix=/usr
图形化工具
yum install graphviz
yum install ghostscript
测试leveldb的demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #include <cassert> #include <iostream> #include <string> #include <leveldb/db.h> #include <gperftools/profiler.h> using namespace std;
#define ASSERT_STATUS(status, db) \ do{ \ if (!status.ok()) \ { \ delete db; \ return -1; \ } \ } while (0) \
int main() { leveldb::DB* db; leveldb::Options options; options.create_if_missing = true; leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db); assert(status.ok());
for (auto k{0}; k < 10000000; ++k) { std::string key = to_string(k+600000); std::string value = "river_fdsssssdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" + to_string(k); status = db->Put(leveldb::WriteOptions(), key, value); ASSERT_STATUS(status, db); }
delete db; cout << "ok!!!" << endl; return 0; }
|
测试结果
1 2 3 4 5
| g++ run.cpp -std=c++11 -lleveldb -pthread -ltcmalloc -lprofiler -g -o run
HEAPPROFILE="/root/code/leveldb/run" ./run
pprof --pdf run run.0001.heap >run.pdf
|
参考
https://github.com/gperftools/gperftools/blob/master/README
https://github.com/libunwind/libunwind
https://gperftools.github.io/gperftools/heapprofile.html
https://www.cnblogs.com/GODYCA/archive/2013/05/28/3104281.html