Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling programs written in C or C++

Tags:

c++

c

profile

What would you suggest the best tool to profile C/C++ code and determine which parts are taking the most time. Currently, I'm just relying on logs but ofcourse the information is not accurate since unnecessary delays are introduced.

Preferrably, the tool would also be able to detect/suggest areas which could be optimized, if such tool exist.

Platform: Linux

The application shall be used on an embedded environment so it should be lightweight and external (not a plugin on some IDE).

like image 584
green_t Avatar asked Dec 01 '22 12:12

green_t


2 Answers

I can heartily recommend callgrind in combination with KCachegrind.

like image 170
Konrad Rudolph Avatar answered Dec 05 '22 05:12

Konrad Rudolph


"gprof" on linux/freebsd is a quite simple and efficient tool to identify which routines are hogging the cPU at runtime. It gives both nested and flat profile of functions. It gives you the percentage of CPU time taken by each function executed during the runtime of the profiler, and also the percentage taken within the function itself, and the percentage taken by its child functions. That helps you easily segregate the offending functions.

like image 40
Harty Avatar answered Dec 05 '22 05:12

Harty