use valgrind to know time(in seconds) spent in each function

家住魔仙堡 提交于 2019-12-03 04:08:43

问题


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 =)


回答1:


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.




回答2:


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 gprof or sysprof. That checks in intervals which function the process is in, with less distorted results.




回答3:


Use this link. I would think something like Callgrind should do the trick.



来源:https://stackoverflow.com/questions/6663614/use-valgrind-to-know-timein-seconds-spent-in-each-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!