MONCONTROL(3)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

✨ NAME ✨

okay so this is MONCONTROL(3) from the Library Functions Manual, bestie β€” the page for moncontrol, monstartup, aka the little duo that lets you control execution profile πŸ’…βœ¨

πŸ“š LIBRARY πŸ“š

It's chilling in the Standard C Library (libc, link it with -lc), no cap 🫢

🧾 SYNOPSIS 🧾

#include <sys/types.h>
#include <sys/gmon.h>

void
moncontrol(int mode);

void
monstartup(u_long lowpc, u_long highpc);

πŸ’– DESCRIPTION πŸ’–

So here's the vibe: if you compile an executable with the -pg option to cc(1), it automatically gets calls baked in that collect statistics for the gprof(1) call-graph execution profiler. Iconic. In typical operation, profiling starts at program startup and ends when the program calls exit. When the program exits, the profiling data get written to the file progname.gmon, where progname is the name of the program, and then you can use gprof(1) to examine the results. Slay πŸ’…

The moncontrol() function selectively controls profiling inside 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 is literally there so you can measure the cost of particular operations. Note β€” and this is important β€” an output file will be produced on program exit regardless of the state of moncontrol(). So don't think stopping it means no file, bestie 😭

Programs that are not loaded with -pg may still 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(). That's the whole vibe check πŸ¦‹

🌱 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. iykyk πŸ’…

πŸ“ FILES πŸ“

  • progname.gmon β€” execution data file ⭐

πŸ‘€ SEE ALSO πŸ‘€

cc(1), gprof(1), profil(2), clocks(7) β€” go read these too, bestie πŸ’–


catch u later, bestie β€” this page is from Debian, dated June 14, 2004, and it's giving MONCONTROL(3) main character energy πŸŒˆπŸ‘‘

πŸ“¦ where this page comes from
  • freebsd 15.1: base 15.1
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms