Cprofile (Python) in C++?

Cprofile (Python) in C++?

本文关键字:C++ in Python Cprofile      更新时间:2023-10-16

在Python中编写代码时,我通常使用Cprofile,它在控制台中打印配置文件结果:

import cProfile, pstats, StringIO
pr = cProfile.Profile()
pr.enable()
#do stuff
pr.disable()
s = StringIO.StringIO()
ps = pstats.Stats(pr, stream=s).sort_stats('cumulative')
ps.print_stats()
print s.getvalue()

C++还有其他选择吗?

编辑 - 我正在使用VS 2008 Express,Windows 64位。

只需转到Analyze -> Profiler -> Attach/Detach .

Valgrind,特别是callgrind,几乎是C++中执行此操作的标准方式。不过,它比python要复杂一些,因为python基本上可以对每种方法的所有调用进行修补,以生成调用图和其他东西。

http://valgrind.org/docs/manual/cl-manual.html