5 #ifndef GEOPM_TIME_H_INCLUDE
6 #define GEOPM_TIME_H_INCLUDE
23 static inline int geopm_time_string(
int buf_size,
char *buf);
28 static inline double geopm_time_since(
const struct geopm_time_s *begin);
45 return clock_gettime(CLOCK_MONOTONIC_RAW, &(time->
t));
48 static inline int geopm_time_real(
struct geopm_time_s *time)
50 return clock_gettime(CLOCK_REALTIME, &(time->
t));
55 return (end->
t.tv_sec - begin->
t.tv_sec) +
56 (end->
t.tv_nsec - begin->
t.tv_nsec) * 1E-9;
61 bool result = aa->
t.tv_sec < bb->
t.tv_sec;
62 if (!result && aa->
t.tv_sec == bb->
t.tv_sec) {
63 result = aa->
t.tv_nsec < bb->
t.tv_nsec;
71 end->
t.tv_sec += elapsed;
72 elapsed -= floor(elapsed);
73 end->
t.tv_nsec += 1E9 * elapsed;
74 if (end->
t.tv_nsec >= 1000000000) {
75 end->
t.tv_nsec -= 1000000000;
80 static inline int geopm_time_to_string(
const struct geopm_time_s *time,
int buf_size,
char *buf)
86 clock_gettime(CLOCK_REALTIME, &(ref_time_real.t));
87 clock_gettime(CLOCK_MONOTONIC_RAW, &(ref_time_mono.t));
88 time_t sec_since_1970 = geopm_time_diff(&ref_time_mono, &ref_time_real) + time->
t.tv_sec;
89 localtime_r(&sec_since_1970, &tm);
90 size_t num_byte = strftime(buf, buf_size,
"%a %b %d %H:%M:%S %Y", &tm);
97 static inline int geopm_time_string(
int buf_size,
char *buf)
100 int err = geopm_time(&time);
102 err = geopm_time_to_string(&time, buf_size, buf);
107 static inline double geopm_time_since(
const struct geopm_time_s *begin)
110 geopm_time(&curr_time);
111 return geopm_time_diff(begin, &curr_time);
#define GEOPM_PUBLIC
Definition: geopm_public.h:10
int GEOPM_PUBLIC geopm_time_zero(struct geopm_time_s *zero_time)
Definition: TimeZero.cpp:77
struct geopm_time_s time_zero(void)
Definition: TimeZero.cpp:53
void time_zero_reset(const geopm_time_s &zero)
Definition: TimeZero.cpp:62
struct geopm_time_s time_curr(void)
Definition: TimeZero.cpp:67
structure to abstract the timespec on linux from other representations of time.
Definition: geopm_time.h:39
struct timespec t
Definition: geopm_time.h:40