qa: update 660 to generate index.html, fixing pcp-testsuite runs
[pcp.git] / qa / src / chk_metric_types.c
blob1ce3249b2bd4e3cecaa362d5e929c067667a3043
1 /*
2 * chk_metric_types - check pmResult value types match pmDesc.
4 * Copyright (c) 1995-2001 Silicon Graphics, Inc. All Rights Reserved.
5 */
7 #include <unistd.h>
8 #include <pcp/pmapi.h>
9 #include <pcp/impl.h>
11 static void checkMetric(const char *);
13 int
14 main(int argc, char **argv)
16 int c;
17 int sts;
18 int errflag = 0;
19 int type = 0;
20 int verbose = 0;
21 char *host = NULL; /* pander to gcc */
22 int mode = PM_MODE_INTERP; /* mode for archives */
23 char *configfile = NULL;
24 char *logfile = NULL;
25 pmLogLabel label; /* get hostname for archives */
26 int zflag = 0; /* for -z */
27 char *tz = NULL; /* for -Z timezone */
28 int tzh; /* initial timezone handle */
29 char local[MAXHOSTNAMELEN];
30 char *pmnsfile = PM_NS_DEFAULT;
31 int samples = -1;
32 double delta = 1.0;
33 char *endnum;
35 __pmSetProgname(argv[0]);
37 while ((c = getopt(argc, argv, "a:c:D:h:l:Ln:s:t:U:VzZ:?")) != EOF) {
38 switch (c) {
40 case 'a': /* archive name */
41 if (type != 0) {
42 fprintf(stderr, "%s: at most one of -a, -h, -L and -U allowed\n", pmProgname);
43 errflag++;
45 type = PM_CONTEXT_ARCHIVE;
46 host = optarg;
47 break;
49 case 'c': /* configfile */
50 if (configfile != NULL) {
51 fprintf(stderr, "%s: at most one -c option allowed\n", pmProgname);
52 errflag++;
54 configfile = optarg;
55 break;
57 case 'D': /* debug flag */
58 sts = __pmParseDebug(optarg);
59 if (sts < 0) {
60 fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n",
61 pmProgname, optarg);
62 errflag++;
64 else
65 pmDebug |= sts;
66 break;
68 case 'h': /* contact PMCD on this hostname */
69 if (type != 0) {
70 fprintf(stderr, "%s: at most one of -a, -h, -L and -U allowed\n", pmProgname);
71 errflag++;
73 host = optarg;
74 type = PM_CONTEXT_HOST;
75 break;
77 case 'L': /* LOCAL, no PMCD */
78 if (type != 0) {
79 fprintf(stderr, "%s: at most one of -a, -h, -L and -U allowed\n", pmProgname);
80 errflag++;
82 host = NULL;
83 type = PM_CONTEXT_LOCAL;
84 putenv("PMDA_LOCAL_PROC="); /* if proc PMDA needed */
85 putenv("PMDA_LOCAL_SAMPLE="); /* if sampledso PMDA needed */
86 break;
88 case 'l': /* logfile */
89 logfile = optarg;
90 break;
92 case 'n': /* alternative name space file */
93 pmnsfile = optarg;
94 break;
96 case 's': /* sample count */
97 samples = (int)strtol(optarg, &endnum, 10);
98 if (*endnum != '\0' || samples < 0) {
99 fprintf(stderr, "%s: -s requires numeric argument\n", pmProgname);
100 errflag++;
102 break;
104 case 't': /* delta seconds (double) */
105 delta = strtod(optarg, &endnum);
106 if (*endnum != '\0' || delta <= 0.0) {
107 fprintf(stderr, "%s: -t requires floating point argument\n", pmProgname);
108 errflag++;
110 break;
112 case 'U': /* uninterpolated archive log */
113 if (type != 0) {
114 fprintf(stderr, "%s: at most one of -a, -h, -L and -U allowed\n", pmProgname);
115 errflag++;
117 type = PM_CONTEXT_ARCHIVE;
118 mode = PM_MODE_FORW;
119 host = optarg;
120 break;
122 case 'V': /* verbose */
123 verbose++;
124 break;
126 case 'z': /* timezone from host */
127 if (tz != NULL) {
128 fprintf(stderr, "%s: at most one of -Z and/or -z allowed\n", pmProgname);
129 errflag++;
131 zflag++;
132 break;
134 case 'Z': /* $TZ timezone */
135 if (zflag) {
136 fprintf(stderr, "%s: at most one of -Z and/or -z allowed\n", pmProgname);
137 errflag++;
139 tz = optarg;
140 break;
142 case '?':
143 default:
144 errflag++;
145 break;
149 if (zflag && type == 0) {
150 fprintf(stderr, "%s: -z requires an explicit -a, -h or -U option\n", pmProgname);
151 errflag++;
154 if (errflag) {
155 fprintf(stderr,
156 "Usage: %s options ...\n\
158 Options\n\
159 -a archive metrics source is an archive log\n\
160 -c configfile file to load configuration from\n\
161 -D debug standard PCP debug flag\n\
162 -h host metrics source is PMCD on host\n\
163 -l logfile redirect diagnostics and trace output\n\
164 -L use local context instead of PMCD\n\
165 -n pmnsfile use an alternative PMNS\n\
166 -s samples terminate after this many iterations\n\
167 -t delta sample interval in seconds(float) [default 1.0]\n\
168 -U archive metrics source is an uninterpolated archive log\n\
169 -V verbose/diagnostic output\n\
170 -z set reporting timezone to local time for host from -a, -h or -U\n\
171 -Z timezone set reporting timezone\n",
172 pmProgname);
173 exit(1);
176 if (logfile != NULL) {
177 __pmOpenLog(pmProgname, logfile, stderr, &sts);
178 if (sts < 0) {
179 fprintf(stderr, "%s: Could not open logfile \"%s\"\n", pmProgname, logfile);
183 if (pmnsfile != PM_NS_DEFAULT && (sts = pmLoadASCIINameSpace(pmnsfile, 1)) < 0) {
184 printf("%s: Cannot load namespace from \"%s\": %s\n", pmProgname,
185 pmnsfile, pmErrStr(sts));
186 exit(1);
189 if (type == 0) {
190 type = PM_CONTEXT_HOST;
191 gethostname(local, sizeof(local));
192 host = local;
194 if ((sts = pmNewContext(type, host)) < 0) {
195 if (type == PM_CONTEXT_HOST)
196 fprintf(stderr, "%s: Cannot connect to PMCD on host \"%s\": %s\n",
197 pmProgname, host, pmErrStr(sts));
198 else
199 fprintf(stderr, "%s: Cannot open archive \"%s\": %s\n",
200 pmProgname, host, pmErrStr(sts));
201 exit(1);
204 if (type == PM_CONTEXT_ARCHIVE) {
205 if ((sts = pmGetArchiveLabel(&label)) < 0) {
206 fprintf(stderr, "%s: Cannot get archive label record: %s\n",
207 pmProgname, pmErrStr(sts));
208 exit(1);
210 if (mode != PM_MODE_INTERP) {
211 if ((sts = pmSetMode(mode, &label.ll_start, 0)) < 0) {
212 fprintf(stderr, "%s: pmSetMode: %s\n", pmProgname, pmErrStr(sts));
213 exit(1);
219 if (zflag) {
220 if ((tzh = pmNewContextZone()) < 0) {
221 fprintf(stderr, "%s: Cannot set context timezone: %s\n",
222 pmProgname, pmErrStr(tzh));
223 exit(1);
225 if (type == PM_CONTEXT_ARCHIVE)
226 printf("Note: timezone set to local timezone of host \"%s\" from archive\n\n",
227 label.ll_hostname);
228 else
229 printf("Note: timezone set to local timezone of host \"%s\"\n\n", host);
231 else if (tz != NULL) {
232 if ((tzh = pmNewZone(tz)) < 0) {
233 fprintf(stderr, "%s: Cannot set timezone to \"%s\": %s\n",
234 pmProgname, tz, pmErrStr(tzh));
235 exit(1);
237 printf("Note: timezone set to \"TZ=%s\"\n\n", tz);
239 else
240 tzh = pmNewContextZone();
242 /* non-flag args are argv[optind] ... argv[argc-1] */
243 if (optind == argc) {
244 if ((sts = pmTraversePMNS(NULL, checkMetric)) < 0) {
245 fprintf(stderr, "%s: pmTraversePMNS: %s\n", pmProgname, pmErrStr(sts));
246 exit(1);
249 else
250 while (optind < argc) {
251 if ((sts = pmTraversePMNS(argv[optind], checkMetric)) < 0) {
252 fprintf(stderr, "%s: pmTraversePMNS: %s\n", pmProgname, pmErrStr(sts));
253 exit(1);
255 optind++;
258 return 0;
261 void
262 checkMetric(const char *metric)
264 int sts;
265 int i;
266 char *nameList[] = { NULL };
267 pmID pmidList[] = { PM_IN_NULL };
268 pmDesc desc;
269 pmResult *result;
271 /* pmLookupName will not modify this string */
272 nameList[0] = (char *)metric;
274 if ((sts = pmLookupName(1, nameList, pmidList)) < 0) {
275 fprintf(stderr, "%s: pmLookupName: %s\n", pmProgname, pmErrStr(sts));
276 exit(1);
279 if ((sts = pmLookupDesc(pmidList[0], &desc)) < 0) {
280 fprintf(stderr, "%s: pmLookupDesc: %s\n", pmProgname, pmErrStr(sts));
281 exit(1);
284 if (desc.type == PM_TYPE_NOSUPPORT)
285 return;
287 if ((sts = pmFetch(1, pmidList, &result)) < 0) {
288 fprintf(stderr, "%s: pmfetch: %s\n", pmProgname, pmErrStr(sts));
289 exit(1);
292 if (result->numpmid > 0) {
293 for (i=0; i < result->vset[0]->numval; i++) {
294 if (result->vset[0]->valfmt != PM_VAL_INSITU) {
295 pmValue *val = &result->vset[0]->vlist[i];
296 if (val->value.pval->vtype == PM_TYPE_UNKNOWN) {
297 printf("metric \"%s\" vtype for instance %d is PM_TYPE_UNKNOWN\n",
298 metric, val->inst);
300 else
301 if (val->value.pval->vtype != desc.type) {
302 printf("metric \"%s\" vtype for instance %d, type (%s)",
303 metric, val->inst, pmTypeStr(val->value.pval->vtype));
304 printf(" does not match descriptor (%s)\n", pmTypeStr(desc.type));
312 pmFreeResult(result);