home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / libsrc87 / dumpgm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-30  |  1.5 KB  |  64 lines

  1. #include <stdio.h>
  2. #include <memory.h>
  3.  
  4. #define ck_fread fread
  5. #define ck_malloc malloc
  6.  
  7. /* gmon header */
  8. struct gm_header {
  9.     void        *low;        /* low pc  */
  10.     void        *high;        /* hi  pc  */
  11.     unsigned long    nbytes;        /* bytes in header + histo size */
  12. };
  13.  
  14. typedef unsigned short CHUNK; /* type of each histogram entry */
  15.  
  16. struct gm_call {    /* gm call record */
  17.     void    *from;    /* the caller                 */
  18.     void    *to;    /* the called function (callee)        */
  19.     unsigned long ncalls; /* # of calls from FROM to  TO    */
  20. };
  21.  
  22. #define    GMON_FILE    "gmon.out"    /* name of GMON file */
  23.  
  24. main(argc, argv)
  25. int argc;
  26. char **argv;
  27. {
  28.     char *file;
  29.     FILE *fp;
  30.     struct gm_header head;
  31.     struct gm_call   arc;
  32.     unsigned short h;
  33.     unsigned long hist_size;
  34.     unsigned short *hist;
  35.     long i;
  36.  
  37.     if(argc > 1)
  38.     file = *++argv;
  39.     else
  40.     file = GMON_FILE;
  41.     
  42.     if((fp = fopen(file, "rb")) == NULL)
  43.     {
  44.     perror(file);
  45.     exit(1);
  46.     }
  47.     ck_fread(&head, sizeof(head), 1L, fp);
  48.     printf("lowpc %ld   hipc %ld hist size %ld tot %ld\n", head.low,
  49.         head.high, (hist_size = head.nbytes - sizeof(head)), head.nbytes);
  50.     hist = (unsigned short *)ck_malloc(hist_size);
  51.     ck_fread(hist, hist_size, 1L, fp);
  52.     printf("\nHistogram:\n");
  53.     for(i = 0; i < hist_size/sizeof(short); i++)
  54.     printf("%ld:\t%d\n", i, (int)hist[i]);
  55.  
  56.     i = 0;
  57.     printf("\nCall Graph:\n");
  58.     while(fread(&arc, sizeof(arc), 1L, fp) == 1L)
  59.     printf("%ld:\t from %ld\tto %ld\tcalls %ld\n", i++, arc.from, arc.to,
  60.         arc.ncalls);
  61.     fclose(fp);
  62. }
  63.  
  64.