home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / vbcc / machines / amiga68k / libsrc / _prof.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-12-30  |  2.5 KB  |  100 lines

  1. #include <exec/devices.h>
  2. #include <devices/timer.h>
  3. #include <clib/exec_protos.h>
  4.  
  5. #include <stdlib.h>
  6.  
  7. extern struct __exitfuncs *__firstexit;
  8.  
  9. static struct timerequest tr;
  10. struct Device *TimerBase;
  11.  
  12. static long freq;
  13.  
  14. struct pd{
  15.     struct pd *next;
  16.     struct EClockVal total,laststart;
  17.     char *name;
  18.     unsigned long count;
  19. } *first;
  20.  
  21. void _closeprof(void)
  22. /*  schliesst alles und gibt Ergebnis aus   */
  23. {
  24.     struct pd *p,*m;
  25.     printf("Freq=%ld\n",freq);
  26.     p=first;
  27.     while(p){
  28.         if(p!=first)
  29.             printf("%s: calls=%lu,total=%lu,%lu\n",p->name,p->count,p->total.ev_hi,p->total.ev_lo);
  30.         m=p;
  31.         p=p->next;
  32.         FreeMem(m,sizeof(struct pd));
  33.     }
  34.     if(TimerBase) CloseDevice((struct IORequest *)&tr);
  35. }
  36.  
  37. int _initprof(void)
  38. /*  oeffnet timer.device etc.   */
  39. {
  40.     struct __exitfuncs *p,*new;
  41. /*    puts("initprof start");*/
  42.     if(OpenDevice(TIMERNAME,UNIT_ECLOCK,(struct IORequest *)&tr,0)) return(1);
  43.     TimerBase=tr.tr_node.io_Device;
  44.     first=AllocMem(sizeof(struct pd),0);
  45.     if(!first) return(1);
  46.     first->next=0;
  47.     first->name=0;
  48.     freq=ReadEClock(&first->total);
  49.     first->total.ev_hi=first->total.ev_lo=0;
  50.     /*  _closeprof als letzte atexit-Funktion   */
  51.     if(!(new=malloc(sizeof(struct __exitfuncs)))) return(1);
  52.     new->next=0;
  53.     new->func=_closeprof;
  54.     p=__firstexit;
  55.     if(!p){
  56.         __firstexit=new;
  57.     }else{
  58.         while(p->next) p=p->next;
  59.         p->next=new;
  60.     }
  61. /*    puts("initprof end");*/
  62.     return(0);
  63. }
  64. void _startprof(char *name)
  65. /*  wird beim Eintritt in eine Funktion gerufen */
  66. {
  67.     struct pd *p=first;
  68. /*    puts("startprof start");*/
  69.     if(!p) {if(_initprof()) return; else p=first;}
  70.     while(p->name!=name&&p->next!=0) p=p->next;
  71.     if(p->name!=name){
  72.         p->next=AllocMem(sizeof(struct pd),0);
  73.         if(!p->next) return;
  74.         p=p->next;
  75.         p->name=name;
  76.         p->next=0;
  77.         p->count=0;
  78.         p->total.ev_hi=p->total.ev_lo=0;
  79.     }
  80.     p->count++;
  81.     ReadEClock(&p->laststart);
  82. /*    puts("startprof start");*/
  83. }
  84. void _endprof(char *name)
  85. /*  wird am Ende einer Funktion gerufen */
  86. {
  87.     struct pd *p=first;struct EClockVal t;
  88. /*    puts("endprof start");*/
  89.     if(!p) return;
  90.     ReadEClock(&t);
  91.     while(p->name!=name&&p->next!=0) p=p->next;
  92.     if(p->name!=name) {/*puts("no match");*/return;}
  93.     p->total.ev_hi+=t.ev_hi-p->laststart.ev_hi;
  94.     p->total.ev_lo+=t.ev_lo-p->laststart.ev_lo;
  95.     if(t.ev_lo<=p->laststart.ev_lo) p->total.ev_hi++;
  96. /*    puts("endprof end");*/
  97. }
  98.  
  99.  
  100.