The poor man's profiler
You can profile an application just by using GDB to stop it at arbitrary intervals to see what it is doing. This is the poor man's profiler. It is easy to set up and is one way of gathering profile data.
The procedure is simple:
- Attach to the process using
gdbserver
(for a remote debug) or GDB (for a
native debug). The process stops. - Observe the function it stopped in. You can use the
backtrace
GDB command
to see the call stack. - Type
continue
so that the program resumes. - After a while, press Ctrl + C to stop it again, and go back to step 2.
If you repeat steps 2 to 4 several times, you will quickly get an idea of whether it is looping or making progress, and if you repeat them often enough, you will get an idea of where the hotspots in the code are.
There is a whole web page dedicated to this idea at http://poormansprofiler.org, together with scripts that make it a little easier. I have used this technique many times...