5 #ifndef GEOPM_TIME_H_INCLUDE
6 #define GEOPM_TIME_H_INCLUDE
24 static inline int geopm_time_string(
int buf_size,
char *buf);
29 static inline double geopm_time_since(
const struct geopm_time_s *begin);
46 return clock_gettime(CLOCK_MONOTONIC_RAW, &(time->
t));
49 static inline int geopm_time_real(
struct geopm_time_s *time)
51 return clock_gettime(CLOCK_REALTIME, &(time->
t));
56 return (end->
t.tv_sec - begin->
t.tv_sec) +
57 (end->
t.tv_nsec - begin->
t.tv_nsec) * 1E-9;
62 bool result = aa->
t.tv_sec < bb->
t.tv_sec;
63 if (!result && aa->
t.tv_sec == bb->
t.tv_sec) {
64 result = aa->
t.tv_nsec < bb->
t.tv_nsec;
72 end->
t.tv_sec += elapsed;
73 elapsed -= floor(elapsed);
74 end->
t.tv_nsec += 1E9 * elapsed;
75 if (end->
t.tv_nsec >= 1000000000) {
76 end->
t.tv_nsec -= 1000000000;
81 static inline int geopm_time_to_string(
const struct geopm_time_s *time,
int buf_size,
char *buf)
87 clock_gettime(CLOCK_REALTIME, &(ref_time_real.t));
88 clock_gettime(CLOCK_MONOTONIC_RAW, &(ref_time_mono.t));
89 time_t sec_since_1970 = geopm_time_diff(&ref_time_mono, &ref_time_real) + time->
t.tv_sec;
90 localtime_r(&sec_since_1970, &tm);
91 size_t num_byte = strftime(buf, buf_size,
"%a %b %d %H:%M:%S %Y", &tm);
101 static inline int geopm_time_string(
int buf_size,
char *buf)
104 int err = geopm_time_real(&time);
111 static inline double geopm_time_since(
const struct geopm_time_s *begin)
114 geopm_time(&curr_time);
115 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:40
struct timespec t
Definition: geopm_time.h:41