1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
'\"macro stdmacro
.\"
.\" Copyright (c) 2014 Red Hat.
.\" Copyright (c) 2010 Ken McDonell. All Rights Reserved.
.\"
.\" This program is free software; you can redistribute it and/or modify it
.\" under the terms of the GNU General Public License as published by the
.\" Free Software Foundation; either version 2 of the License, or (at your
.\" option) any later version.
.\"
.\" This program is distributed in the hope that it will be useful, but
.\" WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
.\" or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
.\" for more details.
.\"
.\"
.TH PMDAEVENTARRAY 3 "PCP" "Performance Co-Pilot"
.SH NAME
.ad l
\f3pmdaEventNewArray\f1,
\f3pmdaEventResetArray\f1,
\f3pmdaEventReleaseArray\f1,
\f3pmdaEventAddRecord\f1,
\f3pmdaEventAddMissedRecord\f1,
\f3pmdaEventAddParam\f1,
\f3pmdaEventGetAddr\f1,
\f3pmdaEventNewHighResArray\f1,
\f3pmdaEventResetHighResArray\f1,
\f3pmdaEventReleaseHighResArray\f1,
\f3pmdaEventAddHighResRecord\f1,
\f3pmdaEventAddHighResMissedRecord\f1,
\f3pmdaEventHighResAddParam\f1,
\f3pmdaEventHighResGetAddr\f1 \- utilities for PMDAs to build packed arrays of event records
.br
.ad
.SH "C SYNOPSIS"
.ft 3
.nf
#include <pcp/pmapi.h>
#include <pcp/impl.h>
#include <pcp/pmda.h>
.fi
.sp
.ad l
.hy 0
.in +8n
.ti -8n
int pmdaEventNewArray(void);
.br
.ti -8n
int pmdaEventResetArray(int \fIidx\fP);
.br
.ti -8n
int pmdaEventReleaseArray(int \fIidx\fP);
.br
.ti -8n
int pmdaEventAddRecord(int \fIidx\fP, struct timeval *\fItp\fP, int\ \fIflags\fP);
.br
.ti -8n
int pmdaEventAddMissedRecord(int \fIidx\fP, struct timeval *\fItp\fP, int\ \fInmissed\fP);
.br
.ti -8n
int pmdaEventAddParam(int \fIidx\fP, pmID \fIpmid\fP, int \fItype\fP, pmAtomValue\ *\fIavp\fP);
.br
.ti -8n
pmEventArray *pmdaEventGetAddr(int \fIidx\fP);
.sp
.in
.hy
.ad l
.hy 0
.in +8n
.ti -8n
int pmdaEventNewHighResArray(void);
.br
.ti -8n
int pmdaEventResetHighResArray(int \fIidx\fP);
.br
.ti -8n
int pmdaEventReleaseHighResArray(int \fIidx\fP);
.br
.ti -8n
int pmdaEventAddHighResRecord(int \fIidx\fP, struct timespec *\fIts\fP, int\ \fIflags\fP);
.br
.ti -8n
int pmdaEventAddHighResMissedRecord(int \fIidx\fP, struct timespec *\fIts\fP, int\ \fInmissed\fP);
.br
.ti -8n
int pmdaEventHighResAddParam(int \fIidx\fP, pmID \fIpmid\fP, int \fItype\fP, pmAtomValue\ *\fIavp\fP);
.br
.ti -8n
pmHighResEventArray *pmdaEventHighResGetAddr(int \fIidx\fP);
.sp
.in
.hy
.ad
cc ... \-lpcp
.ft 1
.SH DESCRIPTION
.de CW
.ie t \f(CW\\$1\f1\\$2
.el \fI\\$1\f1\\$2
..
A Performance Metrics Domain Agent (PMDA) that wishes to export
event records (or trace records) is encouraged to use a metric of
either type
.B PM_TYPE_EVENT
or
.B PM_TYPE_HIGHRES_EVENT
to encode a group of event records into a single packed array.
.PP
The only difference between the two metric types is the resolution
of the timestamp associated with each \- in high resolution form it
is nanosecond scale (see
.BR clock_gettime (2)),
otherwise it is microseconds (see
.BR gettimeofday (2)).
For simplicity, we will only refer to the lower resolution API and
data structures hereafter \- however, the higher resolution variants
are all named similarly and are used in the same way.
.PP
The packed array of event records format is defined in
.I <pcp/pmapi.h>
and consists of a
.B pmEventArray
structure containing a variable number of
.B pmEventRecord
structures, each of which contains a variable number of
.B pmEventParameter
structures, which in turn may contain a variable length value for
each parameter of each event record.
.PP
The higher resolution equivalents are defined in the same location,
and the structures are named the same.
Note that the
.B pmEventParameter
structure has no timestamp associated with it, hence it this does not
have a high resolution counterpart.
.PP
The routines described here are designed to assist the PMDA developer
in building a packed array of event records, and managing all of the
memory allocations required to hold each instance of an array of event
records in a contiguous buffer. Normal use would be as part of PMDA's
.B pmdaFetchCallBack
method.
.PP
.B pmdaEventNewArray
is used to create a new event array. The return value is a small integer that
is used as the
.I idx
parameter to the other routines to identify a specific event array.
If needed, a PMDA can create and use multiple event arrays.
.PP
To start a new cycle and refill an event array from the beginning, call
.BR pmdaEventResetArray .
.PP
If the PMDA has finished with an event array,
.B pmdaEventReleaseArray
may be used to release the underlying storage and ``close'' the event
array so that subsequent attempts to use
.I idx
will return
.BR PM_ERR_NOCONTEXT .
.PP
To start a new event record, use
.BR pmdaEventAddRecord .
The timestamp for the event record is given via
.I tp
and the
.I flags
parameter may be used to set the control field that determines the
type of the event record \-
.I flags
may be the bit-wise ``or'' of one or more of the
.B PM_EVENT_FLAG_*
values defined in
.I <pcp/pmapi.h>
(but note that
.B PM_EVENT_FLAG_MISSED
should not be used in this context).
.PP
If event records have been missed, either because the PMDA cannot keep
up or because the PMAPI client cannot keep up, then
.B pmdaEventAddMissedRecord
may be used.
.I
idx
and
.I tp
have the same meaning as for
.B pmdaEventAddRecord
and
.I nmissed
is the number of event records that have been missed at this point
in the time-series of event records.
.B pmdaEventAddMissedRecord
may be called multiple times for a single batch of event records
if there are more than one ``missed event record'' episode.
.PP
Once an event record has been started by calling
.BR pmdaEventAddRecord ,
one or more event parameters may be added using
.BR pmdaEventAddParam .
The
.I pmid
and
.I type
parameters decribe the PMID of the parameter and the data type
(one of the
.B PM_TYPE_*
values from
.IR <pcp/pmapi.h> )
of the value that is passed via
.IR avp .
.I type
should one where the size of the value is implied by the
.I type
or by the length of a string value (for
.BR PM_TYPE_STRING )
or encoded within
.I avp->vbp
(for
.BR PM_TYPE_AGGREGATE ).
.PP
Once the packed array has been constructed,
.B pmdaEventGetAddr
should be used to initialize the
.B ea_type
and
.B ea_len
fields at the start of the
.B pmEventArray
and return the base address of the event array
that is assigned to the
.B vp
field of the
.B pmAtomValue
structure that the
.B pmdaFetchCallBack
method should return.
.SH EXAMPLE
The following skeletal code shows how these routines might be used.
.PP
.ft CW
.ps -1
.nf
int sts;
int myarray;
int first = 1;
pmEventArray eap;
if (first) {
first = 0;
if ((myarray = pmdaEventNewArray()) < 0) {
// report error and fail
}
}
pmdaEventResetArray(myarray);
// loop over all event records to be exported
\&... {
struct timeval stamp;
int flags;
// establish timestamp and set flags to 0 or some combination
// of PM_EVENT_FLAG_POINT, PM_EVENT_FLAG_START, PM_EVENT_FLAG_ID,
// etc
if ((sts = pmdaEventAddRecord(myarray, &stamp, flags)) < 0) {
// report error and fail
}
// loop over all parameters for this event record
... {
pmID pmid;
int type;
pmAtomValue atom;
// construct pmid, type and atom for the parameter and
// its value
if ((sts = pmdaEventAddParam(myarray, pmid, type, &atom)) < 0) {
// report error and fail
}
}
// if some event records were missed (could be at the start
// of the exported set, or at the end, or in the middle, or
// a combination of multiple missed record episodes)
... {
int nmiss;
struct timeval stamp;
if ((sts = pmdaEventAddMissedRecord(myarray, &stamp, nmiss)) < 0) {
// report error and fail
}
}
}
// finish up
eap = pmdaEventGetAddr(myarray);
.fi
.ps
.ft
.SH SEE ALSO
.BR clock_gettime (2),
.BR gettimeofday (2),
.BR pmdaEventNewQueue (3),
.BR pmdaEventNewClient (3),
.BR PMDA (3)
and
.BR pmEventFlagsStr (3).
|