PMLOOKUPNAME(3) | Library Functions Manual | PMLOOKUPNAME(3) |
pmLookupName - translate performance metric names into PMIDs
#include <pcp/pmapi.h>
int pmLookupName(int numpmid, char **namelist, pmID *pmidlist);
cc ... -lpcp
Given a list in namelist containing numpmid full pathnames for performance metrics from a Performance Metrics Name Space (PMNS), pmLookupName returns the list of associated Performance Metric Identifiers (PMIDs) via pmidlist.
The result from pmLookupName depends on the presence of any lookup failures, their severity and the number of metrics being looked up.
When errors are encountered, any metrics that cannot be looked up result in the corresponding element of pmidlist being 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, as shown in the EXAMPLES section below.
Note that the error protocol guarantees there is a 1:1 relationship between the elements of namelist and pmidlist, hence both lists contain exactly numpmid elements. For this reason, the caller is expected to have pre-allocated a suitably sized array for pmidlist.
#include <pcp/pmapi.h> #define NUMPMID 5 char *names[] = { "sample.bin", "sample", "sample.bog", "sample.secret.bar", "sample.secret.bar.bad" }; pmID pmids[NUMPMID]; int main(int argc, char **argv) {
int sts;
int numpmid = NUMPMID;
pmNewContext(PM_CONTEXT_HOST, "local:");
sts = pmLookupName(numpmid, names, pmids);
if (sts < 0) { fprintf(stderr, "pmLookupName failed: %s0, pmErrStr(sts)); exit(1);
}
if (sts != numpmid) { /* * some of the lookups failed ... report the reason(s) */ int i; for (i = 0; i < numpmid; i++) { if (pmids[i] != PM_ID_NULL) continue; /* this one failed */ sts = pmLookupName(1, &names[i], &pmids[i]); fprintf(stderr, "%s: lookup failed: %s0, names[i], pmErrStr(sts)); } exit(1);
}
/* all good ... */
... }
PMAPI(3), pmGetChildren(3), pmGetChildrenStatus(3), pmGetConfig(3), pmLoadNameSpace(3), pmNameID(3), pmNewContext(3), pcp.conf(5) and pcp.env(5).
PCP | Performance Co-Pilot |