PAPI_profil(3)
π NAME π
PAPI_profil β bestie, this one generates a histogram of hardware counter overflows vs. PC addresses. That's the whole vibe. β¨
Oh and hey, this is from the PAPI manual section 3 β welcome to the PAPI_profil(3) page, grab a snack. π
β¨ SYNOPSIS β¨
Detailed Description
C Interface π«Ά
#include <papi.h>
int PAPI_profil(void *buf, unsigned bufsiz, unsigned long offset,
unsigned scale, int EventSet, int EventCode, int threshold, int
flags );
Fortran Interface
ngl the profiling routines have no Fortran interface. That's it, that's the whole section. π
Parameters
*bufβ pointer to a buffer ofbufsizbytes where the histogram counts live, stored as an array ofunsigned short,unsigned int, orunsigned long longvalues, aka 'buckets'. The size of the buckets is decided by the values in theflagsargument. πbufsizβ the size of the histogram buffer in bytes. It's computed from the length of the code region you're profiling, the size of the buckets, and the scale factor, as discussed further down.offsetβ the start address of the region to be profiled.scaleβ broadly and historically speaking, a contraction factor that shows how much smaller the histogram buffer is than the region being profiled. More precisely,scaleis interpreted as an unsigned 16-bit fixed-point fraction with the decimal point implied on the left. Its value is the reciprocal of the number of addresses in a subdivision, per counter of histogram buffer. Below there's a whole table of representative values forscale. πEventSetβ the PAPI EventSet to profile. This EventSet gets marked as profiling-ready, but profiling doesn't actually start until aPAPI_start()call is issued. Like, it's ready, it's just not going yet, yk?EventCodeβ code of the Event in the EventSet to profile. This event has to already be a member of the EventSet. No gatecrashing. π«thresholdβ minimum number of events that must occur before the PC is sampled. If hardware overflow is supported for your component, this threshold triggers an interrupt when it's reached. Otherwise, the counters get sampled periodically and the PC is recorded for the first sample that exceeds the threshold. Ifthresholdis0, profiling is disabled for this event. β¨flagsβ bit pattern controlling profiling behavior. Defined values are shown in the table further down.
Return values
PAPI_OKβ iconic, everything worked. πPAPI_EINVALβ one or more of the arguments is invalid.PAPI_ENOMEMβ insufficient memory to complete the operation.PAPI_ENOEVSTβ the EventSet specified does not exist.PAPI_EISRUNβ the EventSet is currently counting events.PAPI_ECNFLCTβ the underlying counter hardware can not count this event and other events in the EventSet simultaneously.PAPI_ENOEVNTβ the PAPI preset is not available on the underlying hardware. π
πΈ DESCRIPTION πΈ
PAPI_profil() provides hardware event statistics by profiling the occurrence of specified hardware counter events. It's designed to mimic the UNIX SVR4 profil call β yes, it's giving vintage, but make it PAPI. π
The statistics are generated by creating a histogram of hardware counter event overflows vs. program counter addresses for the current process. The histogram is defined for a specific region of program code to be profiled, and that identified region is logically broken up into a set of equal size subdivisions, each of which corresponds to a count in the histogram. Cute, right? It's a little grid of code. π
With each hardware event overflow, the current subdivision is identified and its corresponding histogram count is incremented. These counts establish a relative measure of how many hardware counter events are occurring in each code subdivision. Slay. π₯
The resulting histogram counts for a profiled region can be used to identify those program addresses that generate a disproportionately high percentage of the event of interest β i.e. the main character addresses. π
Events to be profiled are specified with the EventSet and EventCode parameters. More than one event can be simultaneously profiled by calling PAPI_profil() several times with different EventCode values. Profiling can be turned off for a given event by calling PAPI_profil() with a threshold value of 0.
Representative values for the scale variable π
0x20000/ 131072 β Maps precisely one instruction address to a unique bucket inbuf.0x10000/ 65536 β Maps precisely two instruction addresses to a unique bucket inbuf.0x0FFFF/ 65535 β Maps approximately two instruction addresses to a unique bucket inbuf.0x08000/ 32768 β Maps every four instruction addresses to a bucket inbuf.0x04000/ 16384 β Maps every eight instruction addresses to a bucket inbuf.0x00002/ 2 β Maps all instruction addresses to the same bucket inbuf.0x00001/ 1 β Undefined.0x00000/ 0 β Undefined.
(Heads up: the original table's column header is spelled DEFININTION β iconic typo, we stan, but the meanings above are exactly what it lists.)
Historically, the scale factor was introduced to allow the allocation of buffers smaller than the code size to be profiled. Data and instruction sizes were assumed to be multiples of 16-bits. These assumptions are no longer necessarily true. PAPI_profil() has preserved the traditional definition of scale where appropriate, but deprecated the definitions for 0 and 1 (disable scaling) and extended the range of scale to include 65536 and 131072 to allow for exactly two addresses and exactly one address per profiling bucket. π
The value of bufsiz is computed as follows:
bufsiz = (end - start)*(bucket_size/2)*(scale/65536)
where
bufsizβ the size of the buffer in bytesend,startβ the ending and starting addresses of the profiled regionbucket_sizeβ the size of each bucket in bytes;2,4, or8as defined inflags
Defined bits for the flags variable π¦
PAPI_PROFIL_POSIXβ default type of profiling, similar toprofil (3).PAPI_PROFIL_RANDOMβ drop a random 25% of the samples. rip to those samples, they were brave π«‘PAPI_PROFIL_WEIGHTEDβ weight the samples by their value.PAPI_PROFIL_COMPRESSβ ignore samples as values in the hash buckets get big.PAPI_PROFIL_BUCKET_16β useunsigned short(16 bit) buckets. This is the default bucket.PAPI_PROFIL_BUCKET_32β useunsigned int(32 bit) buckets.PAPI_PROFIL_BUCKET_64β useunsigned long long(64 bit) buckets.PAPI_PROFIL_FORCE_SWβ force software overflow in profiling.
π§ EXAMPLE π§
int retval;
unsigned long length;
PAPI_exe_info_t *prginfo;
unsigned short *profbuf;
if ((prginfo = PAPI_get_executable_info()) == NULL)
handle_error(1);
length = (unsigned long)(prginfo->text_end - prginfo->text_start);
profbuf = (unsigned short *)malloc(length);
if (profbuf == NULL)
handle_error(1);
memset(profbuf,0x00,length);
if ((retval = PAPI_profil(profbuf, length, start, 65536, EventSet,
PAPI_FP_INS, 1000000, PAPI_PROFIL_POSIX | PAPI_PROFIL_BUCKET_16))
!= PAPI_OK)
handle_error(retval);
π SEE ALSO π
PAPI_overflowPAPI_sprofil
iykyk, go read those next bestie π
π AUTHOR π
Generated automatically by Doxygen for PAPI from the source code. (Not a human, just a robot doing its little robot thing. Respect.) π€
aaaand that's the page! π
This was PAPI_profil(3) from PAPI Version 7.2.0.0, dated Wed Jun 25 2025 19:30:48 β mwah, go profile something gorgeous π«Άβ¨πΈ
π¦ where this page comes from
- nixos 26.05: papi 7.2.0
- nixpkgs unstable: papi 7.2.0
- opensuse-leap 16.0: papi-devel 7.2.0-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: papi-devel 7.2.0-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: papi-devel 7.2.0-160000.2.2 Β· BSD-3-Clause
- ubuntu resolute: libpapi-dev 7.2.0-2 Β· BSD-3-Clause
- ubuntu stonking: libpapi-dev 7.2.0-2 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms