PROFIL(2)
π PROFIL(2) π β bestie edition, aka profil system call
okay so picture this: you're on a Debian system, it's December 1, 2017, and you wanna know what your program is actually doing with its life. enter profil(2), the system call manual page. it's giving main character energy for your program counter. let's go π«Ά
β¨ NAME β¨
profil β control process profiling π
π LIBRARY π
Standard C Library (libc, -lc) β yeah, it's in the regular libc, no special girlies needed π
πΈ SYNOPSIS πΈ
#include <unistd.h>
int
profil(char *samples, size_t size, vm_offset_t offset, int scale);
π¦ DESCRIPTION π¦
The profil() system call turns program counter profiling of the current process on or off. no cap. when profiling is on, every single profiling clock tick, the kernel goes and bumps an appropriate count in the samples buffer. and the frequency of that profiling clock? it's recorded in the header in the profiling output file. iykyk β¨
So the buffer samples contains size bytes and is split into a bunch of 16-bit bins. each bin is literally counting how many times the program counter was hanging out in a particular address range in the process when a profiling clock tick happened while profiling was enabled. like a little attendance sheet for addresses π
For a given program counter address, the number of the corresponding bin is given by this iconic relation:
[(pc - offset) / 2] * scale / 65536
The offset argument is the lowest address at which the kernel takes program counter samples. and the scale argument ranges from 1 to 65536, and you use it to change the span of the bins. so:
- a scale of
65536maps each bin to 2 bytes of address range - a scale of
32768gives 4 bytes 16384gives 8 bytes- and so on, you get the vibe π«
intermediate values give you approximate intermediate ranges. and a scale value of 0? that disables profiling. periodt.
π₯ RETURN VALUES π₯
The profil() function returns the value 0 if successful π otherwise the value -1 is returned and the global variable errno is set to indicate the error. sad girl hours π
π FILES π
/usr/lib/gcrt0.oβ profiling C run-time startup file βgmon.outβ conventional name for profiling output file π
π ERRORS π
The following error may be reported:
[EFAULT]β the buffersamplescontains an invalid address. not it. π
π SEE ALSO π
gprof(1)β go read that one too bestie, they're a package deal π«Ά
π§ HISTORY π§
The profil() function appeared in Version 6 AT&T UNIX. like, ancient. vintage. iconic. truly a legacy queen π
π BUGS π
ngl these are real, so listen up:
- This routine should be named
profile(). the missinge? a crime. we've been carrying it for decades π - The
samplesargument should really be a vector of typeunsigned short. yes really. - The format of the
gmon.outfile is undocumented. so likeβ¦ good luck figuring it out yourself, bestie π
okay that's the whole page!! go profile something and slay β¨ this has been the PROFIL(2) System Calls Manual, from Debian, dated December 1, 2017 β mwah, take care of her, she's been around since Version 6 AT&T UNIX and she's still serving πΈππ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms