1
0

gmon.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /*-
  17. * Copyright (c) 1982, 1986, 1992, 1993
  18. * The Regents of the University of California. All rights reserved.
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. * 1. Redistributions of source code must retain the above copyright
  24. * notice, this list of conditions and the following disclaimer.
  25. * 2. Redistributions in binary form must reproduce the above copyright
  26. * notice, this list of conditions and the following disclaimer in the
  27. * documentation and/or other materials provided with the distribution.
  28. * 4. Neither the name of the University nor the names of its contributors
  29. * may be used to endorse or promote products derived from this software
  30. * without specific prior written permission.
  31. *
  32. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  33. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  34. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  35. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  36. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  37. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  38. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  40. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  41. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  42. * SUCH DAMAGE.
  43. *
  44. * @(#)gmon.h 8.2 (Berkeley) 1/4/94
  45. */
  46. #ifndef _SYS_GMON_H
  47. #define _SYS_GMON_H 1
  48. #include <features.h>
  49. #include <sys/types.h>
  50. /*
  51. * See gmon_out.h for gmon.out format.
  52. */
  53. /* structure emitted by "gcc -a". This must match struct bb in
  54. gcc/libgcc2.c. It is OK for gcc to declare a longer structure as
  55. long as the members below are present. */
  56. struct __bb
  57. {
  58. long zero_word;
  59. const char *filename;
  60. long *counts;
  61. long ncounts;
  62. struct __bb *next;
  63. const unsigned long *addresses;
  64. };
  65. extern struct __bb *__bb_head;
  66. /*
  67. * histogram counters are unsigned shorts (according to the kernel).
  68. */
  69. #define HISTCOUNTER unsigned short
  70. /*
  71. * fraction of text space to allocate for histogram counters here, 1/2
  72. */
  73. #define HISTFRACTION 2
  74. /*
  75. * Fraction of text space to allocate for from hash buckets.
  76. * The value of HASHFRACTION is based on the minimum number of bytes
  77. * of separation between two subroutine call points in the object code.
  78. * Given MIN_SUBR_SEPARATION bytes of separation the value of
  79. * HASHFRACTION is calculated as:
  80. *
  81. * HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1);
  82. *
  83. * For example, on the VAX, the shortest two call sequence is:
  84. *
  85. * calls $0,(r0)
  86. * calls $0,(r0)
  87. *
  88. * which is separated by only three bytes, thus HASHFRACTION is
  89. * calculated as:
  90. *
  91. * HASHFRACTION = 3 / (2 * 2 - 1) = 1
  92. *
  93. * Note that the division above rounds down, thus if MIN_SUBR_FRACTION
  94. * is less than three, this algorithm will not work!
  95. *
  96. * In practice, however, call instructions are rarely at a minimal
  97. * distance. Hence, we will define HASHFRACTION to be 2 across all
  98. * architectures. This saves a reasonable amount of space for
  99. * profiling data structures without (in practice) sacrificing
  100. * any granularity.
  101. */
  102. #define HASHFRACTION 2
  103. /*
  104. * Percent of text space to allocate for tostructs.
  105. * This is a heuristic; we will fail with a warning when profiling programs
  106. * with a very large number of very small functions, but that's
  107. * normally OK.
  108. * 2 is probably still a good value for normal programs.
  109. * Profiling a test case with 64000 small functions will work if
  110. * you raise this value to 3 and link statically (which bloats the
  111. * text size, thus raising the number of arcs expected by the heuristic).
  112. */
  113. #define ARCDENSITY 3
  114. /*
  115. * Always allocate at least this many tostructs. This
  116. * hides the inadequacy of the ARCDENSITY heuristic, at least
  117. * for small programs.
  118. *
  119. * Value can be overridden at runtime by glibc.gmon.minarcs tunable.
  120. */
  121. #define MINARCS 50
  122. /*
  123. * The type used to represent indices into gmonparam.tos[].
  124. */
  125. #define ARCINDEX unsigned long
  126. /*
  127. * Maximum number of arcs we want to allow.
  128. * Used to be max representable value of ARCINDEX minus 2, but now
  129. * that ARCINDEX is a long, that's too large; we don't really want
  130. * to allow a 48 gigabyte table.
  131. *
  132. * Value can be overridden at runtime by glibc.gmon.maxarcs tunable.
  133. */
  134. #define MAXARCS (1 << 20)
  135. struct tostruct {
  136. unsigned long selfpc;
  137. long count;
  138. ARCINDEX link;
  139. };
  140. /*
  141. * a raw arc, with pointers to the calling site and
  142. * the called site and a count.
  143. */
  144. struct rawarc {
  145. unsigned long raw_frompc;
  146. unsigned long raw_selfpc;
  147. long raw_count;
  148. };
  149. /*
  150. * general rounding functions.
  151. */
  152. #define ROUNDDOWN(x,y) (((x)/(y))*(y))
  153. #define ROUNDUP(x,y) ((((x)+(y)-1)/(y))*(y))
  154. /*
  155. * The profiling data structures are housed in this structure.
  156. */
  157. struct gmonparam {
  158. long int state;
  159. unsigned short *kcount;
  160. unsigned long kcountsize;
  161. ARCINDEX *froms;
  162. unsigned long fromssize;
  163. struct tostruct *tos;
  164. unsigned long tossize;
  165. long tolimit;
  166. unsigned long lowpc;
  167. unsigned long highpc;
  168. unsigned long textsize;
  169. unsigned long hashfraction;
  170. long log_hashfraction;
  171. };
  172. /*
  173. * Possible states of profiling.
  174. */
  175. #define GMON_PROF_ON 0
  176. #define GMON_PROF_BUSY 1
  177. #define GMON_PROF_ERROR 2
  178. #define GMON_PROF_OFF 3
  179. /*
  180. * Sysctl definitions for extracting profiling information from the kernel.
  181. */
  182. #define GPROF_STATE 0 /* int: profiling enabling variable */
  183. #define GPROF_COUNT 1 /* struct: profile tick count buffer */
  184. #define GPROF_FROMS 2 /* struct: from location hash bucket */
  185. #define GPROF_TOS 3 /* struct: destination/count structure */
  186. #define GPROF_GMONPARAM 4 /* struct: profiling parameters (see above) */
  187. __BEGIN_DECLS
  188. /* Set up data structures and start profiling. */
  189. extern void __monstartup (unsigned long __lowpc, unsigned long __highpc) __THROW;
  190. extern void monstartup (unsigned long __lowpc, unsigned long __highpc) __THROW;
  191. /* Clean up profiling and write out gmon.out. */
  192. extern void _mcleanup (void) __THROW;
  193. __END_DECLS
  194. #endif /* sys/gmon.h */