home *** CD-ROM | disk | FTP | other *** search
- From: gtoal@tharr.UUCP (Graham Toal)
- Newsgroups: alt.sources
- Subject: pmp for Acorn Archimedes
- Message-ID: <1732@tharr.UUCP>
- Date: 6 Feb 91 04:01:02 GMT
-
- Archive-name: pmp/ansi
-
- 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)
-
- %------------------------------------------- h.pmplib
- #ifndef PMPLIB_H
- #define PMPLIB_H 1
- #include <stdio.h>
- struct pmpcount {long scount; long line; char *file; struct pmpcount *prev;};
- extern struct pmpcount *pmpcur; FILE *pmprecurse(struct pmpcount *t, FILE *fi);
- #define pmpregister(pmpc) ((pmpc)->prev = pmpcur, pmpcur = (pmpc))
- #define P do {static struct pmpcount pmpc = {0,__LINE__,__FILE__,(struct \
- pmpcount *)0}; if (!((pmpc.scount)++)) pmpregister(&pmpc); } while(0)
- #define pmp(fn) fclose(pmprecurse(pmpcur, fopen(fn,"w")))
- #endif
- %------------------------------------------- c.pmplib
- #include <stdio.h>
- #include "pmplib.h"
- struct pmpcount *pmpcur = NULL;FILE *pmprecurse(struct pmpcount *t, FILE *fi) {
- return((t != NULL && fi != NULL) ? pmprecurse(t->prev, fi), (void) fprintf(fi,
- "%s, %ld: %ld\n",t->file,t->line,t->scount), 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.
-
- 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 increasing
- order to support the editor-stepping feature... :-)
- %------------------------------------------- END
- --
- (* Posted from tharr.uucp - Public Access Unix - +44 (234) 261804 *)
-