paul@mecazh.UUCP (Paul Breslaw) (10/16/89)
I have tried profiling a number of C and Pascal programs with prof(1) and gprof(1) under HP-UX6.5 on a 9000/340. A simple example follows. The purpose of the meaningless loop in foo_proc is to consume time so that profile(2) gets a look in. /******************************/ /* foo.c */ #include <malloc.h> #include <stdio.h> #include <mon.h> #define MONBUFSZ 65536 extern etext; WORD monbuf[ MONBUFSZ ]; void foo_proc(); main() { int i; monitor( (int (*)()) 2, (int (*)()) &etext, monbuf, MONBUFSZ, 20 ); for (i = 0; i < 10; i++) foo_proc(); monitor( (int (*)()) 0, (int (*)()) 0, 0, 0, 0 ); exit( 0 ); } void foo_proc() { int i, j; for (i = 0; i < 100000; i++) j = i; } /********************************************/ For prof, I compile as:- cc -p -o foo foo.c For gprof:- cc -G -o foo foo.c Then both prof foo and gprof foo crash with a Floating exception. What am I (or someone else) doing wrong? -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Paul Breslaw, Mecasoft SA, | telephone : 41 1 362 2040 Guggachstrasse 10, CH-8057 Zurich, | e-mail : mcvax!cernvax!mecazh!paul Switzerland. |
andyc@hpopd.HP.COM (Andrew Cunningham) (10/17/89)
/ hpopd:comp.sys.hp / paul@mecazh.UUCP (Paul Breslaw) / 1:34 pm Oct 16, 1989 / >I have tried profiling a number of C and Pascal programs with prof(1) >and gprof(1) under HP-UX6.5 on a 9000/340. > >A simple example follows. The purpose of the meaningless loop in foo_proc >is to consume time so that profile(2) gets a look in. > >/******************************/ >/* foo.c */ > >#include <malloc.h> >#include <stdio.h> >#include <mon.h> > >#define MONBUFSZ 65536 > >extern etext; > >WORD monbuf[ MONBUFSZ ]; > >void foo_proc(); > >main() >{ > int i; > > monitor( (int (*)()) 2, (int (*)()) &etext, monbuf, MONBUFSZ, 20 ); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > for (i = 0; i < 10; i++) foo_proc(); > monitor( (int (*)()) 0, (int (*)()) 0, 0, 0, 0 ); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > exit( 0 ); >} > > > >void foo_proc() >{ > int i, j; > > for (i = 0; i < 100000; i++) > j = i; >} > >/********************************************/ > > >For prof, I compile as:- > cc -p -o foo foo.c > >For gprof:- > cc -G -o foo foo.c > >Then both > prof foo >and > gprof foo >crash with a Floating exception. > >What am I (or someone else) doing wrong? When you compile with -G or -p, the calls to monitor are generated automatically. So, if you delete the two calls to monitor things will work fine. You can use thses calls manually to selectively profile your program; but I haven;t tried this. If you do cc -o foo foo.c foo you will find that mon.out (which is read by prof) is created (by the second monitor() call) without a -p option in sight. This still leads to a floating exception, so I would expect that you haven't got these calls quite right. Hope this helps...... --------------------------------------------------------------------------------- DISCLAIMER: I am not speaking as an employee of Hewlett-Packard. Andrew Cunningham, HP Software Engineering Systems Division, Pinewood E-mail: andyc@hpopd.HP.COM hplabs!hpopd!andyc
sjo@hpfcso.HP.COM (Scott Omdahl) (10/17/89)
>I have tried profiling a number of C and Pascal programs with prof(1) >and gprof(1) under HP-UX6.5 on a 9000/340. > ... >For prof, I compile as:- > cc -p -o foo foo.c > >For gprof:- > cc -G -o foo foo.c > >Then both > prof foo >and > gprof foo >crash with a Floating exception. > >What am I (or someone else) doing wrong? You're simply re-doing some work the compiler does for you. The monitor() calls in your main program are duplicates of the ones in gcrt0.o (gprof) and mcrt0.o (prof). The C compiler links in gcrt0.o or mcrt0.o instead of crt0.o when you specify -G or -p. The duplicate calls in your main program cause a corrupted gmon.out (gprof) or mon.out (prof) data file, which [g]prof chokes on. Simply remove the monitor calls and data declarations from your program and it works fine. Scott Omdahl
bobm@hpfcmgw.HP.COM (Bob Montgomery) (10/18/89)
Re: profiling a number of C and Pascal programs with prof(1) and gprof(1) under HP-UX6.5 on a 9000/340. > main() > { > int i; > > monitor( (int (*)()) 2, (int (*)()) &etext, monbuf, MONBUFSZ, 20 ); > for (i = 0; i < 10; i++) foo_proc(); > monitor( (int (*)()) 0, (int (*)()) 0, 0, 0, 0 ); > exit( 0 ); > } > For prof, I compile as:- > cc -p -o foo foo.c > What am I (or someone else) doing wrong? > Paul Breslaw, Mecasoft SA Get rid of the calls to monitor. When you compile and link with -p, the C startup code from mcrt0.o sets up the buffers and calls monitor before calling main and then calls monitor again at exit. I suspect that your extra calls are causing a munged mon.out file which is confusing the prof command. Selective profiling by turning the profiler on and off is harder than this. Bob Montgomery