I would like to profile my c++ application on linux. I would like to find out how much time my application spent on CPU processing vs time spent on block by IO/being idle.
I know there is a profile tool call valgrind on linux. But it breaks down time spent on each method, and it does not give me an overall picture of how much time spent on CPU processing vs idle? Or is there a way to do that with valgrind.
How do I rename a process on Linux?
1:Why does mmap() fail with ENOMEM on a 1TB sparse file?
valgrind's callgrind tool in conjunction with KCacheGrind for visualization. Library for parsing arguments GNU-style? [closed] KCacheGrind makes it pretty easy to see where the hotspots are.. Setup SVN/LAMP/Test Server/ on linux, where to start? Note: It's been too long since I used it, so I'm not sure if you'll be able to receive I/O Wait time out of that. Best practice for C++ audio capture API under Linux?Perhaps in conjunction with iostat or pidstat you'll be able to see where all the time was spent.. How to implement a timeout in read function call?
time myapp(or maybe
/usr/bin/time myapp, which produces slightly different output to the shell builtin).. This will receive you any thing like:.
In this case, user+sys (kernel) time account for almost all the real time and there's just 0.068s unaccounted for... (probably time spent initally loading the app and its supporting libs).. However, if you were to see:.
real 0m1.412s user 0m1.288s sys 0m0.056s
then your app spent 4.51s not consuming CPU and presumably blocked on IO. Which is the information I think you're looking for.. However, where this simple analysis technique breaks down is:.
real 0m5.732s user 0m1.144s sys 0m0.078s
- Apps which wait on a timer/clock or another external stimulus (e.g event-driven GUI apps). It can't distinguish time waiting on the clock and time waiting on disk/network.
- Multithreaded apps, which need a bit more thinking around to interpret the numbers.
[run your app here].
opcontrol --init opcontorl --vmlinux=/path/to/vmlinux (or --no-vmlinux) opcontrol --start
then to start looking at the results look at the man page on opreport.
opcontrol --stop (or opcontrol --shutdown [man for difference]