The poor man's profiler
Suppose you have a program that's using a lot of CPU. What's it doing in there? What is so slow, dammit?
gdb /proc/8337/exe 8337
Observe which function it was in when you interrupted.
gdb> continue
Let it keep running. Hit C-c to interrupt it later; see where it is; rinse, repeat.
This is only useful if the program has function names in the executable. If you built it yourself, that's probably true. If you got it from a distribution it may not. (I think that's lame.)
Most programs spend most of their time in one routine. Attaching from gdb at random times will tell you which routine this is.
gdb is no substitute for a proper profiler or for kcachegrind. It won't tell you about system-call hotspots. But if your program has a single userspace hot spot it will tell you where that is, and that can be useful information. This requires no special preparation, can be done on almost any machine, and can be applied to a program while it's running with little disruption.
posted Fri 10 Sep 2004 in /software/linux | link
Archives 2008: Apr Feb 2007: Jul May Feb Jan 2006: Dec Nov Oct Sep Aug Jul Jun Jan 2005: Sep Aug Jul Jun May Apr Mar Feb Jan 2004: Dec Nov Oct Sep Aug Jul Jun May Apr Mar Feb Jan 2003: Dec Nov Oct Sep Aug Jul Jun May
Copyright (C) 1999-2007 Martin Pool.