Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling partial programs in Linux

I have a program in which significant amount of time is spent loading and saving data. Now I want to know how much time each function is taking in terms of percentage of the total running time. However, I want to exclude the time taken by loading and saving functions from the total time considered by the profiler. Is there any way to do so using gprof or any other popular profiler?

like image 295
MetallicPriest Avatar asked Jul 07 '11 21:07

MetallicPriest


2 Answers

Similarly you can use

valgrind --tool=callgrind --collect-atstart=no --toggle-collect=<function> 

Other options to look at:

--instr-atstart    # to avoid runtime overhead while not profiling

To get instructionlevel stats:

--collect-jumps=yes
--dump-instr=yes

Alternatively you can 'remote control' it on the fly: callgrind_control or annotate your source code (IIRC also with branch predictions stats): callgrind_annotate.

The excellent tool kcachegrind is a marvellous visualization/navigation tool. I can hardly recommend it enough:

enter image description here

like image 169
sehe Avatar answered Sep 28 '22 00:09

sehe


I would consider using something more modern than gprof, such as OProfile. When generating a report using opreport you can use the --exclude-symbols option to exclude functions you are not interested in.

See the OProfile webpage for more details; however for a quick start guide see the OProfile docs page.

like image 32
DaveR Avatar answered Sep 27 '22 22:09

DaveR