const char *ctimespec(const struct timespec *tp) { static char buf[30]; ctimespec_r(tp, buf, sizeof(buf)); return buf; }
const char *ctimenow_r(char *buf, size_t size, bool ns) { struct timespec now; gettime(&now); return ctimespec_r(&now, buf, size, ns); }
const char *debug_timestamp() { struct timespec now = {.tv_sec = 0, .tv_nsec = 0}; static struct timespec first = {.tv_sec = 0, .tv_nsec = 0}; static struct timespec last = {.tv_sec = 0, .tv_nsec = 0}; static char buf[80]; gettime(&now); if (!first.tv_sec && !first.tv_nsec) last = first = now; ctimespec_r(&now, buf, sizeof(buf)); snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), " [+%8.6lf] (%8.6lf)", time_diff(&last, &now), time_diff(&first, &now)); last = now; return buf; }
int debug_timestamp(char **strp) { struct timespec now = {.tv_sec = 0, .tv_nsec = 0}; static struct timespec first = {.tv_sec = 0, .tv_nsec = 0}; static struct timespec last = {.tv_sec = 0, .tv_nsec = 0}; gettime(&now); /* Save time of first call */ if (!first.tv_sec && !first.tv_nsec) first = last = now; char timestamp[30] = ""; ctimespec_r(&now, timestamp, sizeof(timestamp), true); if (asprintf(strp, "%s [+%8.6lf] (%8.6lf)", timestamp, time_diff(&last, &now), time_diff(&first, &now)) == -1) return -1; last = now; return 0; }