google-pprof
982 2020-01-14 18:00:55 google-pprof --pdf ./demo /tmp/profile > output.pdf 983 2020-01-14 18:02:26 g++ -o demo demo.cpp -lprofiler 984 2020-01-14 18:02:29 ./demo 985 2020-01-14 18:02:40 google-pprof --pdf ./demo /tmp/profile > output.pdf 986 2020-01-14 19:41:14 ls 987 2020-01-14 19:41:29 vi demo.cpp 988 2020-01-14 19:41:49 g++ -o demo demo.cpp -lprofiler 989 2020-01-14 19:42:01 ./demo 990 2020-01-14 19:42:09 google-pprof --pdf ./demo /tmp/profile > output.pdf 991 2020-01-14 19:43:02 google-pprof --pdf ./demo my.prof > output.pdf 992 2020-01-14 19:43:27 g++ -o demo demo.cpp -lprofiler 993 2020-01-14 19:43:30 ./demo 994 2020-01-14 19:43:41 google-pprof --pdf ./demo my.prof > output.pdf 995 2020-01-14 19:44:02 history
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//#include <google/profiler.h> #include <gperftools/profiler.h> #include <signal.h> #include <stdlib.h> #include <iostream> using namespace std; void signal_handler(int signo) { signal(signo, signal_handler); std::cout << "recv signal " << signo << std::endl; //switch(signo) //{ // case SIGTERM: //程序自己退出,或shell里调用kill缺省该进程。该信号可以被阻塞,或被处理 //可以在这里做一些程序退出前的最后处理工作 ProfilerStop(); std::cout << "Process recieve SIGTERM" << std::endl; // break; //} exit(0); } void func1() { int i = 0; while (i < 100000) { ++i; } } void func2() { int i = 0; while (i < 200000) { ++i; } } void func3() { for (int i = 0; i < 1000; ++i) { func1(); func2(); } } int main(){ signal(SIGINT, &signal_handler); ProfilerStart("my.prof"); func3(); while (1) { func3(); } ProfilerStop(); return 0; }
posted on 2020-01-14 19:48 csuyangpeng 阅读(471) 评论(0) 编辑 收藏 举报