PMATOMSTR(3)

πŸ“¦
version 7.2.2 Β· 4 versions
, in arch rolling, centos-stream 10, fedora 43, fedora 44, ubuntu resolute, ubuntu stonking

πŸ’– PMATOMSTR πŸ’– β€” it's a 3 page, library functions manual, bestie

okay so welcome to the PMATOMSTR glow-up ✨ this is pmAtomStr, pmAtomStr_r β€” literally the duo that takes a performance metric value and turns it into a string. diagnostic vibes, report vibes, all of it πŸŽ€


✨ NAME ✨

pmAtomStr, pmAtomStr_r β€” convert a performance metric value into a string πŸ¦‹


✨ C SYNOPSIS ✨

#include <pcp/pmapi.h>

const char *pmAtomStr(const pmAtomValue *avp, int type);
char *pmAtomStr_r(const pmAtomValue *avp, int type, char *buf,
                  int buflen);

cc ... -lpcp

✨ DESCRIPTION ✨

so like. every performance metric value can be encoded in a pmAtomValue union, and it is defined like this, no notes:

typedef union {
    __int32_t    l;     /* 32-bit signed */
    __uint32_t   ul;    /* 32-bit unsigned */
    __int64_t    ll;    /* 64-bit signed */
    __uint64_t   ull;   /* 64-bit unsigned */
    float        f;     /* 32-bit floating point */
    double       d;     /* 64-bit floating point */
    char         *cp;   /* char ptr */
    pmValueBlock *vbp;  /* pmValueBlock ptr */
} pmAtomValue;

so you hand over the performance metric value that avp is pointing at, plus a performance metric type defined by type, and pmAtomStr will generate the corresponding metric value as a string β€” perfect for diagnostic or report output, it's giving very put-together πŸ’…

pmAtomStr_r does the exact same thing but stores the result in a user-supplied buffer buf of length buflen, and that buffer should have room for at least 80 bytes. yes bestie, at least 80, don't skimp πŸ™ˆ

the value for type is typically extracted from a pmDesc structure, following a call to pmLookupDesc(3) for a particular performance metric. that's the move πŸ‘‘

some type-specific tea, listen up:

  • if the type is PM_TYPE_STRING, values longer than 38 characters will be truncated after 34 characters, and that truncation is shown with ellipsis ... at the end of the value. so it's not a glitch, it's on purpose 🫢
  • if the type is PM_TYPE_AGGREGATE, then up to the first three 32-bit words are displayed as hexadecimal values πŸ”₯
  • if the type is PM_TYPE_EVENT, then a summary of the number of event records found in the value is generated πŸ“Š

and here's the catch, bestie: the return value from pmAtomStr is held in a single static buffer, so the returned value is only valid until the next call to pmAtomStr. it's giving one-shot, use-it-or-lose-it energy πŸ’€


✨ NOTES ✨

pmAtomStr returns a pointer to a static buffer and hence is not thread-safe. multi-threaded applications should use pmAtomStr_r instead. periodt. 🚨

✨ SEE ALSO ✨

PMAPI(3), pmConvScale(3), pmExtractValue(3), pmLookupDesc(3), pmPrintValue(3), pmTypeStr(3) and pmUnitsStr(3) 🌈


okay and that's the whole page, my love 🌸 this came from Performance Co-Pilot (that's the PCP girlies, you know the ones), page PMATOMSTR(3). go read a metric and slay πŸ’œπŸ‘‘

πŸ“¦ where this page comes from