Back to index

glibc  2.9
gmon.h
Go to the documentation of this file.
00001 /*-
00002  * Copyright (c) 1982, 1986, 1992, 1993
00003  *     The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 4. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  *     @(#)gmon.h    8.2 (Berkeley) 1/4/94
00030  */
00031 
00032 #ifndef       _SYS_GMON_H
00033 #define       _SYS_GMON_H   1
00034 
00035 #include <features.h>
00036 
00037 #include <sys/types.h>
00038 
00039 /*
00040  * See gmon_out.h for gmon.out format.
00041  */
00042 
00043 /* structure emitted by "gcc -a".  This must match struct bb in
00044    gcc/libgcc2.c.  It is OK for gcc to declare a longer structure as
00045    long as the members below are present.  */
00046 struct __bb
00047 {
00048   long               zero_word;
00049   const char         *filename;
00050   long               *counts;
00051   long               ncounts;
00052   struct __bb        *next;
00053   const unsigned long       *addresses;
00054 };
00055 
00056 extern struct __bb *__bb_head;
00057 
00058 /*
00059  * histogram counters are unsigned shorts (according to the kernel).
00060  */
00061 #define       HISTCOUNTER   unsigned short
00062 
00063 /*
00064  * fraction of text space to allocate for histogram counters here, 1/2
00065  */
00066 #define       HISTFRACTION  2
00067 
00068 /*
00069  * Fraction of text space to allocate for from hash buckets.
00070  * The value of HASHFRACTION is based on the minimum number of bytes
00071  * of separation between two subroutine call points in the object code.
00072  * Given MIN_SUBR_SEPARATION bytes of separation the value of
00073  * HASHFRACTION is calculated as:
00074  *
00075  *     HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1);
00076  *
00077  * For example, on the VAX, the shortest two call sequence is:
00078  *
00079  *     calls  $0,(r0)
00080  *     calls  $0,(r0)
00081  *
00082  * which is separated by only three bytes, thus HASHFRACTION is
00083  * calculated as:
00084  *
00085  *     HASHFRACTION = 3 / (2 * 2 - 1) = 1
00086  *
00087  * Note that the division above rounds down, thus if MIN_SUBR_FRACTION
00088  * is less than three, this algorithm will not work!
00089  *
00090  * In practice, however, call instructions are rarely at a minimal
00091  * distance.  Hence, we will define HASHFRACTION to be 2 across all
00092  * architectures.  This saves a reasonable amount of space for
00093  * profiling data structures without (in practice) sacrificing
00094  * any granularity.
00095  */
00096 #define       HASHFRACTION  2
00097 
00098 /*
00099  * Percent of text space to allocate for tostructs.
00100  * This is a heuristic; we will fail with a warning when profiling programs
00101  * with a very large number of very small functions, but that's
00102  * normally OK.
00103  * 2 is probably still a good value for normal programs.
00104  * Profiling a test case with 64000 small functions will work if
00105  * you raise this value to 3 and link statically (which bloats the
00106  * text size, thus raising the number of arcs expected by the heuristic).
00107  */
00108 #define ARCDENSITY   3
00109 
00110 /*
00111  * Always allocate at least this many tostructs.  This
00112  * hides the inadequacy of the ARCDENSITY heuristic, at least
00113  * for small programs.
00114  */
00115 #define MINARCS             50
00116 
00117 /*
00118  * The type used to represent indices into gmonparam.tos[].
00119  */
00120 #define       ARCINDEX      u_long
00121 
00122 /* 
00123  * Maximum number of arcs we want to allow.
00124  * Used to be max representable value of ARCINDEX minus 2, but now 
00125  * that ARCINDEX is a long, that's too large; we don't really want 
00126  * to allow a 48 gigabyte table.
00127  * The old value of 1<<16 wasn't high enough in practice for large C++
00128  * programs; will 1<<20 be adequate for long?  FIXME
00129  */
00130 #define MAXARCS             (1 << 20)
00131 
00132 struct tostruct {
00133        u_long        selfpc;
00134        long          count;
00135        ARCINDEX      link;
00136 };
00137 
00138 /*
00139  * a raw arc, with pointers to the calling site and
00140  * the called site and a count.
00141  */
00142 struct rawarc {
00143        u_long raw_frompc;
00144        u_long raw_selfpc;
00145        long   raw_count;
00146 };
00147 
00148 /*
00149  * general rounding functions.
00150  */
00151 #define ROUNDDOWN(x,y)      (((x)/(y))*(y))
00152 #define ROUNDUP(x,y) ((((x)+(y)-1)/(y))*(y))
00153 
00154 /*
00155  * The profiling data structures are housed in this structure.
00156  */
00157 struct gmonparam {
00158        long int      state;
00159        u_short              *kcount;
00160        u_long        kcountsize;
00161        ARCINDEX      *froms;
00162        u_long        fromssize;
00163        struct tostruct      *tos;
00164        u_long        tossize;
00165        long          tolimit;
00166        u_long        lowpc;
00167        u_long        highpc;
00168        u_long        textsize;
00169        u_long        hashfraction;
00170        long          log_hashfraction;
00171 };
00172 
00173 /*
00174  * Possible states of profiling.
00175  */
00176 #define       GMON_PROF_ON  0
00177 #define       GMON_PROF_BUSY       1
00178 #define       GMON_PROF_ERROR      2
00179 #define       GMON_PROF_OFF 3
00180 
00181 /*
00182  * Sysctl definitions for extracting profiling information from the kernel.
00183  */
00184 #define       GPROF_STATE   0      /* int: profiling enabling variable */
00185 #define       GPROF_COUNT   1      /* struct: profile tick count buffer */
00186 #define       GPROF_FROMS   2      /* struct: from location hash bucket */
00187 #define       GPROF_TOS     3      /* struct: destination/count structure */
00188 #define       GPROF_GMONPARAM      4      /* struct: profiling parameters (see above) */
00189 
00190 __BEGIN_DECLS
00191 
00192 /* Set up data structures and start profiling.  */
00193 extern void __monstartup (u_long __lowpc, u_long __highpc) __THROW;
00194 extern void monstartup (u_long __lowpc, u_long __highpc) __THROW;
00195 
00196 /* Clean up profiling and write out gmon.out.  */
00197 extern void _mcleanup (void) __THROW;
00198 
00199 __END_DECLS
00200 
00201 #endif /* sys/gmon.h */