int QmcGroup::setArchiveMode(int mode, const struct timeval *when, int interval) { int sts, result = 0; for (unsigned int i = 0; i < numContexts(); i++) { if (my.contexts[i]->source().type() != PM_CONTEXT_ARCHIVE) continue; sts = pmUseContext(my.contexts[i]->handle()); if (sts < 0) { pmprintf("%s: Error: Unable to switch to context for %s: %s\n", pmProgname, my.contexts[i]->source().sourceAscii(), pmErrStr(sts)); result = sts; continue; } sts = pmSetMode(mode, when, interval); if (sts < 0) { pmprintf("%s: Error: Unable to set context mode for %s: %s\n", pmProgname, my.contexts[i]->source().sourceAscii(), pmErrStr(sts)); result = sts; } } sts = useContext(); if (sts < 0) result = sts; return result; }
int fetch_metrics(const char *purpose, int nmetrics, pmID *pmids, pmResult **result) { int sts; pmSetMode(fetchmode, &curtime, fetchstep); if ((sts = pmFetch(nmetrics, pmids, result)) < 0) { if (sts != PM_ERR_EOL) fprintf(stderr, "%s: %s query: %s\n", pmProgname, purpose, pmErrStr(sts)); cleanstop(1); } if (pmDebug & DBG_TRACE_APPL1) { pmResult *rp = *result; struct tm tmp; time_t sec; sec = (time_t)rp->timestamp.tv_sec; pmLocaltime(&sec, &tmp); fprintf(stderr, "%s: got %d %s metrics @%02d:%02d:%02d.%03d\n", pmProgname, rp->numpmid, purpose, tmp.tm_hour, tmp.tm_min, tmp.tm_sec, (int)(rp->timestamp.tv_usec / 1000)); } return sts; }
/* * Set the origin position and interval for PMAPI context fetching */ static int setup_origin(pmOptions *opts) { int sts = 0; curtime = origin = opts->origin; /* initial archive mode, position and delta */ if (opts->context == PM_CONTEXT_ARCHIVE) { if (opts->interval.tv_sec || opts->interval.tv_usec) interval = opts->interval; setup_step_mode(); if ((sts = pmSetMode(fetchmode, &curtime, fetchstep)) < 0) { pmprintf( "%s: pmSetMode failure: %s\n", pmProgname, pmErrStr(sts)); opts->flags |= PM_OPTFLAG_RUNTIME_ERR; opts->errors++; } } return sts; }
int main(int argc, char *argv[]) { int c; int sts; char *rawfile = NULL; int i; int ctxid; int first = 1; int dflag = 0; int iflag = 0; int Lflag = 0; int lflag = 0; int Mflag = 0; int mflag = 0; int tflag = 0; int vflag = 0; int mode = PM_MODE_FORW; __pmContext *ctxp; pmResult *raw_result; pmResult *skel_result = NULL; pmResult *result; struct timeval done; while ((c = pmGetOptions(argc, argv, &opts)) != EOF) { switch (c) { case 'a': /* dump everything */ dflag = iflag = lflag = mflag = sflag = tflag = 1; break; case 'd': /* dump pmDesc structures */ dflag = 1; break; case 'i': /* dump instance domains */ iflag = 1; break; case 'L': /* dump label, verbose */ Lflag = 1; lflag = 1; break; case 'l': /* dump label */ lflag = 1; break; case 'm': /* dump metrics in log */ mflag = 1; break; case 'M': /* report <mark> records */ Mflag = 1; break; case 'r': /* read log in reverse chornological order */ mode = PM_MODE_BACK; break; case 's': /* report data size in log */ sflag = 1; break; case 't': /* dump temporal index */ tflag = 1; break; case 'v': /* verbose, dump in raw format */ vflag = 1; rawfile = opts.optarg; break; case 'x': /* report Ddd Mmm DD <timestamp> YYYY */ /* -xx reports numeric timeval also */ xflag++; break; } } if (opts.errors || (vflag && opts.optind != argc) || (!vflag && opts.optind > argc - 1 && !opts.narchives)) { pmUsageMessage(&opts); exit(1); } if (vflag) { FILE *f; if ((f = fopen(rawfile, "r")) == NULL) { fprintf(stderr, "%s: Cannot open \"%s\": %s\n", pmProgname, rawfile, osstrerror()); exit(1); } printf("Raw dump of physical archive file \"%s\" ...\n", rawfile); rawdump(f); exit(0); } if (dflag + iflag + lflag + mflag + tflag == 0) mflag = 1; /* default */ /* delay option end processing until now that we have the archive name */ if (opts.narchives == 0) __pmAddOptArchive(&opts, argv[opts.optind++]); opts.flags &= ~PM_OPTFLAG_DONE; __pmEndOptions(&opts); if ((sts = ctxid = pmNewContext(PM_CONTEXT_ARCHIVE, opts.archives[0])) < 0) { fprintf(stderr, "%s: Cannot open archive \"%s\": %s\n", pmProgname, opts.archives[0], pmErrStr(sts)); exit(1); } /* complete TZ and time window option (origin) setup */ if (pmGetContextOptions(ctxid, &opts)) { pmflush(); exit(1); } numpmid = argc - opts.optind; if (numpmid) { numpmid = 0; pmid = NULL; for (i = 0; opts.optind < argc; i++, opts.optind++) { numpmid++; pmid = (pmID *)realloc(pmid, numpmid * sizeof(pmID)); if ((sts = pmLookupName(1, &argv[opts.optind], &pmid[numpmid-1])) < 0) { if (sts == PM_ERR_NONLEAF) { numpmid--; if ((sts = pmTraversePMNS(argv[opts.optind], dometric)) < 0) fprintf(stderr, "%s: pmTraversePMNS(%s): %s\n", pmProgname, argv[opts.optind], pmErrStr(sts)); } else fprintf(stderr, "%s: pmLookupName(%s): %s\n", pmProgname, argv[opts.optind], pmErrStr(sts)); if (sts < 0) numpmid--; } } if (numpmid == 0) { fprintf(stderr, "No metric names can be translated, dump abandoned\n"); exit(1); } } if ((sts = pmGetArchiveLabel(&label)) < 0) { fprintf(stderr, "%s: Cannot get archive label record: %s\n", pmProgname, pmErrStr(sts)); exit(1); } if (numpmid > 0) { /* * setup dummy pmResult */ skel_result = (pmResult *)malloc(sizeof(pmResult)+(numpmid-1)*sizeof(pmValueSet *)); if (skel_result == NULL) { fprintf(stderr, "%s: malloc(skel_result): %s\n", pmProgname, osstrerror()); exit(1); } } /* * Note: ctxp->c_lock remains locked throughout ... __pmHandleToPtr() * is only called once, and a single context is used throughout * ... so there is no PM_UNLOCK(ctxp->c_lock) anywhere in the * pmdumplog code. * This works because ctxp->c_lock is a recursive lock and * pmdumplog is single-threaded. */ if ((ctxp = __pmHandleToPtr(ctxid)) == NULL) { fprintf(stderr, "%s: botch: __pmHandleToPtr(%d) returns NULL!\n", pmProgname, ctxid); exit(1); } pmSetMode(mode, &opts.start, 0); if (lflag) dumpLabel(Lflag); if (dflag) dumpDesc(ctxp); if (iflag) dumpInDom(ctxp); if (tflag) dumpTI(ctxp); if (mflag) { if (mode == PM_MODE_FORW) { if (opts.start_optarg != NULL || opts.finish_optarg != NULL) { /* -S or -T */ sts = pmSetMode(mode, &opts.start, 0); done = opts.finish; } else { /* read the whole archive */ done.tv_sec = 0; done.tv_usec = 0; sts = pmSetMode(mode, &done, 0); done.tv_sec = INT_MAX; } } else { if (opts.start_optarg != NULL || opts.finish_optarg != NULL) { /* -S or -T */ done.tv_sec = INT_MAX; done.tv_usec = 0; sts = pmSetMode(mode, &done, 0); done = opts.start; } else { /* read the whole archive backwards */ done.tv_sec = INT_MAX; done.tv_usec = 0; sts = pmSetMode(mode, &done, 0); done.tv_sec = 0; } } if (sts < 0) { fprintf(stderr, "%s: pmSetMode: %s\n", pmProgname, pmErrStr(sts)); exit(1); } sts = 0; for ( ; ; ) { sts = __pmLogFetch(ctxp, 0, NULL, &raw_result); if (sts < 0) break; if (numpmid == 0 || (raw_result->numpmid == 0 && Mflag)) { /* * want 'em all or <mark> record ... */ result = raw_result; } else if (numpmid > 0) { /* * cherry pick from raw_result if pmid matches one * of interest */ int picked = 0; int j; skel_result->timestamp = raw_result->timestamp; for (j = 0; j < numpmid; j++) skel_result->vset[j] = NULL; for (i = 0; i < raw_result->numpmid; i++) { for (j = 0; j < numpmid; j++) { if (pmid[j] == raw_result->vset[i]->pmid) { skel_result->vset[j] = raw_result->vset[i]; picked++; break; } } } if (picked == 0) { /* no metrics of interest, skip this record */ pmFreeResult(raw_result); continue; } skel_result->numpmid = picked; if (picked != numpmid) { /* did not find 'em all ... shuffle time */ int j; i = 0; for (j = 0; j < numpmid; j++) { if (skel_result->vset[j] != NULL) skel_result->vset[i++] = skel_result->vset[j]; } } result = skel_result; } else { /* not interesting */ pmFreeResult(raw_result); continue; } if (first && mode == PM_MODE_BACK) { first = 0; printf("\nLog finished at %24.24s - dump in reverse order\n", pmCtime(&result->timestamp.tv_sec, timebuf)); } if ((mode == PM_MODE_FORW && tvcmp(result->timestamp, done) > 0) || (mode == PM_MODE_BACK && tvcmp(result->timestamp, done) < 0)) { sts = PM_ERR_EOL; break; } putchar('\n'); dump_result(result); pmFreeResult(raw_result); } if (sts != PM_ERR_EOL) { fprintf(stderr, "%s: pmFetch: %s\n", pmProgname, pmErrStr(sts)); exit(1); } } exit(0); }
int main(int argc, char **argv) { int sts; char *msg; pmResult *irp; /* input pmResult */ pmResult *orp; /* output pmResult */ __pmPDU *pb; /* pdu buffer */ struct timeval unused; unsigned long peek_offset; /* process cmd line args */ if (parseargs(argc, argv) < 0) { pmUsageMessage(&opts); exit(1); } /* input archive name is argv[opts.optind] */ /* output archive name is argv[argc-1]) */ /* output archive */ oname = argv[argc-1]; /* input archive */ iname = argv[opts.optind]; /* * This is the interp mode context */ if ((ictx_a = pmNewContext(PM_CONTEXT_ARCHIVE, iname)) < 0) { fprintf(stderr, "%s: Error: cannot open archive \"%s\" (ctx_a): %s\n", pmProgname, iname, pmErrStr(ictx_a)); exit(1); } if ((sts = pmGetArchiveLabel(&ilabel)) < 0) { fprintf(stderr, "%s: Error: cannot get archive label record (%s): %s\n", pmProgname, iname, pmErrStr(sts)); exit(1); } /* start time */ logstart_tval.tv_sec = ilabel.ll_start.tv_sec; logstart_tval.tv_usec = ilabel.ll_start.tv_usec; /* end time */ if ((sts = pmGetArchiveEnd(&logend_tval)) < 0) { fprintf(stderr, "%s: Error: cannot get end of archive (%s): %s\n", pmProgname, iname, pmErrStr(sts)); exit(1); } if (zarg) { /* use TZ from metrics source (input-archive) */ if ((sts = pmNewZone(ilabel.ll_tz)) < 0) { fprintf(stderr, "%s: Cannot set context timezone: %s\n", pmProgname, pmErrStr(sts)); exit(1); } printf("Note: timezone set to local timezone of host \"%s\" from archive\n\n", ilabel.ll_hostname); } else if (tz != NULL) { /* use TZ as specified by user */ if ((sts = pmNewZone(tz)) < 0) { fprintf(stderr, "%s: Cannot set timezone to \"%s\": %s\n", pmProgname, tz, pmErrStr(sts)); exit(1); } printf("Note: timezone set to \"TZ=%s\"\n\n", tz); } else { char *tz; tz = __pmTimezone(); /* use TZ from local host */ if ((sts = pmNewZone(tz)) < 0) { fprintf(stderr, "%s: Cannot set local host's timezone: %s\n", pmProgname, pmErrStr(sts)); exit(1); } } /* set winstart and winend timevals */ sts = pmParseTimeWindow(Sarg, Targ, Aarg, Oarg, &logstart_tval, &logend_tval, &winstart_tval, &winend_tval, &unused, &msg); if (sts < 0) { fprintf(stderr, "%s: Invalid time window specified: %s\n", pmProgname, msg); exit(1); } #if PCP_DEBUG if (pmDebug & DBG_TRACE_APPL0) { char buf[26]; pmCtime((const time_t *)&winstart_tval.tv_sec, buf); fprintf(stderr, "Start time: %s", buf); pmCtime((const time_t *)&winend_tval.tv_sec, buf); fprintf(stderr, "End time: %s", buf); } #endif if ((sts = pmSetMode(PM_MODE_INTERP | PM_XTB_SET(PM_TIME_SEC), &winstart_tval, (int)targ)) < 0) { fprintf(stderr, "%s: pmSetMode(PM_MODE_INTERP ...) failed: %s\n", pmProgname, pmErrStr(sts)); exit(1); } /* create output log - must be done before writing label */ if ((sts = __pmLogCreate("", oname, PM_LOG_VERS02, &logctl)) < 0) { fprintf(stderr, "%s: Error: __pmLogCreate: %s\n", pmProgname, pmErrStr(sts)); exit(1); } /* This must be done after log is created: * - checks that archive version, host, and timezone are ok * - set archive version, host, and timezone of output archive * - set start time * - write labels */ newlabel(); current.tv_sec = logctl.l_label.ill_start.tv_sec = winstart_tval.tv_sec; current.tv_usec = logctl.l_label.ill_start.tv_usec = winstart_tval.tv_usec; /* write label record */ writelabel(); /* * Supress any automatic label creation in libpcp at the first * pmResult write. */ logctl.l_state = PM_LOG_STATE_INIT; /* * Traverse the PMNS to get all the metrics and their metadata */ if ((sts = pmTraversePMNS ("", dometric)) < 0) { fprintf(stderr, "%s: Error traversing namespace ... %s\n", pmProgname, pmErrStr(sts)); goto cleanup; } /* * All the initial metadata has been generated, add timestamp */ fflush(logctl.l_mdfp); __pmLogPutIndex(&logctl, ¤t); written = 0; /* * main loop */ while (sarg == -1 || written < sarg) { /* * do stuff */ if ((sts = pmUseContext(ictx_a)) < 0) { fprintf(stderr, "%s: Error: cannot use context (%s): %s\n", pmProgname, iname, pmErrStr(sts)); goto cleanup; } if ((sts = pmFetch(numpmid, pmidlist, &irp)) < 0) { if (sts == PM_ERR_EOL) break; fprintf(stderr, "%s: Error: pmFetch failed: %s\n", pmProgname, pmErrStr(sts)); exit(1); } if (irp->timestamp.tv_sec > winend_tval.tv_sec || (irp->timestamp.tv_sec == winend_tval.tv_sec && irp->timestamp.tv_usec > winend_tval.tv_usec)) { /* past end time as per -T */ break; } #if PCP_DEBUG if (pmDebug & DBG_TRACE_APPL2) { fprintf(stderr, "input record ...\n"); __pmDumpResult(stderr, irp); } #endif /* * traverse the interval, looking at every archive record ... * we are particularly interested in: * - metric-values that are interpolated but not present in * this interval * - counter wraps * - mark records */ doscan(&irp->timestamp); if ((sts = pmUseContext(ictx_a)) < 0) { fprintf(stderr, "%s: Error: cannot use context (%s): %s\n", pmProgname, iname, pmErrStr(sts)); goto cleanup; } orp = rewrite(irp); #if PCP_DEBUG if (pmDebug & DBG_TRACE_APPL2) { if (orp == NULL) fprintf(stderr, "output record ... none!\n"); else { fprintf(stderr, "output record ...\n"); __pmDumpResult(stderr, orp); } } #endif if (orp == NULL) goto next; /* * convert log record to a PDU, and enforce V2 encoding semantics, * then write it out */ sts = __pmEncodeResult(PDU_OVERRIDE2, orp, &pb); if (sts < 0) { fprintf(stderr, "%s: Error: __pmEncodeResult: %s\n", pmProgname, pmErrStr(sts)); goto cleanup; } /* switch volumes if required */ if (varg > 0) { if (written > 0 && (written % varg) == 0) { __pmTimeval next_stamp; next_stamp.tv_sec = irp->timestamp.tv_sec; next_stamp.tv_usec = irp->timestamp.tv_usec; newvolume(oname, &next_stamp); } } /* * Even without a -v option, we may need to switch volumes * if the data file exceeds 2^31-1 bytes */ peek_offset = ftell(logctl.l_mfp); peek_offset += ((__pmPDUHdr *)pb)->len - sizeof(__pmPDUHdr) + 2*sizeof(int); if (peek_offset > 0x7fffffff) { __pmTimeval next_stamp; next_stamp.tv_sec = irp->timestamp.tv_sec; next_stamp.tv_usec = irp->timestamp.tv_usec; newvolume(oname, &next_stamp); } current.tv_sec = orp->timestamp.tv_sec; current.tv_usec = orp->timestamp.tv_usec; doindom(orp); /* write out log record */ sts = __pmLogPutResult2(&logctl, pb); __pmUnpinPDUBuf(pb); if (sts < 0) { fprintf(stderr, "%s: Error: __pmLogPutResult2: log data: %s\n", pmProgname, pmErrStr(sts)); goto cleanup; } written++; rewrite_free(); next: pmFreeResult(irp); } /* write the last time stamp */ fflush(logctl.l_mfp); fflush(logctl.l_mdfp); __pmLogPutIndex(&logctl, ¤t); exit(exit_status); cleanup: { char fname[MAXNAMELEN]; fprintf(stderr, "Archive \"%s\" not created.\n", oname); snprintf(fname, sizeof(fname), "%s.0", oname); unlink(fname); snprintf(fname, sizeof(fname), "%s.meta", oname); unlink(fname); snprintf(fname, sizeof(fname), "%s.index", oname); unlink(fname); exit(1); } }
int main(int argc, char **argv) { int c; int sts; int samples; int pauseFlag = 0; int lines = 0; char *source; const char *host; info_t info; /* values to report each sample */ char timebuf[26]; /* for pmCtime result */ setlinebuf(stdout); while ((c = pmGetOptions(argc, argv, &opts)) != EOF) { switch (c) { case 'P': pauseFlag++; break; default: opts.errors++; break; } } if (pauseFlag && opts.context != PM_CONTEXT_ARCHIVE) { pmprintf("%s: pause can only be used with archives\n", pmProgname); opts.errors++; } if (opts.errors || opts.optind < argc - 1) { pmUsageMessage(&opts); exit(1); } if (opts.context == PM_CONTEXT_ARCHIVE) { source = opts.archives[0]; } else if (opts.context == PM_CONTEXT_HOST) { source = opts.hosts[0]; } else { opts.context = PM_CONTEXT_HOST; source = "local:"; } if ((sts = c = pmNewContext(opts.context, source)) < 0) { if (opts.context == PM_CONTEXT_HOST) fprintf(stderr, "%s: Cannot connect to PMCD on host \"%s\": %s\n", pmProgname, source, pmErrStr(sts)); else fprintf(stderr, "%s: Cannot open archive \"%s\": %s\n", pmProgname, source, pmErrStr(sts)); exit(1); } /* complete TZ and time window option (origin) setup */ if (pmGetContextOptions(c, &opts)) { pmflush(); exit(1); } host = pmGetContextHostName(c); ncpu = get_ncpu(); if ((opts.context == PM_CONTEXT_ARCHIVE) && (opts.start.tv_sec != 0 || opts.start.tv_usec != 0)) { if ((sts = pmSetMode(PM_MODE_FORW, &opts.start, 0)) < 0) { fprintf(stderr, "%s: pmSetMode failed: %s\n", pmProgname, pmErrStr(sts)); exit(1); } } get_sample(&info); /* set a default sampling interval if none has been requested */ if (opts.interval.tv_sec == 0 && opts.interval.tv_usec == 0) opts.interval.tv_sec = 5; /* set sampling loop termination via the command line options */ samples = opts.samples ? opts.samples : -1; while (samples == -1 || samples-- > 0) { if (lines % 15 == 0) { if (opts.context == PM_CONTEXT_ARCHIVE) printf("Archive: %s, ", opts.archives[0]); printf("Host: %s, %d cpu(s), %s", host, ncpu, pmCtime((const time_t *)&info.timestamp.tv_sec, timebuf)); /* - report format CPU Busy Busy Free Mem Disk Load Average Util CPU Util (Mbytes) IOPS 1 Min 15 Min X.XXX XXX X.XXX XXXXX.XXX XXXXXX XXXX.XX XXXX.XX */ printf(" CPU"); if (ncpu > 1) printf(" Busy Busy"); printf(" Free Mem Disk Load Average\n"); printf(" Util"); if (ncpu > 1) printf(" CPU Util"); printf(" (Mbytes) IOPS 1 Min 15 Min\n"); } if (opts.context != PM_CONTEXT_ARCHIVE || pauseFlag) __pmtimevalSleep(opts.interval); get_sample(&info); printf("%5.2f", info.cpu_util); if (ncpu > 1) printf(" %3d %5.2f", info.peak_cpu, info.peak_cpu_util); printf(" %9.3f", info.freemem); printf(" %6d", info.dkiops); printf(" %7.2f %7.2f\n", info.load1, info.load15); lines++; } exit(0); }
int main(int argc, char **argv) { int c; int sts; int e_sts = 0; int errflag = 0; int ahtype = 0; int verbose = 0; int quick = 0; char *host = NULL; /* pander to gcc */ pmResult *result; pmResult *prev = NULL; struct timeval start = { 0,0 }; struct timeval end; int tzh; off_t trunc_size = 0; __pmSetProgname(argv[0]); while ((c = getopt(argc, argv, "a:D:t:qv?")) != EOF) { switch (c) { case 'a': /* archive name */ if (ahtype != 0) { fprintf(stderr, "%s: at most one of -a and/or -h allowed\n", pmProgname); errflag++; } ahtype = PM_CONTEXT_ARCHIVE; host = optarg; break; #ifdef PCP_DEBUG case 'D': /* debug flag */ sts = __pmParseDebug(optarg); if (sts < 0) { fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n", pmProgname, optarg); errflag++; } else pmDebug |= sts; break; #endif case 't': /* truncate */ trunc_size = atol(optarg); break; case 'q': /* quick */ quick = 1; break; case 'v': /* verbose */ verbose++; break; case '?': default: errflag++; break; } } if (errflag || optind < argc) { fprintf(stderr, "Usage: %s options ...\n\ \n\ Options\n\ -a archive metrics source is an archive log\n\ -t size truncate archive to size bytes\n\ -q quick (read last 3 records, not the whole archive)\n\ -v verbose\n", pmProgname); exit(1); } if (ahtype != PM_CONTEXT_ARCHIVE) { fprintf(stderr, "%s: -a is not optional!\n", pmProgname); exit(1); } /* truncate if -t specified, _before_ opening archive */ if (trunc_size != 0) { if (access(host, W_OK) == 0) { if (truncate(host, trunc_size) != 0) { fprintf(stderr, "%s: file %s exists, but cannot truncate\n", pmProgname, host); exit(1); } } else { char path[MAXPATHLEN]; sprintf(path, "%s.0", host); if (access(path, W_OK) == 0) { if (truncate(path, trunc_size) != 0) { fprintf(stderr, "%s: file %s exists, but cannot truncate\n", pmProgname, path); exit(1); } } else { fprintf(stderr, "%s: cannot find writeable %s or %s\n", pmProgname, host, path); exit(1); } } } if ((sts = pmNewContext(ahtype, host)) < 0) { fprintf(stderr, "%s: Cannot open archive \"%s\": %s\n", pmProgname, host, pmErrStr(sts)); exit(1); } /* force -z (timezone of archive */ if ((tzh = pmNewContextZone()) < 0) { fprintf(stderr, "%s: Cannot set context timezone: %s\n", pmProgname, pmErrStr(tzh)); exit(1); } sts = pmGetArchiveEnd(&end); if (sts < 0) { printf("pmGetArchiveEnd: %s\n", pmErrStr(sts)); } else { if (verbose) { printf("pmGetArchiveEnd time: "); printstamp(&end); printf("\n"); } } sts = pmSetMode(PM_MODE_BACK, &end, 0); if (sts < 0) { printf("pmSetMode PM_MODE_BACK: %s\n", pmErrStr(sts)); exit(1); } sts = pmFetchArchive(&result); if (sts < 0) { printf("pmFetchArchive: %s\n", pmErrStr(sts)); e_sts = 1; } else { if (verbose) { printf("last result time (direct): "); printstamp(&result->timestamp); printf("\n"); } if (result->timestamp.tv_sec != end.tv_sec || result->timestamp.tv_usec != end.tv_usec) { printf("Mismatch: end="); printstamp(&end); printf(" direct="); printstamp(&result->timestamp); printf("\n"); e_sts = 1; } start.tv_sec = result->timestamp.tv_sec; start.tv_usec = result->timestamp.tv_usec; pmFreeResult(result); } if (quick && e_sts == 0) { int i; for (i = 0; i < 2; i++) { sts = pmFetchArchive(&result); if (sts >= 0) { start.tv_sec = result->timestamp.tv_sec; start.tv_usec = result->timestamp.tv_usec; pmFreeResult(result); } } } else { /* start from the epoch and move forward */ start.tv_sec = 0; start.tv_usec = 0; } sts = pmSetMode(PM_MODE_FORW, &start, 0); if (sts < 0) { printf("pmSetMode PM_MODE_FORW: %s\n", pmErrStr(sts)); exit(1); } while ((sts = pmFetchArchive(&result)) >= 0) { if (prev != NULL) pmFreeResult(prev); prev = result; } if (verbose) printf("pmFetchArchive: %s\n", pmErrStr(sts)); if (prev == NULL) { printf("no results!\n"); } else { if (verbose) { printf("last result time (serial): "); printstamp(&prev->timestamp); printf("\n"); } if (prev->timestamp.tv_sec != end.tv_sec || prev->timestamp.tv_usec != end.tv_usec) { printf("Mismatch: end="); printstamp(&end); printf(" serial="); printstamp(&prev->timestamp); printf("\n"); e_sts = 1; } pmFreeResult(prev); } exit(e_sts); }
int main(int argc, char **argv) { int c; int sts; int samples; int pauseFlag = 0; int lines = 0; char *source; const char *host; char timebuf[26]; /* for pmCtime result */ setlinebuf(stdout); while ((c = pmGetOptions(argc, argv, &opts)) != EOF) { switch (c) { case 'P': pauseFlag++; break; default: opts.errors++; break; } } if (pauseFlag && opts.context != PM_CONTEXT_ARCHIVE) { pmprintf("%s: pause can only be used with archives\n", pmGetProgname()); opts.errors++; } if (opts.errors || opts.optind < argc - 1) { pmUsageMessage(&opts); exit(1); } if (opts.context == PM_CONTEXT_ARCHIVE) { source = opts.archives[0]; } else if (opts.context == PM_CONTEXT_HOST) { source = opts.hosts[0]; } else { opts.context = PM_CONTEXT_HOST; source = "local:"; } sts = pmCreateFetchGroup(& pmfg, opts.context, source); if (sts < 0) { if (opts.context == PM_CONTEXT_HOST) fprintf(stderr, "%s: Cannot connect to PMCD on host \"%s\": %s\n", pmGetProgname(), source, pmErrStr(sts)); else fprintf(stderr, "%s: Cannot open archive \"%s\": %s\n", pmGetProgname(), source, pmErrStr(sts)); exit(1); } c = pmGetFetchGroupContext(pmfg); /* complete TZ and time window option (origin) setup */ if (pmGetContextOptions(c, &opts)) { pmflush(); exit(1); } host = pmGetContextHostName(c); /* set a default sampling interval if none has been requested */ if (opts.interval.tv_sec == 0 && opts.interval.tv_usec == 0) opts.interval.tv_sec = 5; if (opts.context == PM_CONTEXT_ARCHIVE) { if ((sts = pmSetMode(PM_MODE_INTERP, &opts.start, (int)(opts.interval.tv_sec*1000 + opts.interval.tv_usec/1000))) < 0) { fprintf(stderr, "%s: pmSetMode failed: %s\n", pmGetProgname(), pmErrStr(sts)); exit(1); } } if (opts.context == PM_CONTEXT_ARCHIVE) get_sample(); /* fetch the separate early ncpu record */ get_sample(); /* fetch other rate metrics */ /* set sampling loop termination via the command line options */ samples = opts.samples ? opts.samples : -1; while (samples == -1 || samples-- > 0) { if (lines % 15 == 0) { time_t now = info.timestamp.tv_sec; if (opts.context == PM_CONTEXT_ARCHIVE) printf("Archive: %s, ", opts.archives[0]); printf("Host: %s, %d cpu(s), %s", host, info.ncpu.l, pmCtime(&now, timebuf)); /* - report format CPU Busy Busy Free Mem Disk Load Average Util CPU Util (Mbytes) IOPS 1 Min 15 Min X.XXX XXX X.XXX XXXXX.XXX XXXXXX XXXX.XX XXXX.XX */ printf(" CPU"); if (info.ncpu.l > 1) printf(" Busy Busy"); printf(" Free Mem Disk Load Average\n"); printf(" Util"); if (info.ncpu.l > 1) printf(" CPU Util"); printf(" (Mbytes) IOPS 1 Min 15 Min\n"); } if (opts.context != PM_CONTEXT_ARCHIVE || pauseFlag) __pmtimevalSleep(opts.interval); get_sample(); printf("%5.2f", info.cpu_util); if (info.ncpu.l > 1) printf(" %3d %5.2f", info.peak_cpu, info.peak_cpu_util); printf(" %9.3f", info.freemem.d); printf(" %6d", info.dkiops.l); printf(" %7.2f %7.2f\n", info.load1.d, info.load15.d); lines++; } exit(0); }
int main(int argc, char **argv) { int c; int i; int sts; int errflag = 0; int type = 0; int verbose = 0; char *host = NULL; /* pander to gcc */ int mode = PM_MODE_INTERP; /* mode for archives */ char *configfile = NULL; char *start = NULL; char *finish = NULL; char *align = NULL; char *offset = NULL; char *logfile = NULL; pmLogLabel label; /* get hostname for archives */ int zflag = 0; /* for -z */ char *tz = NULL; /* for -Z timezone */ int tzh; /* initial timezone handle */ char local[MAXHOSTNAMELEN]; char *pmnsfile = PM_NS_DEFAULT; int samples = -1; double delta = 1.0; char *endnum; struct timeval startTime; struct timeval endTime; struct timeval appStart; struct timeval appEnd; struct timeval appOffset; pmSetProgname(argv[0]); while ((c = getopt(argc, argv, "a:A:c:D:h:l:Ln:O:s:S:t:T:U:VzZ:?")) != EOF) { switch (c) { case 'a': /* archive name */ if (type != 0) { fprintf(stderr, "%s: at most one of -a, -h, -L and -U allowed\n", pmGetProgname()); errflag++; } type = PM_CONTEXT_ARCHIVE; host = optarg; break; case 'A': /* time alignment */ align = optarg; break; case 'c': /* configfile */ if (configfile != NULL) { fprintf(stderr, "%s: at most one -c option allowed\n", pmGetProgname()); errflag++; } configfile = optarg; break; case 'D': /* debug options */ sts = pmSetDebug(optarg); if (sts < 0) { fprintf(stderr, "%s: unrecognized debug options specification (%s)\n", pmGetProgname(), optarg); errflag++; } break; case 'h': /* contact PMCD on this hostname */ if (type != 0) { fprintf(stderr, "%s: at most one of -a, -h, -L and -U allowed\n", pmGetProgname()); errflag++; } host = optarg; type = PM_CONTEXT_HOST; break; case 'L': /* LOCAL, no PMCD */ if (type != 0) { fprintf(stderr, "%s: at most one of -a, -h, -L and -U allowed\n", pmGetProgname()); errflag++; } host = NULL; type = PM_CONTEXT_LOCAL; putenv("PMDA_LOCAL_PROC="); /* if proc PMDA needed */ putenv("PMDA_LOCAL_SAMPLE="); /* if sampledso PMDA needed */ break; case 'l': /* logfile */ logfile = optarg; break; case 'n': /* alternative name space file */ pmnsfile = optarg; break; case 'O': /* sample offset time */ offset = optarg; break; case 's': /* sample count */ samples = (int)strtol(optarg, &endnum, 10); if (*endnum != '\0' || samples < 0) { fprintf(stderr, "%s: -s requires numeric argument\n", pmGetProgname()); errflag++; } break; case 'S': /* start time */ start = optarg; break; case 't': /* delta seconds (double) */ delta = strtod(optarg, &endnum); if (*endnum != '\0' || delta <= 0.0) { fprintf(stderr, "%s: -t requires floating point argument\n", pmGetProgname()); errflag++; } break; case 'T': /* terminate time */ finish = optarg; break; case 'U': /* uninterpolated archive log */ if (type != 0) { fprintf(stderr, "%s: at most one of -a, -h, -L and -U allowed\n", pmGetProgname()); errflag++; } type = PM_CONTEXT_ARCHIVE; mode = PM_MODE_FORW; host = optarg; break; case 'V': /* verbose */ verbose++; break; case 'z': /* timezone from host */ if (tz != NULL) { fprintf(stderr, "%s: at most one of -Z and/or -z allowed\n", pmGetProgname()); errflag++; } zflag++; break; case 'Z': /* $TZ timezone */ if (zflag) { fprintf(stderr, "%s: at most one of -Z and/or -z allowed\n", pmGetProgname()); errflag++; } tz = optarg; break; case '?': default: errflag++; break; } } if (zflag && type == 0) { fprintf(stderr, "%s: -z requires an explicit -a, -h or -U option\n", pmGetProgname()); errflag++; } if (errflag) { fprintf(stderr, "Usage: %s options ...\n\ \n\ Options\n\ -a archive metrics source is an archive log\n\ -A align time alignment\n\ -c configfile file to load configuration from\n\ -D debug standard PCP debug options\n\ -h host metrics source is PMCD on host\n\ -l logfile redirect diagnostics and trace output\n\ -L use local context instead of PMCD\n\ -n pmnsfile use an alternative PMNS\n\ -O offset offset sample time\n\ -s samples terminate after this many iterations\n\ -S start start at this time\n\ -t delta sample interval in seconds(float) [default 1.0]\n\ -T finish finish at this time\n\ -U archive metrics source is an uninterpolated archive log\n\ -V verbose/diagnostic output\n\ -z set reporting timezone to local time for host from -a, -h or -U\n\ -Z timezone set reporting timezone\n", pmGetProgname()); exit(1); } if (logfile != NULL) { pmOpenLog(pmGetProgname(), logfile, stderr, &sts); if (sts < 0) { fprintf(stderr, "%s: Could not open logfile \"%s\"\n", pmGetProgname(), logfile); } } if (pmnsfile != PM_NS_DEFAULT && (sts = pmLoadNameSpace(pmnsfile)) < 0) { printf("%s: Cannot load namespace from \"%s\": %s\n", pmGetProgname(), pmnsfile, pmErrStr(sts)); exit(1); } if (type == 0) { type = PM_CONTEXT_HOST; gethostname(local, sizeof(local)); host = local; } if ((sts = pmNewContext(type, host)) < 0) { if (type == PM_CONTEXT_HOST) fprintf(stderr, "%s: Cannot connect to PMCD on host \"%s\": %s\n", pmGetProgname(), host, pmErrStr(sts)); else fprintf(stderr, "%s: Cannot open archive \"%s\": %s\n", pmGetProgname(), host, pmErrStr(sts)); exit(1); } if (type == PM_CONTEXT_ARCHIVE) { if ((sts = pmGetArchiveLabel(&label)) < 0) { fprintf(stderr, "%s: Cannot get archive label record: %s\n", pmGetProgname(), pmErrStr(sts)); exit(1); } if (mode != PM_MODE_INTERP) { if ((sts = pmSetMode(mode, &label.ll_start, 0)) < 0) { fprintf(stderr, "%s: pmSetMode: %s\n", pmGetProgname(), pmErrStr(sts)); exit(1); } } startTime = label.ll_start; sts = pmGetArchiveEnd(&endTime); if (sts < 0) { fprintf(stderr, "%s: pmGetArchiveEnd: %s\n", pmGetProgname(), pmErrStr(sts)); exit(1); } } else { gettimeofday(&startTime, NULL); endTime.tv_sec = INT_MAX; } if (zflag) { if ((tzh = pmNewContextZone()) < 0) { fprintf(stderr, "%s: Cannot set context timezone: %s\n", pmGetProgname(), pmErrStr(tzh)); exit(1); } if (type == PM_CONTEXT_ARCHIVE) printf("Note: timezone set to local timezone of host \"%s\" from archive\n\n", label.ll_hostname); else printf("Note: timezone set to local timezone of host \"%s\"\n\n", host); } else if (tz != NULL) { if ((tzh = pmNewZone(tz)) < 0) { fprintf(stderr, "%s: Cannot set timezone to \"%s\": %s\n", pmGetProgname(), tz, pmErrStr(tzh)); exit(1); } printf("Note: timezone set to \"TZ=%s\"\n\n", tz); } else tzh = pmNewContextZone(); /* non-flag args are argv[optind] ... argv[argc-1] */ while (optind < argc) { printf("extra argument[%d]: %s\n", optind, argv[optind]); optind++; } if (align != NULL && type != PM_CONTEXT_ARCHIVE) { fprintf(stderr, "%s: -A option only supported for PCP archives, alignment request ignored\n", pmGetProgname()); align = NULL; } sts = pmParseTimeWindow(start, finish, align, offset, &startTime, &endTime, &appStart, &appEnd, &appOffset, &endnum); if (sts < 0) { fprintf(stderr, "%s: %s\n", pmGetProgname(), endnum); exit(1); } if ((sts = pmLookupName(2, namelist, pmidlist)) < 0) { fprintf(stderr, "%s: pmLookupName failed: %s\n", pmGetProgname(), pmErrStr(sts)); exit(1); } /* goto the start */ if ((sts = pmSetMode(PM_MODE_INTERP, &appStart, (int)(delta * 1000))) < 0) { fprintf(stderr, "%s: pmSetMode failed: %s\n", pmGetProgname(), pmErrStr(sts)); exit(1); } pmCtime(&appStart.tv_sec, timebuf); printf("archive %s\nstartTime: %19.19s.%06d\n", host, timebuf, (int)appStart.tv_usec); pmCtime(&appEnd.tv_sec, timebuf); printf("endTime : %19.19s.%06d\nsamples=%d delta=%dms\n", timebuf, (int)appEnd.tv_usec, samples, (int)(delta * 1000)); /* play forwards over the mark */ for (i=0; i < samples; i++) { if ((sts = pmFetch(2, pmidlist, &result)) < 0) { fprintf(stderr, "%s: pmFetch failed: %s\n", pmGetProgname(), pmErrStr(sts)); exit(1); } check_result("forwards ", result); curpos = result->timestamp; /* struct cpy */ pmFreeResult(result); } /* rewind back over the mark */ if ((sts = pmSetMode(PM_MODE_INTERP, &curpos, (int)(delta * -1000))) < 0) { fprintf(stderr, "%s: pmSetMode failed: %s\n", pmGetProgname(), pmErrStr(sts)); exit(1); } for (i=0; i < samples; i++) { if ((sts = pmFetch(2, pmidlist, &result)) < 0) { fprintf(stderr, "%s: pmFetch failed: %s\n", pmGetProgname(), pmErrStr(sts)); exit(1); } check_result("rewinding", result); pmFreeResult(result); } return 0; }
int pass3(__pmContext *ctxp, char *archname, pmOptions *opts) { struct timeval timespan; int sts; pmResult *result; struct timeval last_stamp; struct timeval delta_stamp; l_ctxp = ctxp; l_archname = archname; if (vflag) fprintf(stderr, "%s: start pass3\n", archname); if ((sts = pmSetMode(PM_MODE_FORW, &opts->start, 0)) < 0) { fprintf(stderr, "%s: pmSetMode failed: %s\n", l_archname, pmErrStr(sts)); return STS_FATAL; } /* check which timestamp print format we should be using */ timespan = opts->finish; tsub(×pan, &opts->start); if (timespan.tv_sec > 86400) /* seconds per day: 60*60*24 */ dayflag = 1; sts = 0; last_stamp = opts->start; for ( ; ; ) { /* * we need the next record with no fancy checks or record * skipping in libpcp, so use __pmLogRead() in preference * to pmFetchArchive() */ if ((sts = __pmLogRead(l_ctxp->c_archctl->ac_log, l_ctxp->c_mode, NULL, &result, PMLOGREAD_NEXT)) < 0) break; result_count++; delta_stamp = result->timestamp; tsub(&delta_stamp, &last_stamp); #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL0) { int i; int sum_val = 0; int cnt_noval = 0; int cnt_err = 0; pmValueSet *vsp; fprintf(stderr, "%s.%d:[", l_archname, l_ctxp->c_archctl->ac_vol); print_stamp(stderr, &result->timestamp); for (i = 0; i < result->numpmid; i++) { vsp = result->vset[i]; if (vsp->numval > 0) sum_val += vsp->numval; else if (vsp->numval == 0) cnt_noval++; else cnt_err++; } fprintf(stderr, "] delta(stamp)=%.3fsec", __pmtimevalToReal(&delta_stamp)); fprintf(stderr, " numpmid=%d sum(numval)=%d", result->numpmid, sum_val); if (cnt_noval > 0) fprintf(stderr, " count(numval=0)=%d", cnt_noval); if (cnt_err > 0) fprintf(stderr, " count(numval<0)=%d", cnt_err); fputc('\n', stderr); } #endif if (delta_stamp.tv_sec < 0) { /* time went backwards! */ fprintf(stderr, "%s.%d:[", l_archname, l_ctxp->c_archctl->ac_vol); print_stamp(stderr, &result->timestamp); fprintf(stderr, "]: timestamp went backwards, prior timestamp: "); print_stamp(stderr, &last_stamp); fprintf(stderr, "\n"); } last_stamp = result->timestamp; if ((opts->finish.tv_sec > result->timestamp.tv_sec) || ((opts->finish.tv_sec == result->timestamp.tv_sec) && (opts->finish.tv_usec >= result->timestamp.tv_usec))) { if (result->numpmid == 0) { /* * MARK record ... make sure wrap check is not done * at next fetch (mimic interp.c from libpcp) */ __pmHashNode *hptr; checkData *checkdata; int k; for (hptr = __pmHashWalk(&hashlist, PM_HASH_WALK_START); hptr != NULL; hptr = __pmHashWalk(&hashlist, PM_HASH_WALK_NEXT)) { checkdata = (checkData *)hptr->data; for (k = 0; k < checkdata->listsize; k++) { checkdata->instlist[k]->lasttime.tv_sec = 0; } } mark_count++; } else docheck(result); pmFreeResult(result); } else { pmFreeResult(result); sts = PM_ERR_EOL; break; } } if (sts != PM_ERR_EOL) { fprintf(stderr, "[after "); print_stamp(stderr, &last_stamp); fprintf(stderr, "]: pmFetch: error: %s\n", pmErrStr(sts)); return STS_FATAL; } return STS_OK; }
/* find Fetch bundle for Metric */ static Fetch * findFetch(Host *h, Metric *m) { Fetch *f; int sts; int i; int n; pmID pmid = m->desc.pmid; pmID *p; struct timeval tv; /* find existing Fetch bundle */ f = h->fetches; /* create new Fetch bundle */ if (! f) { f = newFetch(h); if ((f->handle = newContext(symName(h->name))) < 0) { free(f); h->down = 1; return NULL; } if (archives) { int tmp_ival; int tmp_mode = PM_MODE_INTERP; getDoubleAsXTB(&h->task->delta, &tmp_ival, &tmp_mode); __pmtimevalFromReal(start, &tv); if ((sts = pmSetMode(tmp_mode, &tv, tmp_ival)) < 0) { fprintf(stderr, "%s: pmSetMode failed: %s\n", pmProgname, pmErrStr(sts)); exit(1); } #if PCP_DEBUG if (pmDebug & DBG_TRACE_APPL1) { fprintf(stderr, "findFetch: fetch=0x%p host=0x%p delta=%.6f handle=%d\n", f, h, h->task->delta, f->handle); } #endif } f->next = NULL; f->prev = NULL; h->fetches = f; } /* look for existing pmid */ p = f->pmids; n = f->npmids; for (i = 0; i < n; i++) { if (*p == pmid) break; p++; } /* add new pmid */ if (i == n) { p = f->pmids; p = ralloc(p, (n+1) * sizeof(pmID)); p[n] = pmid; f->npmids = n + 1; f->pmids = p; } return f; }
static void report(void) { int i; int sts; pmDesc desc; pmResult *result = NULL; pmResult *xresult = NULL; pmValueSet *vsp = NULL; char *buffer; int all_count; int *all_inst; char **all_names; if (batchidx == 0) return; /* Lookup names. * Cull out names that were unsuccessfully looked up. * However, it is unlikely to fail because names come from a traverse PMNS. */ if (need_pmid) { if ((sts = pmLookupName(batchidx, namelist, pmidlist)) < 0) { int j = 0; for (i = 0; i < batchidx; i++) { if (pmidlist[i] == PM_ID_NULL) { printf("%s: pmLookupName: %s\n", namelist[i], pmErrStr(sts)); free(namelist[i]); } else { /* assert(j <= i); */ pmidlist[j] = pmidlist[i]; namelist[j] = namelist[i]; j++; } } batchidx = j; } } if (p_value || verify) { if (opts.context == PM_CONTEXT_ARCHIVE) { if ((sts = pmSetMode(PM_MODE_FORW, &opts.origin, 0)) < 0) { fprintf(stderr, "%s: pmSetMode failed: %s\n", pmProgname, pmErrStr(sts)); exit(1); } } if ((sts = pmFetch(batchidx, pmidlist, &result)) < 0) { for (i = 0; i < batchidx; i++) printf("%s: pmFetch: %s\n", namelist[i], pmErrStr(sts)); goto done; } } for (i = 0; i < batchidx; i++) { if (p_desc || p_value || verify) { if ((sts = pmLookupDesc(pmidlist[i], &desc)) < 0) { printf("%s: pmLookupDesc: %s\n", namelist[i], pmErrStr(sts)); continue; } } if (p_desc || p_help || p_value) /* Not doing verify, output separator */ putchar('\n'); if (p_value || verify) { vsp = result->vset[i]; if (p_force) { if (result->vset[i]->numval == PM_ERR_PROFILE) { /* indom is non-enumerable; try harder */ if ((all_count = pmGetInDom(desc.indom, &all_inst, &all_names)) > 0) { pmDelProfile(desc.indom, 0, NULL); pmAddProfile(desc.indom, all_count, all_inst); if (xresult != NULL) { pmFreeResult(xresult); xresult = NULL; } if (opts.context == PM_CONTEXT_ARCHIVE) { if ((sts = pmSetMode(PM_MODE_FORW, &opts.origin, 0)) < 0) { fprintf(stderr, "%s: pmSetMode failed: %s\n", pmProgname, pmErrStr(sts)); exit(1); } } if ((sts = pmFetch(1, &pmidlist[i], &xresult)) < 0) { printf("%s: pmFetch: %s\n", namelist[i], pmErrStr(sts)); continue; } vsp = xresult->vset[0]; /* leave the profile in the default state */ free(all_inst); free(all_names); pmDelProfile(desc.indom, 0, NULL); pmAddProfile(desc.indom, 0, NULL); } else if (all_count == 0) { printf("%s: pmGetIndom: No instances?\n", namelist[i]); continue; } else { printf("%s: pmGetIndom: %s\n", namelist[i], pmErrStr(all_count)); continue; } } } } if (verify) { if (desc.type == PM_TYPE_NOSUPPORT) printf("%s: Not Supported\n", namelist[i]); else if (vsp->numval < 0) printf("%s: %s\n", namelist[i], pmErrStr(vsp->numval)); else if (vsp->numval == 0) printf("%s: No value(s) available\n", namelist[i]); continue; } else /* not verify */ printf("%s", namelist[i]); if (p_mid) printf(" PMID: %s", pmIDStr(pmidlist[i])); if (p_fullmid) printf(" = %d = 0x%x", pmidlist[i], pmidlist[i]); if (p_oneline) { if ((sts = pmLookupText(pmidlist[i], PM_TEXT_ONELINE, &buffer)) == 0) { if (p_fullmid) printf("\n "); else putchar(' '); printf("[%s]", buffer); free(buffer); } else printf(" One-line Help: Error: %s\n", pmErrStr(sts)); } putchar('\n'); if (p_desc) __pmPrintDesc(stdout, &desc); if (p_help) { if ((sts = pmLookupText(pmidlist[i], PM_TEXT_HELP, &buffer)) == 0) { char *p; for (p = buffer; *p; p++) ; while (p > buffer && p[-1] == '\n') { p--; *p = '\0'; } if (*buffer != '\0') { printf("Help:\n"); printf("%s", buffer); putchar('\n'); } else printf("Help: <empty entry>\n"); free(buffer); } else printf("Full Help: Error: %s\n", pmErrStr(sts)); } if (p_value) { mydump(&desc, vsp, NULL); } } if (result != NULL) { pmFreeResult(result); result = NULL; } if (xresult != NULL) { pmFreeResult(xresult); xresult = NULL; } done: for (i = 0; i < batchidx; i++) free(namelist[i]); batchidx = 0; }