1PMLOOKUPNAME(3) Library Functions Manual PMLOOKUPNAME(3)
2
3
4
6 pmLookupName - translate performance metric names into PMIDs
7
9 #include <pcp/pmapi.h>
10
11 int pmLookupName(int numpmid, const char **namelist, pmID *pmidlist);
12
13 cc ... -lpcp
14
16 Given a list in namelist containing numpmid full pathnames for perfor‐
17 mance metrics from a Performance Metrics Name Space (PMNS), pmLookup‐
18 Name returns the list of associated Performance Metric Identifiers
19 (PMIDs) via pmidlist.
20
21 The result from pmLookupName depends on the presence of any lookup
22 failures, their severity and the number of metrics being looked up.
23
24 1. If there are no lookup failures, the return value will be numpmid.
25
26 2. If a fatal error is encountered, the return value will be less than
27 0. For example PM_ERR_TOOSMALL, PM_ERR_NOPMNS or PM_ERR_IPC.
28
29 3. If numpmid is greater than one and non-fatal error(s) are encoun‐
30 tered, the return value is the number of metric names that have
31 successfully been looked up (greater than or equal to zero and less
32 than or equal to numpmid).
33
34 4. If numpmid is one and a non-fatal error is encountered, the return
35 value is the error code (less than zero).
36
37 When errors are encountered, any metrics that cannot be looked up
38 result in the corresponding element of pmidlist being set to
39 PM_ID_NULL.
40
41 The slightly convoluted error protocol allows bulk lookups, then prob‐
42 ing for more error details in the case of a specific failure, as shown
43 in the EXAMPLES section below.
44
45 Note that the error protocol guarantees there is a 1:1 relationship
46 between the elements of namelist and pmidlist, hence both lists contain
47 exactly numpmid elements. For this reason, the caller is expected to
48 have pre-allocated a suitably sized array for pmidlist.
49
51 #include <pcp/pmapi.h>
52
53 #define NUMPMID (sizeof(names)/sizeof(const char *))
54 const char *names[] = {
55 "sample.bin",
56 "sample",
57 "sample.bog",
58 "sample.secret.bar",
59 "sample.secret.bar.bad"
60 };
61 pmID pmids[NUMPMID];
62
63 int
64 main(int argc, char **argv)
65 {
66 int sts;
67 int numpmid = NUMPMID;
68
69 pmNewContext(PM_CONTEXT_HOST, "local:");
70
71 sts = pmLookupName(numpmid, names, pmids);
72
73 if (sts < 0) {
74 fprintf(stderr, "pmLookupName failed: %s0, pmErrStr(sts));
75 exit(1);
76 }
77 if (sts != numpmid) {
78 /*
79 * some of the lookups failed ... report the reason(s)
80 */
81 int i;
82
83 for (i = 0; i < numpmid; i++) {
84 if (pmids[i] != PM_ID_NULL) continue;
85 /* this one failed */
86 sts = pmLookupName(1, &names[i], &pmids[i]);
87 fprintf(stderr, "%s: lookup failed: %s0, names[i], pmErrStr(sts));
88 }
89 exit(1);
90 }
91
92 /* all good ... */
93 ...
94 }
95
96
98 PMAPI(3), pmGetChildren(3), pmGetChildrenStatus(3), pmGetConfig(3),
99 pmLoadNameSpace(3), pmNameID(3), pmNewContext(3), pcp.conf(5) and
100 pcp.env(5).
101
103 PM_ERR_TOOSMALL
104 numpmid must be at least 1
105
106 PM_ERR_NOPMNS
107 Failed to access a PMNS for operation. Note that if the appli‐
108 cation hasn't a priori called pmLoadNameSpace(3) and wants to
109 use the distributed PMNS, then a call to pmLookupName must be
110 made after the creation of a context (see pmNewContext(3)).
111
112 PM_ERR_NAME
113 namelist[0] does not correspond to a valid metric name in the
114 PMNS.
115
116 PM_ERR_NONLEAF
117 namelist[0] refers to a node in the PMNS but it was not a leaf
118 node.
119
120 PM_ERR_*
121 Other diagnostics are for protocol failures when accessing the
122 distributed PMNS.
123
124
125
126Performance Co-Pilot PCP PMLOOKUPNAME(3)