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.
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.
You can try valgrind. It is a bundle of different modules put together into a neat package
My recommendation would be Zoom from RotateRight - you can download a free 30 day evaluation from their web site.