summaryrefslogtreecommitdiff
path: root/man/man3/pmsetmode.3
blob: 7b47281a8285b6e49b6d7d57ff36a5009719b94b (plain)
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
'\"macro stdmacro
.\"
.\" Copyright (c) 2000-2004 Silicon Graphics, Inc.  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 PMSETMODE 3 "PCP" "Performance Co-Pilot"
.SH NAME
\f3pmSetMode\f1 \- set collection time parameters for the current PMAPI context
.SH "C SYNOPSIS"
.ft 3
#include <pcp/pmapi.h>
.sp
int pmSetMode(int \fImode\fP, const struct timeval *\fIwhen\fP, int \fIdelta\fP);
.sp
cc ... \-lpcp
.ft 1
.SH DESCRIPTION
.de CW
.ie t \f(CW\\$1\f1\\$2
.el \fI\\$1\f1\\$2
..
.B pmSetMode
is used to define the collection time and/or mode for accessing
performance metrics and meta-data in the current
Performance Metrics Application Programming Interface (PMAPI)
context.
This mode affects the semantics of subsequent calls to the following
PMAPI routines: 
.BR pmFetch (3),
.BR pmFetchArchive (3),
.BR pmLookupDesc (3),
.BR pmGetInDom (3),
.BR pmLookupInDom (3)
and
.BR pmNameInDom (3).
.PP
If
.I mode
is
.B PM_MODE_LIVE
then all information is returned from the active pool of performance metrics
as of the time that the PMAPI call is made, and the other two parameters to
.B pmSetMode
are ignored.
.B PM_MODE_LIVE
is the default mode when a new PMAPI context of type
.B PM_CONTEXT_HOST
is created.
.PP
If the
.I mode
is not
.BR PM_MODE_LIVE ,
then the
.I when
parameter defines a time origin, and all requests for meta-data (metric
descriptions and instance identifiers from the instance domains) will be
processed to reflect the state of the meta-data as of the time origin, i.e. we
use the last state of this information at, or before, the time origin.
.PP
If the
.I mode
is
.B PM_MODE_INTERP
then, in the case of
.BR pmFetch (3),
the underlying code will use an interpolation scheme to compute the values of
the metrics from the values recorded for times in the proximity of the time
origin.
A
.I mode
of
.B PM_MODE_INTERP
may only be used with an archive context.
.PP
If the
.I mode
is
.B PM_MODE_FORW
then, in the case of
.BR pmFetch (3),
the collection of recorded metric values will be scanned in a forwards
direction in time, until values for at least one of the requested metrics is
located after the time origin, and then all requested metrics stored in the log
or archive at that time will be returned with the corresponding timestamp.
A
.I mode
of
.B PM_MODE_FORW
may only be used with an archive context.
.PP
If the
.I mode
is
.B PM_MODE_BACK
then, the situation is the same as for
.BR PM_MODE_FORW ,
except a
.BR pmFetch (3)
will be serviced by scanning the collection of recorded metrics in a backwards
direction in time for metrics before the time origin.
A
.I mode
of
.B PM_MODE_BACK
may only be used with an archive context.
.PP
If the
.I mode
is
.B PM_MODE_FORW
or
.BR PM_MODE_BACK ,
and no qualifying metrics can be found in the requested direction of searching
before the end or start of the archive
log is found, then
.BR pmFetch (3)
returns the special error indicator,
.BR PM_ERR_EOL .
.PP
For
.IR mode s
other than
.BR PM_MODE_LIVE ,
after each successful 
.BR pmFetch (3),
the time origin is reset to the timestamp returned via the
.CW pmResult
structure from
.BR pmFetch (3).
.PP
The
.B pmSetMode
parameter
.I delta
defines an additional number of time units that should be used to adjust the
time origin (forwards or backwards), after the new time origin from the
.CW pmResult
has been determined.
This automatic adjustment of the time origin only occurs when the
.I mode
is
.BR PM_MODE_INTERP ,
and the adjustment is applied, even if the
.BR pmFetch (3)
fails because the time origin is outside the range defined by
the records in an archive log, i.e. returns
.BR PM_ERR_EOL .
The high-order bits of the
.I mode
parameter is also used to optionally set the units of time for the
.I delta
field. To specify the units of time use
.B PM_XTB_SET 
macro with one of the values
.BR PM_TIME_NSEC ,
.BR PM_TIME_MSEC ,
.BR PM_TIME_SEC ,
etc.
as follows:
.P
.in +0.5i
PM_MODE_INTERP | PM_XTB_SET(PM_TIME_XXXX)
.P
If no units are specified the default is to interpret
.I delta
as milliseconds. 
.PP
Using these
.I mode
options, an application can implement replay, playback, fast forward, reverse,
etc. for performance metric values held in the archive log by alternating calls
to
.B pmSetMode
and
.BR pmFetch (3).
.PP
As a special case, if
.I when
is
.B NULL
then the
.I mode
and
.I delta
arguments are used as described above, but the current time in the archive
is not altered.
.PP
For example, the following code fragment may be used to dump just those values
recorded in an archive in correct temporal sequence, for a selected set of
performance metrics; this uses the default collection time mechanisms.
.PP
.ft CW
.nf
.in +0.5i
pmNewContext(PM_CONTEXT_ARCHIVE, "myarchive");
while (pmFetch(npmid, pmidlist, &result) != PM_ERR_EOL) {
    /*
     * process real metric values as of result->timestamp
     */
    \&. . .
    pmFreeResult(result);
}
.in
.fi
.ft 1
.PP
Alternatively, to replay interpolated metrics from the log in reverse
chronological order, at 10 second intervals (of recorded time), the following
code fragment could be used.
.PP
.ft CW
.nf
.in +0.5i
struct timeval mytime;

mytime.tv_sec = 0x7fffffff;
pmSetMode(PM_MODE_BACK, &mytime, 0);
pmFetchArchive(&result);
mytime = result->timestamp;
pmFreeResult(result);
pmSetMode(PM_MODE_INTERP | PM_XTB_SET(PM_TIME_SEC), &mytime, \-10);

while (pmFetch(numpmid, pmidlist, &result) != PM_ERR_EOL) {
    /*
     * process interpolated metric values as of
     * result->timestamp
     */
    \&. . .
    pmFreeResult(result);
}
.in
.fi
.ft 1
.SH "SEE ALSO"
.BR PMAPI (3),
.BR pmFetch (3),
.BR pmFetchArchive (3),
.BR pmGetInDom (3),
.BR pmLookupDesc (3),
.BR pmLookupInDom (3)
and
.BR pmNameInDom (3).
.SH DIAGNOSTICS
.IP \f3PM_ERR_MODE\f1
The
.I mode
parameter is invalid