使用 valgrind 了解每个函数花费的时间(以秒为单位)
是否有任何可以在命令窗口中使用的 valgrind 扩展,可以帮助我了解 C 代码中每个函数所花费的时间(以秒为单位)?
谢谢=)
is there any extension of valgrind, that can be used in the command window, that would help me know the time, in seconds, spent in each function in my C code?
thanks =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于机器指令分析,请使用 valgrind 的 callgrind (另外,cachegrind 可以进行缓存和分支预测分析,这非常好)。
对于时间测量,请使用 google 的 cpu profiler,它提供的结果比 gprof 更好。您可以设置采样频率,它可以将输出显示为漂亮的带注释的调用图。
For machine instruction profiling use valgrind's callgrind (also, cachegrind can do cache and branch prediction profiling which is quite nice).
For time measurements use google's cpu profiler, it gives way better results than gprof. You can set sampling frequency and it can show the output as a nice annotated call graph.
Valgrind 不适合测量时间,因为在 valgrind 中运行应用程序会扭曲结果(速度变慢、CPU 与 I/O)。因此 valgrind 分析工具 callgrind 不测量时间,而是测量 CPU 指令。仅当您的瓶颈受 CPU 限制(因此 CPU 指令很重要)时,Callgrind 才有用,然后测量的 CPU 指令将与所花费的时间成正比。如果涉及大量 I/O 或多个进程,则它没有用。那么您应该使用采样分析器,例如 sysprof 或 gprof(Edit 2020:perf)。它以间隔时间检查该过程所处的功能,从而减少扭曲的结果。
Valgrind isn't suited for measuring time, as running an application in valgrind distorts the results (slowdown, CPU vs. I/O). Thus valgrind profiling tool callgrind doesn't measure time but CPU instructions. Callgrind is only useful if your bottleneck is CPU-bound (thus CPU instructions matter), then CPU instructions measured will be in proportion to the time spent. It's not useful if heavy I/O or multiple processes are involved. Then you should use a sampling profiler, like sysprof or gprof (Edit 2020: perf). That checks in intervals which function the process is in, with less distorted results.
使用此链接。我认为像 Callgrind 这样的东西应该可以解决问题。
Use this link. I would think something like
Callgrind
should do the trick.