2

I'm developing in C++(g++) with a non-opensource lib. every time I run the program, the lib will crash (it double-free some memory).

it's ok for my program now. but it's bad for profiling. I use -pg to profiling the program. As a result of the crash, no 'gmon.out' is generated. so I cannot profile it at all.

Question: How to profiling a 'crashy' program (with gprof).

PS. valgrind is ok to analysis a crashy program.

regards!

wuxb
  • 2,572
  • 1
  • 21
  • 30
  • 2
    If valgrind works fine, you could just use it for profiling using callgrind and massif tools. – Robert Bossy Dec 13 '11 at 09:52
  • 1
    1) Fix the bug. 2) Don't expect much from *gprof*. People use it because it's there. *[There are much better ways to do performance tuning.](http://stackoverflow.com/questions/1777556/alternatives-to-gprof/1779343#1779343)* – Mike Dunlavey Dec 13 '11 at 13:34
  • 1
    @Mike Dunlavey:thanks, the link is very helpful, but as I mentioned, the lib is not open, so I cannot fix it:) – wuxb Dec 14 '11 at 10:00
  • OK, so if you want to see how you can speed up your code in the time before it crashes, that method works. – Mike Dunlavey Dec 14 '11 at 13:46

1 Answers1

0

There's a function you can call from your program to dump profile data (the same one that's automatically installed as an atexit handler when you link with -pg), but I don't know what it's called offhand.

The easyist thing to do it, just insert an exit(0); call at a suitable point in your program. Alternatively, you can set a breakpoint and use call exit(0) in GDB (except that debugging the program will affect the profile data if you stop it in the middle).

ams
  • 24,923
  • 4
  • 54
  • 75