const struct timeval * __pmDefaultRequestTimeout(void) { static int done_default = 0; PM_INIT_LOCKS(); PM_LOCK(__pmLock_libpcp); if (!done_default) { char *timeout_str; char *end_ptr; if ((timeout_str = getenv("PMCD_REQUEST_TIMEOUT")) != NULL) { def_timeout = strtod(timeout_str, &end_ptr); if (*end_ptr != '\0' || def_timeout < 0.0) { __pmNotifyErr(LOG_WARNING, "ignored bad PMCD_REQUEST_TIMEOUT = '%s'\n", timeout_str); } else { __pmtimevalFromReal(def_timeout, &def_wait); } } done_default = 1; } PM_UNLOCK(__pmLock_libpcp); return (&def_wait); }
void GroupControl::adjustArchiveWorldViewBackward(QmcTime::Packet *packet, bool setup) { console->post("GroupControl::adjustArchiveWorldViewBackward"); my.timeState = BackwardState; int setmode = PM_MODE_INTERP; int delta = packet->delta.tv_sec; if (packet->delta.tv_usec == 0) { setmode |= PM_XTB_SET(PM_TIME_SEC); } else { delta = delta * 1000 + packet->delta.tv_usec / 1000; setmode |= PM_XTB_SET(PM_TIME_MSEC); } // // X-Axis _min_ becomes packet->position. // Rest of (following) time window filled in using packet->delta. // int last = my.samples - 1; double tolerance = my.realDelta / 20.0; // 5% of the sample interval double position = my.realPosition; double left = position - (my.realDelta * last); double right = position; double interval = pmchart->timeAxis()->scaleValue((double)delta, my.visible); for (int i = 0; i <= last; i++, position -= my.realDelta) { if (setup == false && fuzzyTimeMatch(my.timeData[i], position, tolerance) == true) { continue; } my.timeData[i] = position; struct timeval timeval; __pmtimevalFromReal(position, &timeval); setArchiveMode(setmode, &timeval, -delta); console->post("Fetching data[%d] at %s", i, timeString(position)); fetch(); if (i == last) // refreshGadgets() finishes up last one break; console->post("GroupControl::adjustArchiveWorldViewBackward: " "setting time position[%d]=%.2f[%s] state=%s count=%d", i, position, timeString(position), timeState(), gadgetCount()); for (int j = 0; j < gadgetCount(); j++) my.gadgetsList.at(j)->updateValues(false, false, my.samples, my.visible, left, right, interval); } bool active = isActive(packet); if (setup) packet->state = QmcTime::StoppedState; if (active) newButtonState(packet->state, packet->mode, pmchart->isTabRecording()); pmtime->setArchivePosition(&packet->position); pmtime->setArchiveInterval(&packet->delta); refreshGadgets(active); }
void QmcGroup::updateBounds() { double newStart = DBL_MAX; double newEnd = 0.0; double startReal; double endReal; struct timeval startTv; struct timeval endTv; my.timeStart.tv_sec = 0; my.timeStart.tv_usec = 0; my.timeEnd = my.timeStart; for (unsigned int i = 0; i < numContexts(); i++) { if (my.contexts[i]->handle() >= 0 && my.contexts[i]->source().type() == PM_CONTEXT_ARCHIVE) { startTv = my.contexts[i]->source().start(); endTv = my.contexts[i]->source().end(); startReal = __pmtimevalToReal(&startTv); endReal = __pmtimevalToReal(&endTv); if (startReal < newStart) newStart = startReal; if (endReal > newEnd) newEnd = endReal; } } __pmtimevalFromReal(newStart, &my.timeStart); __pmtimevalFromReal(newEnd, &my.timeEnd); my.timeEndReal = newEnd; if (pmDebug & DBG_TRACE_PMC) { QTextStream cerr(stderr); cerr << "QmcGroup::updateBounds: start = " << my.timeStart.tv_sec << '.' << my.timeStart.tv_usec << ", end = " << my.timeEnd.tv_sec << '.' << my.timeEnd.tv_usec << endl; } }
// conversion from seconds (double precision) to struct timeval void QedApp::timevalFromSeconds(double value, struct timeval *tv) { __pmtimevalFromReal(value, tv); }
void rawwrite(pmOptions *opts, const char *name, struct timeval *delta, unsigned int nsamples, char midnightflag) { pmRecordHost *record; struct timeval elapsed; double duration; double interval; char args[MAXPATHLEN]; char *host; int sts; host = (opts->nhosts > 0) ? opts->hosts[0] : "local:"; interval = __pmtimevalToReal(delta); duration = interval * nsamples; if (midnightflag) { time_t now = time(NULL); struct tm *tp; tp = localtime(&now); tp->tm_hour = 23; tp->tm_min = 59; tp->tm_sec = 59; duration = (double) (mktime(tp) - now); } if (pmDebug & DBG_TRACE_APPL1) { fprintf(stderr, "%s: start recording, %.2fsec duration [%s].\n", pmProgname, duration, name); } if (__pmMakePath(name, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) < 0) { fprintf(stderr, "%s: making folio path %s for recording: %s\n", pmProgname, name, osstrerror()); cleanstop(1); } if (chdir(name) < 0) { fprintf(stderr, "%s: entering folio %s for recording: %s\n", pmProgname, name, strerror(oserror())); cleanstop(1); } /* ** Non-graphical application using libpcp_gui services - never want ** to see popup dialogs from pmlogger(1) here, so force the issue. */ putenv("PCP_XCONFIRM_PROG=/bin/true"); snprintf(args, sizeof(args), "%s.folio", basename((char *)name)); args[sizeof(args)-1] = '\0'; if (pmRecordSetup(args, pmProgname, 1) == NULL) { fprintf(stderr, "%s: cannot setup recording to %s: %s\n", pmProgname, name, osstrerror()); cleanstop(1); } if ((sts = pmRecordAddHost(host, 1, &record)) < 0) { fprintf(stderr, "%s: adding host %s to recording: %s\n", pmProgname, host, pmErrStr(sts)); cleanstop(1); } rawconfig(record->f_config, interval); /* ** start pmlogger with a deadhand timer, ensuring it will stop */ snprintf(args, sizeof(args), "-T%.3fseconds", duration); args[sizeof(args)-1] = '\0'; if ((sts = pmRecordControl(record, PM_REC_SETARG, args)) < 0) { fprintf(stderr, "%s: setting loggers arguments: %s\n", pmProgname, pmErrStr(sts)); cleanstop(1); } if ((sts = pmRecordControl(NULL, PM_REC_ON, "")) < 0) { fprintf(stderr, "%s: failed to start recording: %s\n", pmProgname, pmErrStr(sts)); cleanstop(1); } __pmtimevalFromReal(duration, &elapsed); __pmtimevalSleep(elapsed); if ((sts = pmRecordControl(NULL, PM_REC_OFF, "")) < 0) { fprintf(stderr, "%s: failed to stop recording: %s\n", pmProgname, pmErrStr(sts)); cleanstop(1); } if (pmDebug & DBG_TRACE_APPL1) { fprintf(stderr, "%s: cleanly stopped recording.\n", pmProgname); } }
/* 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; }