views:

149

answers:

4

I have a program written in c++ that I want to profile, and I want to avoid restarting it when I start and stop profiling. Ideally I would be profiling both CPU usage and memory allocation. Is there any tool that will allow me to do this? I'm running on Linux.

A: 

If you can get by with simple metrics, in the past, I have implemented a simple profiler. Track memory and time. Track the start and stop of each function, print a line at the start and stop. Track the memory before and after if important. Have all of this gated by a runtime variable that you can change externally. In a web application, it could be an extra post/get parameter. In a thick client program, it could be an extra switch.

Then, at runtime, you could start to collect data. I have added multiple levels in the past as well to allow for selective and then more detailed data collection.

Good luck.

TheJacobTaylor
+1  A: 

Free

  1. oprofile
  2. perf
  3. SystemTap (probably want a RedHat/CentOS distro for this)

Not Free

  1. VTune
Zan Lynx
A: 

You can try valgrind. It is a bundle of different modules put together into a neat package

rocknroll
+1  A: 

My recommendation would be Zoom from RotateRight - you can download a free 30 day evaluation from their web site.

Paul R
++ Yes, Zoom is a good tool for the performance part. I don't know about the memory part, but I usually find that if there is slowness due to excessive memory allocation, it shows up in performance tuning.
Mike Dunlavey