1PMDAMAIN(3) Library Functions Manual PMDAMAIN(3)
2
3
4
6 pmdaMain, pmdaMainLoop, pmdaSetResultCallBack, pmdaSetCheckCallBack,
7 pmdaSetDoneCallBack, pmdaMainLoopFreeResultCallback - generic PDU pro‐
8 cessing for a PMDA
9
11 #include <pcp/pmapi.h>
12 #include <pcp/impl.h>
13 #include <pcp/pmda.h>
14
15 cc ... -lpcp_pmda -lpcp
16
17 PMDA Interface 2 or higher
18
19 void pmdaMain(pmdaInterface *dispatch);
20
21 void pmdaSetResultCallBack(pmdaInterface *dispatch, pmdaResultCallBack
22 callback);
23
24 void pmdaSetCheckCallBack(pmdaInterface *dispatch, pmdaCheckCallBack
25 callback);
26
27 void pmdaSetDoneCallBack(pmdaInterface *dispatch, pmdaDoneCallBack
28 callback);
29
30 PMDA Interface 1
31
32 void pmdaMainLoop(char *name, int infd, int outfd, _pmPMDA *dispatch,
33 int (*check)(void), void (*done)(void));
34
35 void pmdaMainLoopFreeResultCallback(void (*callback)(pmResult *res));
36
38 For Performance Metric Domain Agents (PMDA(3)) using the binary PDU
39 protocols to communicate with pmcd(1), the routine pmdaMain provides a
40 generic implementation of the PDU-driven main loop.
41
42 pmdaMainLoop and pmdaMainLoopFreeResultCallback implemented an earlier
43 version of this functionality. Both functions will be removed in a
44 later release and should not be used.
45
46 The arguments that are now encapsulated in pmdaExt that were passed to
47 pmdaMainLoop include the name of the PMDA (used only in error messages)
48 and the file descriptors infd and outfd used to receive and send PDUs
49 to the pmcd(1) process.
50
51 dispatch describes how to process each incoming PDU. It is a vector of
52 function pointers, one per request PDU type, as used in the DSO inter‐
53 face for a PMDA, namely:
54
55 /*
56 * Interface Definitions for PMDA Methods
57 */
58 typedef struct {
59 int domain; /* set/return performance metrics domain id here */
60 struct {
61 unsigned int pmda_interface: 8; /* PMDA DSO interface version */
62 unsigned int pmapi_version : 8; /* PMAPI version */
63 unsigned int flags : 16; /* usage TBD */
64 } comm; /* set/return communication and version info */
65 int status; /* return initialization status here */
66
67 union {
68 struct { /* PMDA_INTERFACE_1 */
69 int (*profile)(__pmProfile *);
70 int (*fetch)(int, pmID *, pmResult **);
71 int (*desc)(pmID, pmDesc *);
72 int (*instance)(pmInDom, int, char *, __pmInResult **);
73 int (*text)(int, int, char **);
74 int (*control)(pmResult *, int, int, int);
75 int (*store)(pmResult *);
76 } one;
77
78 struct { /* PMDA_INTERFACE_2 or _3 */
79 pmdaExt *e_ext;
80 int (*profile)(__pmProfile *, pmdaExt *);
81 int (*fetch)(int, pmID *, pmResult **, pmdaExt *);
82 int (*desc)(pmID, pmDesc *, pmdaExt *);
83 int (*instance)(pmInDom, int, char *, __pmInResult **, pmdaExt *);
84 int (*text)(int, int, char **, pmdaExt *);
85 int (*store)(pmResult *, pmdaExt *);
86 } two;
87
88 struct { /* PMDA_INTERFACE_4 */
89 pmdaExt *ext;
90 int (*profile)(__pmProfile *, pmdaExt *);
91 int (*fetch)(int, pmID *, pmResult **, pmdaExt *);
92 int (*desc)(pmID, pmDesc *, pmdaExt *);
93 int (*instance)(pmInDom, int, char *, __pmInResult **, pmdaExt *);
94 int (*text)(int, int, char **, pmdaExt *);
95 int (*store)(pmResult *, pmdaExt *);
96 int (*pmid)(char *, pmID *, pmdaExt *);
97 int (*name)(pmID, char ***, pmdaExt *);
98 int (*children)(char *, int, char ***, int **, pmdaExt *);
99 } four;
100 } version;
101
102 } pmdaInterface;
103
104 This structure has been extended to incorporate the multiple interface
105 versions that have evolved over time. For pmdaMain, dispatch->domain
106 and dispatch->status are ignored. The comm.pmda_interface field is
107 used to determine the interface used by the PMDA. Setting this field
108 to PMDA_INTERFACE_1 will force pmdaMain to use the callbacks in the
109 version.one structure. A setting of PMDA_INTERFACE_2 or PMDA_INTER‐
110 FACE_3 will force pmdaMain to use the callbacks in the version.two
111 structure. A setting of PMDA_INTERFACE_4 will force pmdaMain to use
112 the callbacks in the version.four structure. Any other value will
113 result in an error and termination of pmdaMain.
114
115 Note that the use of dispatch as the interface between the pmcd(1) and
116 the methods of the PMDA allows each PMDA to be implemented as though it
117 were a DSO, with pmdaMain providing a convenient wrapper that may be
118 used to convert from the DSO interface to the binary PDU (daemon PMDA)
119 interface.
120
121 pmdaMainLoop provided two additional callbacks, check and done. If not
122 null, check is called after each PDU is received (but before it was
123 processed), and done is called after each PDU is sent. If check
124 returns a value less than zero (typically PM_ERR_AGAIN), the PDU pro‐
125 cessing is skipped and in most cases the function value is returned as
126 an error PDU to pmcd(1) - this may be used for PMDAs that require some
127 sort of deferred connection or reconnect protocols for the underlying
128 sources of performance metrics, e.g. a DBMS. The error indication from
129 check is not passed back to pmcd(1) in the cases where no acknowledg‐
130 ment is expected, e.g. for a PDU_PROFILE.
131
132 The callback done would typically be used to monitor termination condi‐
133 tions, or do PMDA housekeeping required after PDU processing.
134
135 These callbacks should now be set with pmdaSetCheckCallBack and
136 pmdaSetDoneCallBack when using pmdaMain.
137
138 One further callback mechanism is provided for handling the pmResult
139 built for a PDU_RESULT in response to a PDU_FETCH request. By default,
140 pmdaMain will free the pmResult once the result has been sent to the
141 pmcd(1). For some PMDAs this is inappropriate, e.g. the pmResult is
142 statically allocated, or contains a hybrid of pinned PDU buffer infor‐
143 mation and dynamically allocated information. pmdaSetResultCallback
144 may be used to define an alternative callback from pmdaMain. The rou‐
145 tine pmdaMainLoopFreeResultCallback has been replaced by pmdaSetResult‐
146 CallBack.
147
148 pmdaMain executes as a continuous loop, returning only when an end of
149 file is encountered on the PDU input file descriptor.
150
152 pmcd(1), pmdbg(1), PMAPI(3) and PMDA(3).
153
155 These messages may be appended to the PMDA's log file:
156
157 PMDA interface version interface not supported
158 The interface version is not supported by
159 pmdaMain.
160
161 Unrecognized pdu type The PMDA received a PDU from pmcd that it does
162 not recognize. This may indicate that the pmcd
163 process is using a more advanced interface
164 than pmdaMain.
165
166 If the PMAPI(3) debug control variable (pmdebug) has the
167 DBG_TRACE_LIBPMDA flag set then each PDU that is received is reported
168 in the PMDA's log file.
169
170
171
172Performance Co-Pilot SGI PMDAMAIN(3)