gmon.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* $OpenBSD: gmon.h,v 1.7 2013/03/12 09:37:16 mpi Exp $ */
  2. /* $NetBSD: gmon.h,v 1.5 1996/04/09 20:55:30 cgd Exp $ */
  3. /*-
  4. * Copyright (c) 1982, 1986, 1992, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the University nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * @(#)gmon.h 8.2 (Berkeley) 1/4/94
  32. */
  33. #ifndef _SYS_GMON_H_
  34. #define _SYS_GMON_H_
  35. #include <machine/profile.h>
  36. /*
  37. * Structure prepended to gmon.out profiling data file.
  38. */
  39. struct gmonhdr {
  40. u_long lpc; /* base pc address of sample buffer */
  41. u_long hpc; /* max pc address of sampled buffer */
  42. int ncnt; /* size of sample buffer (plus this header) */
  43. int version; /* version number */
  44. int profrate; /* profiling clock rate */
  45. int spare[3]; /* reserved */
  46. };
  47. #define GMONVERSION 0x00051879
  48. /*
  49. * histogram counters are unsigned shorts (according to the kernel).
  50. */
  51. #define HISTCOUNTER unsigned short
  52. /*
  53. * fraction of text space to allocate for histogram counters here, 1/2
  54. */
  55. #define HISTFRACTION 2
  56. /*
  57. * Fraction of text space to allocate for from hash buckets.
  58. * The value of HASHFRACTION is based on the minimum number of bytes
  59. * of separation between two subroutine call points in the object code.
  60. * Given MIN_SUBR_SEPARATION bytes of separation the value of
  61. * HASHFRACTION is calculated as:
  62. *
  63. * HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1);
  64. *
  65. * For example, on the VAX, the shortest two call sequence is:
  66. *
  67. * calls $0,(r0)
  68. * calls $0,(r0)
  69. *
  70. * which is separated by only three bytes, thus HASHFRACTION is
  71. * calculated as:
  72. *
  73. * HASHFRACTION = 3 / (2 * 2 - 1) = 1
  74. *
  75. * Note that the division above rounds down, thus if MIN_SUBR_FRACTION
  76. * is less than three, this algorithm will not work!
  77. *
  78. * In practice, however, call instructions are rarely at a minimal
  79. * distance. Hence, we will define HASHFRACTION to be 2 across all
  80. * architectures. This saves a reasonable amount of space for
  81. * profiling data structures without (in practice) sacrificing
  82. * any granularity.
  83. */
  84. #define HASHFRACTION 2
  85. /*
  86. * percent of text space to allocate for tostructs with a minimum.
  87. */
  88. #define ARCDENSITY 2
  89. #define MINARCS 50
  90. #define MAXARCS ((1 << (8 * sizeof(HISTCOUNTER))) - 2)
  91. struct tostruct {
  92. u_long selfpc;
  93. long count;
  94. u_short link;
  95. u_short pad;
  96. };
  97. /*
  98. * a raw arc, with pointers to the calling site and
  99. * the called site and a count.
  100. */
  101. struct rawarc {
  102. u_long raw_frompc;
  103. u_long raw_selfpc;
  104. long raw_count;
  105. };
  106. /*
  107. * general rounding functions.
  108. */
  109. #define ROUNDDOWN(x,y) (((x)/(y))*(y))
  110. #define ROUNDUP(x,y) ((((x)+(y)-1)/(y))*(y))
  111. /*
  112. * The profiling data structures are housed in this structure.
  113. */
  114. struct gmonparam {
  115. int state;
  116. u_short *kcount;
  117. u_long kcountsize;
  118. u_short *froms;
  119. u_long fromssize;
  120. struct tostruct *tos;
  121. u_long tossize;
  122. long tolimit;
  123. u_long lowpc;
  124. u_long highpc;
  125. u_long textsize;
  126. u_long hashfraction;
  127. };
  128. #ifdef _KERNEL
  129. extern int gmoninit; /* Is the kernel ready for beeing profiled? */
  130. #else
  131. extern struct gmonparam _gmonparam;
  132. #endif
  133. /*
  134. * Possible states of profiling.
  135. */
  136. #define GMON_PROF_ON 0
  137. #define GMON_PROF_BUSY 1
  138. #define GMON_PROF_ERROR 2
  139. #define GMON_PROF_OFF 3
  140. /*
  141. * Sysctl definitions for extracting profiling information from the kernel.
  142. */
  143. #define GPROF_STATE 0 /* int: profiling enabling variable */
  144. #define GPROF_COUNT 1 /* struct: profile tick count buffer */
  145. #define GPROF_FROMS 2 /* struct: from location hash bucket */
  146. #define GPROF_TOS 3 /* struct: destination/count structure */
  147. #define GPROF_GMONPARAM 4 /* struct: profiling parameters (see above) */
  148. #endif /* !_SYS_GMON_H_ */