PMLOOKUPDESC(3)

✨ NAME ✨

pmLookupDesc, pmLookupDescs β€” okay bestie, these two are literally the obtain descriptions for performance metrics girlies πŸ’– they pull the full backstory on a metric so you know what you're actually looking at 🫢

This one lives in the Library Functions Manual section (that's the 3 in PMLOOKUPDESC(3), iykyk) πŸ’…


🌸 C SYNOPSIS 🌸

#include <pcp/pmapi.h>

int pmLookupDesc(pmID pmid, pmDesc *desc);
int pmLookupDescs(int numpmid, pmID *pmids, pmDesc *descs);

cc ... -lpcp

πŸ’… DESCRIPTION πŸ’…

So like, you hand it a Performance Metrics Identifier (that's a PMID for short ✨) as pmid, and pmLookupDesc fills in the pmDesc structure you pointed at with desc β€” and where does it get it from? The current Performance Metrics Application Programming Interface (PMAPI) context. That's the vibe 🌈

Now the pmLookupDescs variant does the exact same thing but for numpmid metrics all at once, with the pmids array carrying the metric identifiers you wanna look up. And listen β€” it's more efficient as the number of metrics increases, because it dodges all that round trip latency from making a million individual requests. Slay πŸŽ€

Heads up bestie: the error protocol guarantees a 1:1 relationship between the elements of descs and pmids, so both lists contain exactly numpmid elements. Which means you are expected to have preallocated a suitably sized array for descs. No cap, that part is on you πŸ™ˆ

The pmDesc structure is giving everything you need to describe and manipulate a performance metric via the PMAPI, and here's its declaration:

/* Performance Metric Descriptor */
typedef struct {
    pmID    pmid;   /* unique identifier */
    int     type;   /* base data type (see below) */
    pmInDom indom;  /* instance domain */
    int     sem;    /* semantics of value (see below) *
    pmUnits units;  /* dimension and units (see below) */
} pmDesc;

/* pmDesc.type -- data type of metric values */
#define PM_TYPE_NOSUPPORT        -1    /* not impl. in this version */
#define PM_TYPE_32               0    /* 32-bit signed integer */
#define PM_TYPE_U32              1    /* 32-bit unsigned integer */
#define PM_TYPE_64               2    /* 64-bit signed integer */
#define PM_TYPE_U64              3    /* 64-bit unsigned integer */
#define PM_TYPE_FLOAT            4    /* 32-bit floating point */
#define PM_TYPE_DOUBLE           5    /* 64-bit floating point */
#define PM_TYPE_STRING           6    /* array of char */
#define PM_TYPE_AGGREGATE        7    /* arbitrary binary data */
#define PM_TYPE_AGGREGATE_STATIC 8    /* static pointer to aggregate */
#define PM_TYPE_EVENT            9    /* packed pmEventArray */
#define PM_TYPE_UNKNOWN          255  /* used in pmValueBlock, not pmDesc */

/* pmDesc.sem -- semantics/interpretation of metric values */
#define PM_SEM_COUNTER  1  /* cumulative ctr (monotonic incr) */
#define PM_SEM_INSTANT  3  /* instant. value continuous domain */
#define PM_SEM_DISCRETE 4  /* instant. value discrete domain */

(not me noticing the sem comment is missing its closing */ in the source β€” iconic behavior honestly, we respect it πŸ’€ the code is copied exactly as it lives, so don't come for me)

The type field in the pmDesc describes all the various encodings (or formats, same thing) for a metric's value πŸ¦‹

If a value is counted in the underlying base instrumentation with less than 32 bits of integer precision, it is the responsibility of the Performance Metrics Domain Agent (PMDA) to promote the value to a 32-bit integer before it gets exported into the Performance Metrics Collection Subsystem (PMCS). Translation bestie: applications above the PMAPI never ever have to deal with 8-bit and 16-bit counters. We are protected 🫢

And if the value of a performance metric is of type PM_TYPE_AGGREGATE, PM_TYPE_AGGREGATE_STATIC, PM_TYPE_EVENT or PM_TYPE_STRING, then the interpretation of that value is unknown to the PMCS. In those cases the application using the value and the PMDA providing the value have to have some common understanding about how the value is structured and interpreted. Like, y'all need to have talked about it first 🀝


πŸŽ€ the dimensionality + scale situation πŸŽ€

Each value for a performance metric is assumed to be drawn from a set of values that can be described in terms of their dimensionality and scale by a compact encoding, like this: the dimensionality is defined by a power, or index, in each of 3 orthogonal dimensions β€” namely Space, Time and Count (or Events, which are dimensionless ✨). And there's also additional extra units available, described below.

For example, I/O throughput might be represented as

             -1
Space.Time

while the running total of system calls is Count, memory allocation is Space and average service time is

             -1
Time.Count

In each dimension there are a number of common scale values that may be used to better encode ranges that might otherwise exhaust the precision of a 32-bit value πŸ”₯ That information is encoded in the pmUnits structure, which is embedded in the pmDesc structure. Obsessed with the layering honestly:

/*
 * Encoding for the units (dimensions Time and Space) and scale
 * for Performance Metric Values
 *
 * For example, a pmUnits struct of
 *      { 1, -1, 0, PM_SPACE_MBYTE, PM_TIME_SEC, 0, 0, 0 }
 * represents Mbytes/sec, while
 *      { 0, 1, -1, 0, PM_TIME_HOUR, 6, 0, 0 }
 * represents hours/million-events, and
 *      { 0, 0, 0, 0, 0, 0, PM_UNIT_VOLTAGE, PM_VOLTAGE_mV }
 * represents voltage in units of mV
 */
typedef struct {
    int dimSpace:4;             /* space dimension */
    int dimTime:4;              /* time dimension */
    int dimCount:4;             /* event dimension */
    unsigned int scaleSpace:4;  /* one of PM_SPACE_* below */
    unsigned int scaleTime:4;   /* one of PM_TIME_* below */
    int scaleCount:4;           /* one of PM_COUNT_* below */
    int extraUnit:5;            /* code for extra unit from PM_UNIT_* below */
    int extraScale:3;           /* scale for extra unit */
} pmUnits;                      /* dimensional units and scale of value */

/* pmUnits.scaleSpace */
#define PM_SPACE_BYTE   0       /* bytes */
#define PM_SPACE_KBYTE  1       /* Kilobytes (1024) */
#define PM_SPACE_MBYTE  2       /* Megabytes (1024^2) */
#define PM_SPACE_GBYTE  3       /* Gigabytes (1024^3) */
#define PM_SPACE_TBYTE  4       /* Terabytes (1024^4) */
#define PM_SPACE_PBYTE   5    /* pebibytes (1024^5) */
#define PM_SPACE_EBYTE   6    /* exbibytes (1024^6) */
#define PM_SPACE_ZBYTE   7    /* zebibytes (1024^7) */
#define PM_SPACE_YBYTE   8    /* yobibytes (1024^8) */
/* pmUnits.scaleTime */
#define PM_TIME_NSEC    0       /* nanoseconds */
#define PM_TIME_USEC    1       /* microseconds */
#define PM_TIME_MSEC    2       /* milliseconds */
#define PM_TIME_SEC     3       /* seconds */
#define PM_TIME_MIN     4       /* minutes */
#define PM_TIME_HOUR    5       /* hours */
/*
 * pmUnits.scaleCount (e.g. count events, syscalls, interrupts,
 * etc.) these are simply powers of 10, and not enumerated here,
 * e.g. 6 for 10^6, or -3 for 10^-3
 */
#define PM_COUNT_ONE    0       /* 1 */
/*
 * the extra unit types are mutually exclusive so at most one one of
 * the following extraUnit values may be used for each metric
 */
#define PM_UNIT_TEMPERATURE    1
#define PM_UNIT_VOLTAGE        2
#define PM_UNIT_CURRENT        3
#define PM_UNIT_POWER          4
/*
 * scale factors for extra units ... must be > 0 and <= 7 and
 * unique for each extra unit type
 */
#define PM_TEMPERATURE_C        1       /* celsius */
#define PM_TEMPERATURE_F        2       /* fahrenheit */
#define PM_TEMPERATURE_K        3       /* kelvin */
#define PM_VOLTAGE_V            1       /* Volt */
#define PM_VOLTAGE_mV           2       /* milli Volt */
#define PM_VOLTAGE_uV           3       /* micro Volt */
#define PM_CURRENT_A            1       /* Ampere */
#define PM_CURRENT_mA           2       /* milli Ampere */
#define PM_CURRENT_uA           3       /* micro Ampere */
#define PM_POWER_kW             1       /* kilo Watt */
#define PM_POWER_W              2       /* Watt */
#define PM_POWER_mW             3       /* milli Watt */
#define PM_POWER_uW             4       /* micro Watt */

Special routines β€” think pmExtractValue(3), pmConvScale(3) β€” are provided to manipulate values in conjunction with the pmUnits structure that defines the dimension and scale of the values for a particular performance metric. So cute, so useful 🌸

And below the PMAPI? The information required to complete the pmDesc structure is fetched from the PMDAs, and this is how the format and scale of performance metrics may change dynamically as the PMDAs and their underlying instrumentation evolve with time. So when some metrics suddenly become 64-bits long, or change their units from Mbytes to Gbytes, well-written applications using the services provided by the PMAPI will continue to function correctly. Character development fr fr πŸ‘‘


🩺 DIAGNOSTICS 🩺

These routines return a negative error code to indicate failure 😭

  • PM_ERR_PMID β€” the requested PMID is not known to the PMCS
  • PM_ERR_NOAGENT β€” the PMDA responsible for providing the metric is currently not available

pmLookupDesc returns zero to indicate success ✨

The result from pmLookupDescs depends on the presence of any lookup failures, their severity and the number of metrics being looked up. Sit with that for a sec, here's the whole map:

  1. If there are no lookup failures, the return value will be numpmid.
  2. If a fatal error is encountered, the return value will be less than 0. For example PM_ERR_IPC.
  3. If numpmid is greater than one and non-fatal error(s) are encountered, the return value is the number of metric descriptors that have successfully been looked up (greater than or equal to zero and less than or equal to numpmid).
  4. If numpmid is one and a non-fatal error is encountered, the return value is the error code (less than zero).

When errors are encountered, any metrics that cannot be looked up result in the corresponding descriptor element of descs having its pmid field set to PM_ID_NULL. The slightly convoluted error protocol allows bulk lookups, then probing for more error details in the case of a specific failure. It's giving "look at everything, then zoom in when something's off" πŸ”πŸ’–


πŸ‘€ SEE ALSO πŸ‘€

PMAPI(3), pmAtomStr(3), pmConvScale(3), pmExtractValue(3), pmGetConfig(3), pmTypeStr(3), pmUnitsStr(3), pcp.conf(5) and pcp.env(5) 🌈


k bye bestie, go look up some descriptors πŸ’…βœ¨ This little love letter came to you from Performance Co-Pilot (PCP), and it's the PMLOOKUPDESC(3) page β€” no dates were harmed in the making of this rewrite πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from