Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GNU C++ Profiling under Linux

0 views
Skip to first unread message

Ignoramus17844

unread,
May 29, 2009, 10:13:43 AM5/29/09
to
I need to profile some piece of C++ code. I am aware of gprof, but it
seems to involve a lot of output and I am concerned that my program
will not even be able to run under my real life load (trading app)
with gprof.

Instead, I wanted to see if I can find a profiler that would stop my
app once in a while, examine stack, and continue to run immediately
after taking a call stack snapshot. After getting so many stack
snapshots, I would be able to get some idea of where time is spent.

Is there something like that for Linux?

(Ubuntu Jaunty in my case).

thanks

i

Maxim Yegorushkin

unread,
May 29, 2009, 10:53:44 AM5/29/09
to
On May 29, 3:13 pm, Ignoramus17844 <ignoramus17...@NOSPAM.

This profiling technique is called sampling and oprofile does that.
SunStudio for Linux (and Solaris) also does that.

--
Max

Markus Raab

unread,
May 30, 2009, 1:34:37 PM5/30/09
to
Ignoramus17844 wrote:

> Is there something like that for Linux?

Have you tried valgrind?

Markus

Rolf Magnus

unread,
May 31, 2009, 9:24:50 AM5/31/09
to
Markus Raab wrote:

If the performance with gprof is an issue, valgrind isn't really an
alternative.

Andrew Tomazos

unread,
May 31, 2009, 10:04:09 AM5/31/09
to
On May 29, 4:13 pm, Ignoramus17844 <ignoramus17...@NOSPAM.

17844.invalid> wrote:
> I wanted to see if I can find a profiler that would stop my
> app once in a while, examine stack, and continue to run immediately
> after taking a call stack snapshot.

It may be easier than you think to roll your own programmatically by
setting up an asynchronous periodic signal interrupt, and within the
signal handler calling the glibc 'backtrace' call.

In the glibc manual see "Signal Handling" and "Backtraces":

http://www.gnu.org/s/libc/manual/html_node/Signal-Handling.html
http://www.gnu.org/s/libc/manual/html_node/Backtraces.html

Enjoy,
Andrew.

--
Andrew Tomazos <and...@tomazos.com> <http://www.tomazos.com>

Jorgen Grahn

unread,
Jun 14, 2009, 5:02:12 AM6/14/09
to
On Fri, 29 May 2009 09:13:43 -0500, Ignoramus17844 <ignoram...@NOSPAM.17844.invalid> wrote:
> I need to profile some piece of C++ code. I am aware of gprof, but it
> seems to involve a lot of output and I am concerned that my program
> will not even be able to run under my real life load (trading app)
> with gprof.

Running code compiled with -pg for gprof *does* slow it down, but try
it before you reject the idea.

It does not "involve a lot of output" -- as far as I can tell it
stores statistics in a memory area proportional to the number of
functions or calls in your program. A file is written, but not until
your program exits.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se> R'lyeh wgah'nagl fhtagn!

0 new messages