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; }
static void printstamp(FILE *f, const struct timeval *tp) { struct tm tmp; time_t now; now = (time_t)tp->tv_sec; pmLocaltime(&now, &tmp); fprintf(f, "%4d-%02d-%02d %02d:%02d:%02d.%06d", 1900+tmp.tm_year, tmp.tm_mon, tmp.tm_mday, tmp.tm_hour, tmp.tm_min, tmp.tm_sec, (int)(tp->tv_usec)); }
/* ** Function convdate() converts a value (number of seconds since ** 1-1-1970) to an ascii-string in the format yyyy/mm/dd, stored in ** chardat (11 bytes long). */ char * convdate(double timed, char *chardat, size_t buflen) { time_t utime = (time_t) timed; struct tm tt; pmLocaltime(&utime, &tt); snprintf(chardat, buflen, "%04d/%02d/%02d", tt.tm_year+1900, tt.tm_mon+1, tt.tm_mday); return chardat; }
/* ** Function convtime() converts a value (number of seconds since ** 1-1-1970) to an ascii-string in the format hh:mm:ss, stored in ** chartim (9 bytes long). */ char * convtime(double timed, char *chartim, size_t buflen) { time_t utime = (time_t) timed; struct tm tt; pmLocaltime(&utime, &tt); snprintf(chartim, buflen, "%02d:%02d:%02d", tt.tm_hour, tt.tm_min, tt.tm_sec); return chartim; }
QString QmcSource::timeStringBrief(const struct timeval *timeval) { QString timestring; struct tm tmp; time_t secs = (time_t)timeval->tv_sec; pmLocaltime(&secs, &tmp); timestring.sprintf("%02d:%02d:%02d.%03d", tmp.tm_hour, tmp.tm_min, tmp.tm_sec, (int)(timeval->tv_usec/1000)); return timestring; }
// return a string containing hour and milliseconds char *QedApp::timeHiResString(double time) { static char s[16]; char m[8]; time_t secs = (time_t)time; struct tm t; sprintf(m, "%.3f", time - floor(time)); pmLocaltime(&secs, &t); sprintf(s, "%02d:%02d:%02d.%s", t.tm_hour, t.tm_min, t.tm_sec, m+2); s[strlen(s)-1] = '\0'; return s; }
/* update time variables to reflect current time */ void reflectTime(RealTime d) { static time_t then = 0; /* previous time */ int skip = now - then; struct tm tm; then = (time_t)now; /* sample interval */ delta = d; /* try short path for current time */ if (skip >= 0 && skip < 24 * 60 * 60) { second += skip; if (second < 60) return; skip = (int)(second / 60); second -= (double)(60 * skip); minute += (double)skip; if (minute < 60) return; skip = (int)(minute / 60); minute -= (double)(60 * skip); hour += (double)skip; if (hour < 24) return; } /* long path for current time */ pmLocaltime(&then, &tm); second = (double) tm.tm_sec; minute = (double) tm.tm_min; hour = (double) tm.tm_hour; day = (double) tm.tm_mday; month = (double) tm.tm_mon; /* tm_year is years since 1900, so this is Y2K safe */ year = (double) tm.tm_year + 1900; weekday = (double) tm.tm_wday; }
QString QmcSource::timeString(const struct timeval *timeval) { QString timestring; char timebuf[32], *ddmm, *year; struct tm tmp; time_t secs = (time_t)timeval->tv_sec; ddmm = pmCtime(&secs, timebuf); ddmm[10] = '\0'; year = &ddmm[20]; year[4] = '\0'; pmLocaltime(&secs, &tmp); timestring.sprintf("%02d:%02d:%02d.%03d", tmp.tm_hour, tmp.tm_min, tmp.tm_sec, (int)(timeval->tv_usec/1000)); timestring.prepend(" "); timestring.prepend(ddmm); timestring.append(" "); timestring.append(year); return timestring; }