home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / mach-o / gmon.h < prev    next >
C/C++ Source or Header  |  1993-01-20  |  5KB  |  164 lines

  1. /*
  2.  * Copyright (c) 1980 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  *
  6.  *    @(#)gmon.h    5.1 (Berkeley) 5/30/85
  7.  */
  8.  
  9. /*
  10.  * Histogram counters are unsigned shorts (according to the kernel).
  11.  */
  12. #define    HISTCOUNTER    unsigned short
  13.  
  14. /*
  15.  * Fraction of text space to allocate for histogram counters here, 1/2
  16.  */
  17. #define    HISTFRACTION    2
  18.  
  19. /*
  20.  * Fraction of text space to allocate for from hash buckets.
  21.  * The value of HASHFRACTION is based on the minimum number of bytes
  22.  * of separation between two subroutine call points in the object code.
  23.  * Given MIN_SUBR_SEPARATION bytes of separation the value of
  24.  * HASHFRACTION is calculated as:
  25.  *
  26.  *     HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1);
  27.  *
  28.  * For the VAX,
  29.  *    the shortest two call sequence is:
  30.  *         calls    $0,(r0)
  31.  *        calls    $0,(r0)
  32.  *     which is separated by only three bytes, thus HASHFRACTION is 
  33.  *    calculated as:
  34.  *        HASHFRACTION = 3 / (2 * 2 - 1) = 1
  35.  *
  36.  * For the m68k,
  37.  *    the shortest two call sequence is:
  38.  *         jsr    a0
  39.  *        jsr    a0
  40.  *     which is separated by only four bytes, thus HASHFRACTION is 
  41.  *    calculated as:
  42.  *        HASHFRACTION = 4 / (2 * 2 - 1) = 1
  43.  *
  44.  * For all RISC machines
  45.  *    the shortest two call sequence is 2 32-bit instructions,
  46.  *     which is separated by only four bytes, thus HASHFRACTION is 
  47.  *    calculated as:
  48.  *        HASHFRACTION = 4 / (2 * 2 - 1) = 1
  49.  *
  50.  * For the i386,
  51.  *    the shortest two call sequence is:
  52.  *         call    %eax
  53.  *        call    %eax
  54.  *     which is separated by only two bytes, thus HASHFRACTION is 
  55.  *    calculated as:
  56.  *        HASHFRACTION = 2 / (2 * 2 - 1) = 0
  57.  *    So on the i386 we use a HASHFRACTION of 1 instead and it can fail
  58.  *    to determine that two call sites are different.  But since all
  59.  *    the call site address in gprof(1) is currently used for is
  60.  *    to determine which routine was doing the calling it works for now.
  61.  *
  62.  * Note that the division above rounds down, thus if MIN_SUBR_FRACTION
  63.  * is less than three, this algorithm will not work!
  64.  */
  65. #define    HASHFRACTION    1
  66.  
  67. /*
  68.  * percent of text space to allocate for tostructs with a minimum.
  69.  */
  70. #define ARCDENSITY    4
  71. #define MINARCS        50
  72.  
  73. #ifndef ASSEMBLER
  74. /*
  75.  * The tostruct is used internal to the monitor library routines to implement
  76.  * the recording of calls via mcount().
  77.  */
  78. struct tostruct {
  79.     char        *selfpc;
  80.     long        count;
  81.     unsigned short    link;
  82.     unsigned short    order;
  83. };
  84.  
  85. /*
  86.  * The phdr (profile header) structure is what appears at the beginning of a
  87.  * mon.out (cc(1) -p) and gmon.out (cc(1) -pg) file and describes the histogram
  88.  * counters.  The histogram counters are unsigned shorts which follow after the
  89.  * header for ncnt - sizeof(struct phdr) bytes.
  90.  */
  91. struct phdr {
  92.     char    *lpc;     /* low program counter */
  93.     char    *hpc;     /* high program counter */
  94.     int        ncnt;    /* number of bytes of histogram counters minius
  95.                sizeof(struct phdr) that follow */
  96. };
  97.  
  98. /*
  99.  * In a gmon.out (cc(1) -pg) file what follows the above histogram counters are
  100.  * the raw arcs.  A raw arc contains pointers to the calling site, the called
  101.  * site and a count.  These repeat in the gmon.out file after the histogram
  102.  * counters to the end of the file.
  103.  */
  104. struct rawarc {
  105.     unsigned long    raw_frompc;
  106.     unsigned long    raw_selfpc;
  107.     unsigned long    raw_count;
  108. };
  109.  
  110. /*
  111.  * In order to support more information than in the original mon.out and
  112.  * gmon.out files there is an alternate gmon.out file format.  The alternate
  113.  * gmon.out file format starts with a magic number then separates the
  114.  * information with gmon_data structs.
  115.  */
  116. #define GMON_MAGIC 0xbeefbabe
  117. struct gmon_data {
  118.     unsigned long type; /* constant for type of data following this struct */
  119.     unsigned long size; /* size in bytes of the data following this struct */
  120. };
  121.  
  122. /*
  123.  * The GMONTYPE_SAMPLES gmon_data.type is for the histogram counters described
  124.  * above and has a struct phdr followed by the counters.
  125.  */
  126. #define GMONTYPE_SAMPLES    1
  127. /*
  128.  * The GMONTYPE_RAWARCS gmon_data.type is for the raw arcs described above.
  129.  */
  130. #define GMONTYPE_RAWARCS    2
  131. /*
  132.  * The GMONTYPE_ARCS_ORDERS gmon_data.type is for the raw arcs with a call
  133.  * order field.  The order is the order is a sequence number for the order each
  134.  * call site was executed.  Raw_order values start at 1 not zero.  Other than
  135.  * the raw_order field this is the same information as in the struct rawarc.
  136.  */
  137. #define GMONTYPE_ARCS_ORDERS    3
  138. struct rawarc_order {
  139.     unsigned long    raw_frompc;
  140.     unsigned long    raw_selfpc;
  141.     unsigned long    raw_count;
  142.     unsigned long    raw_order;
  143. };
  144. /*
  145.  * The GMONTYPE_RLD_STATE gmon_data.type is for the rld_load()'ed state of the
  146.  * program.
  147.  * The informations starts with an unsigned long with the count of states:
  148.  *    rld_nloaded_states
  149.  * Then each state follows in the file.  The state is made up of 
  150.  *    header_addr (where rld loaded this set of objects)
  151.  *    nobjectfiles (the number of objects in this set)
  152.  *        offsets into the string table (one for each object in the set)
  153.  *    nbytes of string table
  154.  *        the file name strings null terminated.
  155.  */
  156. #define GMONTYPE_RLD_STATE    4
  157. #endif !ASSEMBLER
  158.  
  159. /*
  160.  * general rounding functions.
  161.  */
  162. #define ROUNDDOWN(x,y)    (((x)/(y))*(y))
  163. #define ROUNDUP(x,y)    ((((x)+(y)-1)/(y))*(y))
  164.