5 #ifndef GEOPM_TIME_H_INCLUDE
6 #define GEOPM_TIME_H_INCLUDE
23 #define GEOPM_TIME_STRING_MAX 255ULL
27 static inline int geopm_time_string(
int buf_size,
char *buf);
32 static inline double geopm_time_since(
const struct geopm_time_s *begin);
49 return clock_gettime(CLOCK_MONOTONIC_RAW, &(time->
t));
52 static inline int geopm_time_real(
struct geopm_time_s *time)
54 return clock_gettime(CLOCK_REALTIME, &(time->
t));
59 return (end->
t.tv_sec - begin->
t.tv_sec) +
60 (end->
t.tv_nsec - begin->
t.tv_nsec) * 1E-9;
65 bool result = aa->
t.tv_sec < bb->
t.tv_sec;
66 if (!result && aa->
t.tv_sec == bb->
t.tv_sec) {
67 result = aa->
t.tv_nsec < bb->
t.tv_nsec;
75 end->
t.tv_sec += elapsed;
76 elapsed -= floor(elapsed);
77 end->
t.tv_nsec += 1E9 * elapsed;
78 if (end->
t.tv_nsec >= 1000000000) {
79 end->
t.tv_nsec -= 1000000000;
84 static inline int geopm_time_to_string(
const struct geopm_time_s *time,
int buf_size,
char *buf)
90 clock_gettime(CLOCK_REALTIME, &(ref_time_real.t));
91 clock_gettime(CLOCK_MONOTONIC_RAW, &(ref_time_mono.t));
92 time_t sec_since_1970 = geopm_time_diff(&ref_time_mono, &ref_time_real) + time->
t.tv_sec;
93 localtime_r(&sec_since_1970, &tm);
94 size_t num_byte = strftime(buf, buf_size,
"%a %b %d %H:%M:%S %Y", &tm);
104 static inline int geopm_time_string(
int buf_size,
char *buf)
107 int err = geopm_time_real(&time);
114 static inline double geopm_time_since(
const struct geopm_time_s *begin)
117 geopm_time(&curr_time);
118 return geopm_time_diff(begin, &curr_time);
#define GEOPM_PUBLIC
Definition: geopm_public.h:10
int GEOPM_PUBLIC geopm_time_real_to_iso_string(const struct geopm_time_s *time, int buf_size, char *buf)
Definition: TimeZero.cpp:104
int GEOPM_PUBLIC geopm_time_zero(struct geopm_time_s *zero_time)
Definition: TimeZero.cpp:98
struct geopm_time_s time_zero(void)
Definition: TimeZero.cpp:56
struct geopm_time_s time_curr_real(void)
Definition: TimeZero.cpp:77
void time_zero_reset(const geopm_time_s &zero)
Definition: TimeZero.cpp:65
std::string time_curr_string(void)
Definition: TimeZero.cpp:84
struct geopm_time_s time_curr(void)
Definition: TimeZero.cpp:70
structure to abstract the timespec on linux from other representations of time.
Definition: geopm_time.h:43
struct timespec t
Definition: geopm_time.h:44