monstartup(3)

monstartup3

Control execution profile

Part of moncontrol(3).

Usage

#include <sys/types.h>

#include <sys/gmon.h>

void

moncontrol(int mode);

void

monstartup(u_long lowpc, u_long highpc);

Library

Standard C Library (libc, -lc)

Overview

An executable program compiled using the -pg option to cc(1) automatically includes calls to collect statistics for the gprof(1) call-graph execution profiler. In typical operation, profiling begins at program startup and ends when the program calls exit. When the program exits, the profiling data are written to the file progname.gmon, where progname is the name of the program, then gprof(1) can be used to examine the results.

The moncontrol() function selectively controls profiling within a program. When the program starts, profiling begins. To stop the collection of histogram ticks and call counts use moncontrol(0); to resume the collection of histogram ticks and call counts use moncontrol(1). This feature allows the cost of particular operations to be measured. Note that an output file will be produced on program exit regardless of the state of moncontrol().

Programs that are not loaded with -pg may selectively collect profiling statistics by calling monstartup() with the range of addresses to be profiled. The lowpc and highpc arguments specify the address range that is to be sampled; the lowest address sampled is that of lowpc and the highest is just below highpc. Only functions in that range that have been compiled with the -pg option to cc(1) will appear in the call graph part of the output; however, all functions in that address range will have their execution time measured. Profiling begins on return from monstartup().

Environment

The following environment variables affect the execution of moncontrol:

PROFIL_USE_PID

If set, the pid of the process is inserted into the filename.

Files

progname.gmon

execution data file

Releases

87 releases since FreeBSD 2.0.5-RELEASE; the text changed 46 times.

  1. 2.0.5
  2. 2.1.5–2.2.5
  3. 2.2.6–2.2.9
  4. 3.0–3.4
  5. 3.5–3.5.1
  6. 4.0
  7. 4.1–4.2
  8. 4.3
  9. 4.4
  10. 4.5–4.11
  11. 5.0
  12. 5.1–5.2.1
  13. 5.3–6.2
  14. 6.3
  15. 6.4
  16. 7.0
  17. 7.1
  18. 7.2
  19. 7.3
  20. 7.4
  21. 8.0
  22. 8.1
  23. 8.2
  24. 8.3
  25. 8.4
  26. 9.0
  27. 9.1
  28. 9.2
  29. 9.3
  30. 10.0
  31. 10.1
  32. 10.2
  33. 10.3
  34. 10.4
  35. 11.0
  36. 11.1
  37. 11.2
  38. 11.3
  39. 11.4
  40. 12.0
  41. 12.1
  42. 12.2
  43. 12.3
  44. 12.4
  45. 13.0–13.2
  46. 13.3–14.5
  47. 15.0–16.0

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.