home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2665 < prev    next >
Internet Message Format  |  1991-02-05  |  3KB

  1. From: gtoal@tharr.UUCP (Graham Toal)
  2. Newsgroups: alt.sources
  3. Subject: pmp for Acorn Archimedes
  4. Message-ID: <1732@tharr.UUCP>
  5. Date: 6 Feb 91 04:01:02 GMT
  6.  
  7. Archive-name: pmp/ansi
  8.  
  9. This was Dan Bernstein's Poor Mans Profiler -- a utility to find out how often
  10. particular lines of your source have been executed.  My apologies to Dan for
  11. beating it to death.  It now works only on ANSI-compatible systems, like
  12. the Acorn Archimedes for which this posting is intended. (comp.sys.acorn)
  13.  
  14. %------------------------------------------- h.pmplib
  15. #ifndef PMPLIB_H
  16. #define PMPLIB_H 1
  17. #include <stdio.h>
  18. struct pmpcount {long scount; long line; char *file; struct pmpcount *prev;};
  19. extern struct pmpcount *pmpcur; FILE *pmprecurse(struct pmpcount *t, FILE *fi);
  20. #define pmpregister(pmpc) ((pmpc)->prev = pmpcur, pmpcur = (pmpc))
  21. #define P do {static struct pmpcount pmpc = {0,__LINE__,__FILE__,(struct \
  22. pmpcount *)0}; if (!((pmpc.scount)++)) pmpregister(&pmpc); } while(0)
  23. #define pmp(fn) fclose(pmprecurse(pmpcur, fopen(fn,"w")))
  24. #endif
  25. %------------------------------------------- c.pmplib
  26. #include <stdio.h>
  27. #include "pmplib.h"
  28. struct pmpcount *pmpcur = NULL;FILE *pmprecurse(struct pmpcount *t, FILE *fi) {
  29. return((t != NULL && fi != NULL) ? pmprecurse(t->prev, fi), (void) fprintf(fi,
  30. "%s, %ld: %ld\n",t->file,t->line,t->scount), fi : fi);}
  31. %------------------------------------------- c.test
  32. #include "pmplib.h"
  33.  
  34. int main()
  35. {
  36.  int i;
  37.  int j;
  38.  
  39.  /* P: produce profiling information. */
  40.  /* pmp("test-pmp"): save pmp's results in test-pmp. */
  41.  
  42.  for (i = 0;i < 1000;i++)
  43.   {
  44.    P;
  45.    for (j = 0;j < 1000;j++)
  46.     {
  47.      P;
  48.      if (i % 2)
  49.        P;
  50.     }
  51.   }
  52.  pmp("test-pmp");
  53. }
  54. %------------------------------------------- sample-out
  55. c.test, 19: 1000
  56. c.test, 22: 1000000
  57. c.test, 24: 500000
  58. %------------------------------------------- README
  59. This is pmp, the poor man's profiler.
  60.  
  61. pmp gives you statement counts.
  62.  
  63. pmp has one big advantage over every other profiling system I've seen:
  64. it doesn't force optimization off. You can place profiling marks
  65. anywhere in your code; you only hurt optimization where you put the
  66. marks. So if you're sick of having your program slowed down dramatically
  67. just because the profiler sticks its nose into your inner loops, pmp
  68. should be a welcome relief.
  69.  
  70. Of course, pmp is also the smallest profiler known to man.
  71.  
  72. Other than that, it's pretty poor.
  73.  
  74. This was once pmp version 1.0, 9/13/90, by Daniel J. Bernstein.
  75. pmp is public domain.
  76.  
  77. This version is gtoal@ed.ac.uk's hack of the alt.sources posting --
  78. the timing stuff (which used SIGVTALARM) has been removed, and I've
  79. (ahem) shortened the code somewhat :-)
  80.  
  81. To use pmp, just cc test.c pmplib.c
  82. If you have an editor which lets you step through error listings (Emacs? Twin?)
  83. in synch with your source, use it to step through the test-pmp output file,
  84. otherwise merge the profile info with the source by hand (or hack up a prog
  85. to do it).
  86.  
  87.  
  88. Good luck!
  89. PS Dan - I removed a few lines to make it print the profile in increasing
  90. order to support the editor-stepping feature... :-)
  91. %------------------------------------------- END
  92. -- 
  93. (* Posted from tharr.uucp - Public Access Unix - +44 (234) 261804 *)
  94.