Re: Can't use gprof



On Jun 13, 12:09 pm, desktop <f...@xxxxxxx> wrote:
....
Ups I have correct that error but I still get the same error when trying
to run

gprof -b main gmon.out > results.txt

The gmon.out file is supposed to be created by the executable itself.
The -pg compiler option results in code being added to your program
such that when it calls exit() or returns from main(), the profiling
code takes control and writes out the profiling data to the file
gmon.out. Only then, after having run your program, can you then run
gprof on the generated gmon.out file.

To review:
1) build program using -pg option both when compiling and linking
(the output of make should confirm whether you have this correct)
2) run program, exercising the code that you want to profile and
bringing the program to a normal exit (you won't get any profile
output if the program dies from a signal)
3) run gprof

Programs that use chdir() or fork() or change UID or GID have
additional complications: the gmon.out file is created in the
process's current directory when exit() is called. If the process
doesn't have permission to create and or write to that file, then it
won't be generated. Processes that fork() and then call exit() in
more than on process can overwrite or corrupt the gmon.out file.


Philip Guenther

.



Relevant Pages

  • Re: Is intrinsic MIN inefficient?
    ... > gprof to profile the execution on the most recent run. ... Does gprof give timings for MIN itself? ... profiling results. ... > A second DO loop inside the subroutine includes a line like ...
    (comp.lang.fortran)
  • Re: Profiling of shared libraries
    ... After spending several hours with gprof, ... about the functions in the shared libraries. ... profiling shared libraries. ... OProfile is a system-wide profiler for Linux systems, capable of profiling all running code at low overhead. ...
    (comp.unix.programmer)
  • Re: gprof - profilers in general
    ... while we're discussing profiling anyhow I'd like to ask a question... ... gprof may be good but is not be the ultimate tool... ... embedded devices (Xscale with older 2.4 kernel). ...
    (comp.os.linux.development.apps)
  • Re: good profiling tools
    ... I am lookign for good and reliable profiling tools that work on ... FreeBSD. ... I am using gprof but am wondering if there are better tools ...
    (freebsd-performance)