2 * Copyright (c) 2013-2015 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * Lookup up the metrics named on stdin and generate pmDesc descriptors.
16 * Mark Goodwin <mgoodwin@redhat.com> May 2013.
19 #include <pcp/pmapi.h>
23 static char *semStr
[] = { "0", "PM_SEM_COUNTER", "2", "PM_SEM_INSTANT", "PM_SEM_DISCRETE" };
30 if (indom
== PM_INDOM_NULL
)
31 strcpy(buf
, "PM_INDOM_NULL");
33 sprintf(buf
, "0x%04x", indom
);
39 main(int argc
, char *argv
[])
49 if (isatty(fileno(stdin
))) {
51 "Usage: pminfo metric ... | pmdesc\n\n"
52 "Reads metric names on stdin and prints a descriptor for each in a table.\n"
53 "The metric descriptor table should be defined in \"./metrics.h\" as follows :\n"
59 " extern metric_t metrics[];\n");
63 ctx
= pmNewContext(PM_CONTEXT_HOST
, "local:");
65 fprintf(stderr
, "Error: pmNewContext %s\n", pmErrStr(ctx
));
69 printf("/* This file is automatically generated .. do not edit! */\n");
70 printf("#include \"metrics.h\"\n\n");
72 printf("metric_t metrics[] = {\n");
73 while (fgets(buf
, sizeof(buf
), stdin
)) {
74 if ((p
= strrchr(buf
, '\n')) != NULL
)
77 if ((sts
= pmLookupName(1, &name
, &pmid
)) < 0) {
78 fprintf(stderr
, "Error: pmLookupName \"%s\": %s\n", name
, pmErrStr(sts
));
82 if ((sts
= pmLookupDesc(pmid
, &desc
)) < 0) {
83 fprintf(stderr
, "Error: pmLookupDesc \"%s\": %s\n", name
, pmErrStr(sts
));
87 printf(" /* %-8s */ { \"%s\", { 0x%04x, PM_TYPE_%s, %s, %s,\n"
88 " { .dimSpace=%d, .dimTime=%d, .dimCount=%d, "
89 ".scaleSpace=%d, .scaleTime=%d, .scaleCount=%d } } },\n",
90 pmIDStr(desc
.pmid
), name
, desc
.pmid
, pmTypeStr(desc
.type
),
91 indomStr(desc
.indom
), semStr
[desc
.sem
], desc
.units
.dimSpace
,
92 desc
.units
.dimTime
, desc
.units
.dimCount
, desc
.units
.scaleSpace
,
93 desc
.units
.scaleTime
, desc
.units
.scaleCount
);
96 printf(" { NULL }\n};\n");