trace2 / tr2_tbuf.con commit conditional markdown preprocessing (c8b1cd9)
   1#include "cache.h"
   2#include "tr2_tbuf.h"
   3
   4void tr2_tbuf_local_time(struct tr2_tbuf *tb)
   5{
   6        struct timeval tv;
   7        struct tm tm;
   8        time_t secs;
   9
  10        gettimeofday(&tv, NULL);
  11        secs = tv.tv_sec;
  12        localtime_r(&secs, &tm);
  13
  14        xsnprintf(tb->buf, sizeof(tb->buf), "%02d:%02d:%02d.%06ld", tm.tm_hour,
  15                  tm.tm_min, tm.tm_sec, (long)tv.tv_usec);
  16}
  17
  18void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb)
  19{
  20        struct timeval tv;
  21        struct tm tm;
  22        time_t secs;
  23
  24        gettimeofday(&tv, NULL);
  25        secs = tv.tv_sec;
  26        gmtime_r(&secs, &tm);
  27
  28        xsnprintf(tb->buf, sizeof(tb->buf),
  29                  "%4d-%02d-%02dT%02d:%02d:%02d.%06ldZ", tm.tm_year + 1900,
  30                  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
  31                  (long)tv.tv_usec);
  32}
  33
  34void tr2_tbuf_utc_datetime(struct tr2_tbuf *tb)
  35{
  36        struct timeval tv;
  37        struct tm tm;
  38        time_t secs;
  39
  40        gettimeofday(&tv, NULL);
  41        secs = tv.tv_sec;
  42        gmtime_r(&secs, &tm);
  43
  44        xsnprintf(tb->buf, sizeof(tb->buf), "%4d%02d%02dT%02d%02d%02d.%06ldZ",
  45                  tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
  46                  tm.tm_min, tm.tm_sec, (long)tv.tv_usec);
  47}