【笔记】 使用GNU profiler查找性能瓶颈,查看代码中每个函数所消耗的时间

OS: ubuntu 12.04 

在ubuntu linux下调试C++代码时,我们很可能想要查看每个函数的运行时间,找到代码的性能瓶颈,以便加以修缮。我在师兄的引导下在github中学到了以下这个方法,很受用。

我们使用的是GNU profiler。 具体方法是:(假设现在想编译的代码文件是main.cpp)

  • 编译时添加-pg    比如:    g++ -c -pg main.cpp
  • ./main运行,结束时会生成gmon.out
  • gprof ./main gmon.out | less 查看

参考文献:

https://github.com/roles/deep_learning

  感谢作者和开源的世界~

A mind needs books like a sword needs a whetstone.
原文地址:https://www.cnblogs.com/yzsatcnblogs/p/4277053.html