PMEVENTFLAGSSTR(3)

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

πŸ’– PMEVENTFLAGSSTR(3) β€” the pmEventFlagsStr & pmEventFlagsStr_r glow-up πŸ’–

okay bestie, this is a page from the Library Functions Manual for PCP (Performance Co-Pilot), and it's literally so simple it's giving ✨main character✨. two lil functions, one job: turn a flags number into something a human can actually read. no cap. let's go 🫢


✨ NAME ✨

pmEventFlagsStr, pmEventFlagsStr_r β€” convert an event record flags value into a string πŸ’…


πŸŽ€ C SYNOPSIS πŸŽ€

#include <pcp/pmapi.h>

const char *pmEventFlagsStr(int flags);
char *pmEventFlagsStr_r(int flags, char *buf, int buflen);

cc ... -lpcp

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe. when you're throwing error and diagnostic messages and you've got a raw flags number just sitting there looking cryptic, pmEventFlagsStr swoops in and returns a human readable version of the value flags πŸ‘‘

and like β€” it's assuming that flags is the er_flags field of a pmEventRecord or a pmHighResEventRecord. iykyk. it's not guessing, it's assuming, and that assumption is the whole point πŸ“

then there's pmEventFlagsStr_r, which does literally the same thing but drops the result into your buffer instead of its own. that's the buf (user-supplied, you bring it) and buflen (its length). and bestie, make sure buf has room for at least 64 bytes. at least. 64. don't play with it πŸ™ˆ

⚠️ ok so important tea: the string that pmEventFlagsStr hands back lives in a single static buffer. that means the value it returns is only valid until the next call to pmEventFlagsStr. one call later and your pointer is pointing at somebody else's business πŸ’€ copy it if you need to keep it, fr fr.

🌸 NOTES 🌸

because pmEventFlagsStr returns a pointer to a static buffer, it is not thread-safe 😭 that's just how it is.

multi-threaded applications should use pmEventFlagsStr_r instead β€” it's the one with the user-supplied buffer, so every thread gets its own lil space and nobody's stepping on anybody πŸ’œ iconic behavior.


πŸ’… SEE ALSO πŸ’…

PMAPI(3) and pmdaEventAddRecord(3). go read those next, they're also slay ⭐


k bye bestie, that's the whole page πŸŽ€ stay safe out there with your static buffers, and remember: if you're multithreaded, use the _r version, periodt πŸ’–

✨ this has been a page from Performance Co-Pilot (PCP) β€” PMEVENTFLAGSSTR(3) ✨

πŸ“¦ where this page comes from