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

前端 未结 3 849
南旧
南旧 2021-01-31 03:01

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

3条回答
  •  情歌与酒
    2021-01-31 03:13

    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.

提交回复
热议问题