docs: describe the pmdaroot process interfaces
[pcp.git] / src / collectl2pcp / pmdesc.c
blob8bef208c5412d69543bb7f3eedb5e81a4d0ce4fd
1 /*
2 * Copyright (c) 2013-2015 Red Hat Inc.
3 *
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.
8 *
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
12 * for more details.
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>
20 #include <pcp/impl.h>
21 #include <pcp/pmda.h>
23 static char *semStr[] = { "0", "PM_SEM_COUNTER", "2", "PM_SEM_INSTANT", "PM_SEM_DISCRETE" };
25 static char *
26 indomStr(int indom)
28 static char buf[16];
30 if (indom == PM_INDOM_NULL)
31 strcpy(buf, "PM_INDOM_NULL");
32 else
33 sprintf(buf, "0x%04x", indom);
35 return buf;
38 int
39 main(int argc, char *argv[])
41 int ctx;
42 int sts;
43 char buf[1024];
44 char *name = buf;
45 char *p;
46 pmID pmid;
47 pmDesc desc;
49 if (isatty(fileno(stdin))) {
50 fprintf(stderr,
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"
54 " typedef struct {\n"
55 " char *name;\n"
56 " pmDesc desc;\n"
57 " } metric_t;\n"
58 "\n"
59 " extern metric_t metrics[];\n");
60 exit(1);
63 ctx = pmNewContext(PM_CONTEXT_HOST, "local:");
64 if (ctx < 0) {
65 fprintf(stderr, "Error: pmNewContext %s\n", pmErrStr(ctx));
66 exit(1);
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)
75 *p = '\0';
77 if ((sts = pmLookupName(1, &name, &pmid)) < 0) {
78 fprintf(stderr, "Error: pmLookupName \"%s\": %s\n", name, pmErrStr(sts));
79 exit(1);
82 if ((sts = pmLookupDesc(pmid, &desc)) < 0) {
83 fprintf(stderr, "Error: pmLookupDesc \"%s\": %s\n", name, pmErrStr(sts));
84 exit(1);
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");
97 exit(0);