diff --git a/src/pmval/pmval.c b/src/pmval/pmval.c index 61bb835..6fd1896 100644 --- a/src/pmval/pmval.c +++ b/src/pmval/pmval.c @@ -1119,6 +1119,9 @@ getargs(int argc, /* in - command line argument count */ exit(EXIT_FAILURE); } + initapi(cntxt); + initinsts(cntxt); + if (!(gui || port != -1) && *smpls == ALL_SAMPLES && last.tv_sec != INT_MAX && @@ -1126,16 +1129,43 @@ getargs(int argc, /* in - command line argument count */ *smpls = (long)((__pmtimevalToReal(&last) - __pmtimevalToReal(posn)) / __pmtimevalToReal(delta)); - /* if end is before start, no samples thanks */ - if (*smpls < 0) *smpls = 0; - /* counters require 2 samples to produce reported sample */ - if (*smpls > 0 && cntxt->desc.sem != PM_SEM_COUNTER) - (*smpls)++; + if (*smpls < 0) + /* if end is before start, no samples thanks */ + *smpls = 0; + else { + /* + * p stands for posn + * + p + p+delta + p+2*delta + p+3*delta + last + * | | | | | | + * +-----------+-----------+-----------+-- ...... ----+---+---> time + * 1 2 3 smpls + */ + if (cntxt->desc.sem != PM_SEM_COUNTER) { + /* non-counters are reported on the first sample as well */ + (*smpls)++; + } + } #ifdef PCP_DEBUG - if (pmDebug & DBG_TRACE_APPL0) - fprintf(stderr, "getargs: first=%.6f posn=%.6f last=%.6f\ngetargs: delta=%.6f samples=%ld\n", - __pmtimevalToReal(&first), __pmtimevalToReal(posn), - __pmtimevalToReal(&last), __pmtimevalToReal(delta), *smpls); + if (pmDebug & DBG_TRACE_APPL0) { + char tbfr[26]; + char *tp; + fprintf(stderr, "getargs: first=%.6f", __pmtimevalToReal(&first)); + tp = pmCtime((time_t *)&first.tv_sec, tbfr); + /* + * tp -> Ddd Mmm DD HH:MM:SS YYYY\n + * 0 4 8 1 1 2 2 2 + * 1 8 0 3 4 + */ + fprintf(stderr, "[%8.8s]\n", &tp[11]); + fprintf(stderr, "getargs: posn=%.6f", __pmtimevalToReal(posn)); + tp = pmCtime((time_t *)&posn->tv_sec, tbfr); + fprintf(stderr, "[%8.8s]\n", &tp[11]); + fprintf(stderr, "getargs: last=%.6f", __pmtimevalToReal(&last)); + tp = pmCtime((time_t *)&last.tv_sec, tbfr); + fprintf(stderr, "[%8.8s]\n", &tp[11]); + fprintf(stderr, "getargs: delta=%.6f samples=%ld\n", + __pmtimevalToReal(delta), *smpls); + } #endif } @@ -1173,8 +1203,6 @@ main(int argc, char *argv[]) getargs(argc, argv, &cntxt, &now, &delta, &smpls, &cols); forever = (smpls == ALL_SAMPLES || gui); - initapi(&cntxt); - initinsts(&cntxt); if (cols <= 0) cols = howide(cntxt.desc.type);