home *** CD-ROM | disk | FTP | other *** search
- From: gtoal@tharr.UUCP (Graham Toal)
- Newsgroups: alt.sources
- Subject: [comp.sys.acorn] pmp - Poor Mans Profiler (UNOFFICAL version :-))
- Message-ID: <1734@tharr.UUCP>
- Date: 6 Feb 91 06:37:53 GMT
-
- Archive-name: pmp/gthack
-
- [Serendipitously, our mailer broke when I tried to post this earlier, so
- I've had a spare 10 minutes in which to 'tidy' the code up a little :-)]
-
- This was Dan Bernstein's Poor Mans Profiler -- a utility to find out how often
- particular lines of your source have been executed. My apologies to Dan for
- beating it to death. It now works only on ANSI-compatible systems, like
- the Acorn Archimedes for which this posting is intended. (comp.sys.acorn)
- [We've been banned from posting these nasty long sources on c.s.a until we
- can forge enough votes for a comp.sources.acorn :-(]
-
- %------------------------------------------- h.pmplib
- #ifndef PMPLIB_H
- #define PMPLIB_H 1
- #include <stdio.h>
- struct _p {long s; long l; char *f; struct _p *p;};
- extern struct _p *_pc; FILE *_pm(struct _p *t, FILE *fi);
- #define _pr(_ps) (_ps.p = _pc, _pc = &_ps)
- #define P do {static struct _p p = {0,__LINE__,__FILE__,0};\
- if (!((p.s)++)) _pr(p);} while(0)
- #define pmp(fn) fclose(_pm(_pc, fopen(fn,"w")))
- #endif
- %------------------------------------------- c.pmplib
- #include "pmplib.h"
- struct _p *_pc = 0;FILE *_pm(struct _p *t, FILE *fi) {return((t && fi) ?
- _pm(t->p, fi), fprintf(fi,"%s, %ld: %ld\n",t->f,t->l,t->s), fi : fi);}
- %------------------------------------------- c.test
- #include "pmplib.h"
-
- int main()
- {
- int i;
- int j;
-
- /* P: produce profiling information. */
- /* pmp("test-pmp"): save pmp's results in test-pmp. */
-
- for (i = 0;i < 1000;i++)
- {
- P;
- for (j = 0;j < 1000;j++)
- {
- P;
- if (i % 2)
- P;
- }
- }
- pmp("test-pmp");
- }
- %------------------------------------------- sample-out
- c.test, 19: 1000
- c.test, 22: 1000000
- c.test, 24: 500000
- %------------------------------------------- README
- This is pmp, the poor man's profiler.
-
- pmp gives you statement counts.
-
- pmp has one big advantage over every other profiling system I've seen:
- it doesn't force optimization off. You can place profiling marks
- anywhere in your code; you only hurt optimization where you put the
- marks. So if you're sick of having your program slowed down dramatically
- just because the profiler sticks its nose into your inner loops, pmp
- should be a welcome relief.
-
- Of course, pmp is also the smallest profiler known to man. [*now* :-)]
-
- Other than that, it's pretty poor.
-
- This was once pmp version 1.0, 9/13/90, by Daniel J. Bernstein.
- pmp is public domain.
-
- This version is gtoal@ed.ac.uk's hack of the alt.sources posting --
- the timing stuff (which used SIGVTALARM) has been removed, and I've
- (ahem) shortened the code somewhat :-)
-
- To use pmp, just cc test.c pmplib.c
- If you have an editor which lets you step through error listings (Emacs? Twin?)
- in synch with your source, use it to step through the test-pmp output file,
- otherwise merge the profile info with the source by hand (or hack up a prog
- to do it).
-
-
- Good luck!
- PS Dan - I removed a few lines to make it print the profile in forward
- (= reverse to you) order to support the editor-stepping feature... :-)
- %------------------------------------------- END
- --
- (* Posted from tharr.uucp - Public Access Unix - +44 (234) 261804 *)
-