PMGETVERSION(3)

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

πŸ’– PMGETVERSION(3) πŸ’–

okay bestie, welcome to the Library Functions Manual corner of the PCP universe (that's Performance Co-Pilot, section 3, iykyk) ✨ this one's short and sweet and lowkey adorable.


🌸 NAME 🌸

pmGetVersion β€” fetch installed PCP version number


πŸŽ€ C SYNOPSIS πŸŽ€

#include <pcp/pmapi.h>

int pmGetVersion(void);

cc ... -lpcp

✨ DESCRIPTION ✨

so pmGetVersion hands you back a binary encoding of the PCP version number that's installed locally on your machine. that's it, that's the whole vibe πŸ’…

and the way you're supposed to use it is in combo with the related macros PM_VERSION(a,b,c) and PM_VERSION_CURRENT, which generate PCP version numbers in that exact same format. so they all speak the same language, no translation needed. there's an example down below, keep scrolling 🫢

now, the encoding itself? it's giving one byte per part of the version number of the installed PCP package β€” so that's the major number, the minor number, and the revision number, three bytes, one each. so PCP version 3.10.5 gets encoded as 0x30a05. iconic.

and if you want the version number as a string instead? that's also available from pmGetConfig with the argument PCP_VERSION. different flavor, same energy ✨

fun fact for the history girlies: pmGetVersion was introduced in PCP 3.10.5.


🌈 EXAMPLE 🌈

here's a C fragment that flexes both the compile-time macros and the run-time pmGetVersion function, for an app that should not be built for PCP versions older than 3.10.5 β€” but after that, there are two alternative implementations, with a newer (faster, sweeter, smaller) variant of the XYZ service that only becomes available in PCP 4.0.0. slay.

#include <pcp/pmapi.h>

#ifdef PM_VERSION_CURRENT
#if PM_VERSION_CURRENT < PM_VERSION(3,10,5)
    /* no pmGetVersion() before PCP 3.10.5 */
    printf("PCP version 0x%x too old\n", PM_VERSION_CURRENT);
#endif
    version = pmGetVersion();
    if (version >= PM_VERSION(4,0,0) {
     /* V2 of the XYZ service introduced in PCP 4.0.0 */
     printf("Using V2 of service XYZ\n")
     ...
    }
    else {
     printf("Using V1 of service XYZ\n")
     ...
    }
#else
    {
     char *ver = pmGetConfig("PCP_VERSION");
     /* only option is to extract version number from returned string */
     ...
    }
#endif

πŸ‘‘ SEE ALSO πŸ‘‘

PMAPI(3), and pmGetConfig(3).


and that's the whole page, bestie πŸ’œ this little gem lives in the Performance Co-Pilot (PCP) manual, filed under PMGETVERSION(3) β€” go forth and version-check responsibly πŸ¦‹

πŸ“¦ where this page comes from