PAPI_sprofil(3)
π PAPI_sprofil β PAPI manual page, bestie π
π NAME π
PAPI_sprofil β generate PC histogram data from multiple code regions where hardware counter overflow occurs. It's giving very specific profiler energy, and honestly? Slay. π
β¨ SYNOPSIS β¨
πΈ Detailed Description πΈ
π» C Interface π»
#include <papi.h>
int PAPI_sprofil( PAPI_sprofil_t * prof, int profcnt, int EventSet,
int EventCode, int threshold, int flags );
π«Ά Parameters π«Ά
Okay so here's the whole parameter group chat, and every single one is important:
*profβ pointer to an array ofPAPI_sprofil_tstructures. Each copy of the structure contains the following:bufβ pointer to a buffer ofbufsizbytes in which the histogram counts are stored in an array ofunsigned short,unsigned int, orunsigned long longvalues, or 'buckets'. The size of the buckets is determined by values in theflagsargument.bufsizβ the size of the histogram buffer in bytes. It is computed from the length of the code region to be profiled, the size of the buckets, and the scale factor as discussed below.offsetβ the start address of the region to be profiled.scaleβ broadly and historically speaking, a contraction factor that indicates how much smaller the histogram buffer is than the region to be 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.
profcntβ number of structures in theprofarray for hardware profiling.EventSetβ the PAPI EventSet to profile. This EventSet is marked as profiling-ready, but profiling doesn't actually start until aPAPI_start()call is issued.EventCodeβ code of the Event in the EventSet to profile. This event must already be a member of the EventSet.thresholdβ minimum number of events that must occur before the PC is sampled. If hardware overflow is supported for your component, this threshold will trigger an interrupt when reached. Otherwise, the counters will be sampled periodically and the PC will be recorded for the first sample that exceeds the threshold.
π¨ And bestie, if the value ofthresholdis0, profiling will literally be disabled for this event. Periodt.
flagsβ bit pattern to control profiling behavior. Defined values are given in a table in the documentation forPAPI_pofil. No cap.
π Return values π
Return values for PAPI_sprofil() are identical to those for PAPI_profil. Please refer to that page for further details. π
Now the main character prose: PAPI_sprofil() is a structure driven profiler that profiles one or more disjoint regions of code in a single call. It accepts a pointer to a preinitialized array of sprofil structures, and initiates profiling based on the values contained in the array. Each structure in the array defines the profiling parameters that are normally passed to PAPI_profil(). For more information on profiling, PAPI_profil.
The way that PAPI_sprofil() handles multiple disjoint code regions in one call is highkey iconic. Lowkey obsessed. Fr fr.
π Example π
Okay, example time β keep every field and line exactly as shown, because that's where the details live:
int retval;
unsigned long length;
PAPI_exe_info_t *prginfo;
unsigned short *profbuf1, *profbuf2, profbucket;
PAPI_sprofil_t sprof[3];
prginfo = PAPI_get_executable_info();
if (prginfo == NULL) handle_error( NULL );
length = (unsigned long)(prginfo->text_end - prginfo->text_start);
// Allocate 2 buffers of equal length
profbuf1 = (unsigned short *)malloc(length);
profbuf2 = (unsigned short *)malloc(length);
if ((profbuf1 == NULL) || (profbuf2 == NULL))
handle_error( NULL );
memset(profbuf1,0x00,length);
memset(profbuf2,0x00,length);
// First buffer
sprof[0].pr_base = profbuf1;
sprof[0].pr_size = length;
sprof[0].pr_off = (vptr_t) DO_FLOPS;
sprof[0].pr_scale = 0x10000;
// Second buffer
sprof[1].pr_base = profbuf2;
sprof[1].pr_size = length;
sprof[1].pr_off = (vptr_t) DO_READS;
sprof[1].pr_scale = 0x10000;
// Overflow bucket
sprof[2].pr_base = profbucket;
sprof[2].pr_size = 1;
sprof[2].pr_off = 0;
sprof[2].pr_scale = 0x0002;
retval = PAPI_sprofil(sprof, EventSet, PAPI_FP_INS, 1000000,
PAPI_PROFIL_POSIX | PAPI_PROFIL_BUCKET_16)) != PAPI_OK)
if ( retval != PAPI_OK ) handle_error( retval );
π¦ See also π¦
PAPI_overflowPAPI_get_executable_infoPAPI_profil
iykyk. π
π Author π
Generated automatically by Doxygen for PAPI from the source code.
π That's a wrap, bestie! This iconic little manual page is from PAPI version 7.2.0.0, dated Wed Jun 25 2025 19:30:49. Go profile something fabulous. π
β¨
π¦ 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