1PMLOOKUPNAME(3)            Library Functions Manual            PMLOOKUPNAME(3)
2
3
4

NAME

6       pmLookupName - translate performance metric names into PMIDs
7

C SYNOPSIS

9       #include <pcp/pmapi.h>
10
11       int pmLookupName(int numpmid, char **namelist, pmID *pmidlist);
12
13       cc ... -lpcp
14

DESCRIPTION

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

EXAMPLE

51       #include <pcp/pmapi.h>
52
53       #define NUMPMID 5
54       char      *names[] = { "sample.bin",
55                      "sample",
56                      "sample.bog",
57                      "sample.secret.bar",
58                      "sample.secret.bar.bad"
59                    };
60       pmID pmids[NUMPMID];
61
62       int
63       main(int argc, char **argv)
64       {
65           int   sts;
66           int   numpmid = NUMPMID;
67
68           pmNewContext(PM_CONTEXT_HOST, "local:");
69
70           sts = pmLookupName(numpmid, names, pmids);
71
72           if (sts < 0) {
73            fprintf(stderr, "pmLookupName failed: %s0, pmErrStr(sts));
74            exit(1);
75           }
76           if (sts != numpmid) {
77            /*
78             * some of the lookups failed ... report the reason(s)
79             */
80            int  i;
81
82            for (i = 0; i < numpmid; i++) {
83                if (pmids[i] != PM_ID_NULL) continue;
84                /* this one failed */
85                sts = pmLookupName(1, &names[i], &pmids[i]);
86                fprintf(stderr, "%s: lookup failed: %s0, names[i], pmErrStr(sts));
87            }
88            exit(1);
89           }
90
91           /* all good ... */
92           ...
93       }
94
95

SEE ALSO

97       PMAPI(3),   pmGetChildren(3),  pmGetChildrenStatus(3),  pmGetConfig(3),
98       pmLoadNameSpace(3),  pmNameID(3),  pmNewContext(3),   pcp.conf(5)   and
99       pcp.env(5).
100

DIAGNOSTICS

102       PM_ERR_TOOSMALL
103              numpmid must be at least 1
104
105       PM_ERR_NOPMNS
106              Failed  to access a PMNS for operation.  Note that if the appli‐
107              cation hasn't a priori called pmLoadNameSpace(3)  and  wants  to
108              use  the  distributed  PMNS, then a call to pmLookupName must be
109              made after the creation of a context (see pmNewContext(3)).
110
111       PM_ERR_NAME
112              namelist[0] does not correspond to a valid metric  name  in  the
113              PMNS.
114
115       PM_ERR_NONLEAF
116              namelist[0]  refers  to a node in the PMNS but it was not a leaf
117              node.
118
119       PM_ERR_*
120              Other diagnostics are for protocol failures when  accessing  the
121              distributed PMNS.
122
123
124
125Performance Co-Pilot                  PCP                      PMLOOKUPNAME(3)
Impressum