PMPARSEMETRICSPEC(3)

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

✨ PMPARSEMETRICSPEC(3) ✨

okay bestie, so this one is pmParseMetricSpec and pmFreeMetricSpec from the Library Functions Manual β€” the uniform metric specification parser πŸ’… she's a libpcp girlie, part of the PCP (Performance Co-Pilot) situation, and honestly? she ate.


πŸŽ€ NAME πŸŽ€

pmParseMetricSpec, pmFreeMetricSpec β€” uniform metric specification parser. yes that's the whole name section, no notes, periodt ✨


🌸 C SYNOPSIS 🌸

#include <pcp/pmapi.h>

int pmParseMetricSpec(const char *string, int isarch, char *source,
                      pmMetricSpec **rsltp, char **errmsg);
void pmFreeMetricSpec(pmMetricSpec *rslt);

cc ... -lpcp

like, you gotta link -lpcp or she simply will not show up. non-negotiable 🫢


πŸ’– DESCRIPTION πŸ’–

so pmParseMetricSpec takes a string that names a PCP performance metric, and optionally the source for it β€” which is either a hostname or a PCP archive filename β€” plus the instances for that metric. the whole syntax vibe is described over in PCPIntro(1), go check her out πŸ”₯

if you don't provide either the host or the archive component in your metric spec, then the isarch and source arguments get used to fill in the returned pmMetricSpec structure instead. it's giving "we got you, bestie, we'll fill in the blanks" πŸ’–


πŸ¦‹ the struct πŸ¦‹

the pmMetricSpec structure that comes back to you via rsltp represents the parsed string, and her declaration is literally this:

typedef struct {
    int     isarch;      /* source type: 0 -> live host, 1 -> archive, 2 -> local context */
    char    *source;     /* name of source host or archive */
    char    *metric;     /* name of metric */
    int     ninst;       /* number of instances, 0 -> all */
    char    *inst[1];    /* array of instance names */
} pmMetricSpec;

look at her. isarch is doing main character work: 0 means live host, 1 means archive, 2 means local context. ninst being 0 means all the instances, and inst[1] is the array of instance names, iykyk πŸ‘‘


πŸ’… what she returns πŸ’…

pmParseMetricSpec returns 0 if the given string was successfully parsed. slay. in that case, literally all the storage allocated by pmParseMetricSpec can be released with a single call to free(3) using the address returned from pmMetricSpec via rsltp. one call. that's it. the convenience macro pmFreeMetricSpec is, and I quote, a thinly disguised wrapper for free(3) β€” she's not doing anything fancy, she's just free(3) in a cute little outfit πŸŽ€

if the given string does not parse, pmParseMetricSpec returns PM_ERR_GENERIC and hands you a dynamically allocated error message string in errmsg. and bestie, you must free(3) that error message string in this situation. don't leave her hanging 😭

⚠️ undefined-behaviour check, and this is important so listen up: in the case of an error, rsltp is undefined. in the case of success, errmsg is undefined. and if rsltp->ninst is 0, then rsltp->inst[0] is undefined. do not go poking at those, fr fr πŸ’€

🌈 SEE ALSO 🌈


Performance Co-Pilot Β· PCP Β· PMPARSEMETRICSPEC(3) β€” that's the source, the version and the date, all wrapped up with a bow πŸŽ€βœ¨ thanks for reading, mwah πŸ’–πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from