summaryrefslogtreecommitdiff
path: root/man/man1/pmgenmap.1
blob: 7f3d0bb9158ff5414b7068b19661d60e6786bfeb (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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
'\"macro stdmacro
.\"
.\" Copyright (c) 2000 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 PMGENMAP 1 "PCP" "Performance Co-Pilot"
.SH NAME
\f3pmgenmap\f1 \- generate C code to simplify handling of performance metrics
.\" literals use .B or \f3
.\" arguments use .I or \f2
.SH SYNOPSIS
\f3pmgenmap\f1
[\f2infile\f1]
.SH DESCRIPTION
.de CW
.ie t \f(CW\\$1\f1\\$2
.el \fI\\$1\f1\\$2
..
Given one or more lists of metric names in
.I infile
or on standard input,
.B pmgenmap
generates C declarations
and
.BR cpp (1)
macros suitable for use across the
Performance Metrics Programming Interface (PMAPI)
on standard output.
.PP
The declarations produced by
.B pmgenmap
simplify the coding for client applications using the PMAPI.
.PP
The input should consist of one or more lists of metric names of the form
.PP
.ft CW
.nf
.in +0.5i
listname {
    metricname1 symbolname1
    metricname2 symbolname2
    ...
}
.in
.fi
.ft 1
.PP
which will generate C and
.BR cpp (1)
declarations of the form
.PP
.ft CW
.nf
.in +0.5i
char *listname[] = {
#define symbolname1 0
    "metricname1",
#define symbolname2 1
    "metricname2",
    ...
};
.in
.fi
.ft 1
.PP
The array declarations produced are suitable as parameters to
.BR pmLookupName (3)
and the
.BR #define d
constants may be used to index the
.CW vset s
in the
.CW pmResult
structure returned by a
.BR pmFetch (3)
call.
.PP
Obviously,
.CW listname
must conform to the C identifier naming rules, each
.CW symbolname
must conform to the
.BR cpp (1)
macro naming rules, and each
.CW metricname
is expected to be a valid performance metrics name (see
.BR pmns (5)
for more details).
.PP
The input may include
.BR sh -style
comment lines, i.e. with a `\f3#\f1' as the first non-blank character of a
line, and these are translated on output to either single line or multi-line C
comments in the K&R style.  For example, the input:

.PP
.ft CW
.nf
.in +0.5i
# leading block of multi-line comments
# initialization group
foo {
        a.b.c   ONE
        d.e.f.g TWO
        # embedded block of multi-lines
        # comments and boring pad text
        xx.yy.zz        THREE
}

# trailing single line comment
.in
.fi
.ft 1
.PP

Produces the output:
.PP
.ft CW
.nf
.in +0.5i
/*
 * leading block of multi-line comments
 * initialization group
 */
char *foo[] = {
#define ONE 0
        "a.b.c",
#define TWO 1
        "d.e.f.g",
/*
 * embedded block of multi-lines
 * comments and boring pad text
 */
#define THREE 2
        "xx.yy.zz",

};


/* trailing single line comment */
.in
.fi
.ft 1
.SH EXAMPLE
For brevity we have removed the error handling code, and assumed the chosen
metrics do not have multiple values.
.PP
The input file
.PP
.ft CW
.nf
.in +0.5i
mystats {
    kernel.percpu.cpu.idle     IDLE
    kernel.percpu.cpu.sys      SYS
    kernel.percpu.cpu.user     USER
    hinv.ncpu                       NCPU
}
.in
.fi
.ft 1
.PP
produces the following C code, suitable for
.BR #include -ing
.PP
.ft CW
.nf
.in +0.5i
/*
 * Performance Metrics Name Space Map
 * Built by pmgenmap from the file
 * mystats.metrics
 * on Wed Dec 28 19:44:17 EST 1994
 *
 * Do not edit this file!
 */

char *mystats[] = {
#define IDLE    0
        "kernel.percpu.cpu.idle",
#define SYS     1
        "kernel.percpu.cpu.sys",
#define USER    2
        "kernel.percpu.cpu.user",
#define NCPU    3
        "hinv.ncpu",

};
.in
.fi
.ft 1
.PP
Using the code generated by
.BR pmgenmap ,
we are now able to easily obtain metrics from the Performance Metrics Collection
Subsystem (PMCS) as follows:

.PP
.ft CW
.nf
.in +0.5i
#define MAX_PMID 4

    int         trip = 0;
    int         numpmid = sizeof(mystats)/sizeof(mystats[0]);
    double      duration;
    pmResult    *resp;
    pmResult    *prev;
    pmID        pmidlist[MAX_PMID];

    pmNewContext(PM_CONTEXT_HOST, "localhost");
    pmLookupName(numpmid, mystats, pmidlist);
    pmFetch(numpmid, pmidlist, &resp);

    printf("%d CPUs: %d usr   %d sys   %d   idle\n", 
           resp->vset[NCPU]->vlist[0].value.lval,
           resp->vset[USER]->vlist[0].value.lval,
           resp->vset[SYS]->vlist[0].value.lval,
           resp->vset[IDLE]->vlist[0].value.lval);
.in
.fi
.ft 1
.PP
Some calls to ensure portability have been removed from the code above for the
sake of clarity \- the example above should not be used as a template for
programming.  In particular, the raw values of the metrics were used when
.BR pmLookupDesc (3)
should have been called to determine the semantics of each metric.
.PP
More complete examples that demonstrate the use of
.B pmgenmap
which may be used as a basis for program development are included in the
PCP demos, e.g.
.IR $PCP_DEMOS_DIR/pmclient .
.SH FILES
.PD 0
.TP 10
.BI $PCP_VAR_DIR/pmns/ *
default PMNS specification files
.PD
.SH "PCP ENVIRONMENT"
Environment variables with the prefix
.B PCP_
are used to parameterize the file and directory names
used by PCP.
On each installation, the file
.I /etc/pcp.conf
contains the local values for these variables.
The
.B $PCP_CONF
variable may be used to specify an alternative
configuration file,
as described in
.BR pcp.conf (5).
.SH SEE ALSO
.BR cpp (1),
.BR PMAPI (3),
.BR pmFetch (3),
.BR pmLookupName (3),
.BR pmNewContext (3),
.BR pcp.conf (5),
.BR pcp.env (5)
and
.BR pmns (5).