32 #ifndef __BASE_TIME_HH__ 33 #define __BASE_TIME_HH__ 56 void _set(
bool monotonic);
74 time_t
sec()
const {
return _time.tv_sec; }
77 long nsec()
const {
return _time.tv_nsec; }
87 void clear() { memset(&_time, 0,
sizeof(_time)); }
103 void set(time_t _sec,
long _nsec) {
sec(_sec);
nsec(_nsec); }
128 double seconds = floor(new_time);
129 sec((time_t)seconds);
130 nsec((
long)((seconds - new_time) * 1e9));
138 nsec(tv.tv_usec * 1000);
153 operator double()
const 155 return (
double)
sec() + ((double)
nsec()) * 1
e-9;
161 operator timespec()
const {
return _time; }
162 operator timeval()
const 174 _time.tv_sec += other.
sec();
175 _time.tv_nsec += other.
nsec();
176 if (_time.tv_nsec > NSEC_PER_SEC) {
187 _time.tv_sec -= other.
sec();
188 _time.tv_nsec -= other.
nsec();
189 if (_time.tv_nsec < 0) {
197 std::string
date(
const std::string &
format =
"")
const;
198 std::string
time()
const;
221 return (l.
sec() < r.
sec()) ||
228 return (l.
sec() < r.
sec()) ||
235 return (l.
sec() > r.
sec()) ||
242 return (l.
sec() > r.
sec()) ||
262 inline std::ostream &
271 #endif // __BASE_TIME_HH__
Time operator+(const Time &l, const Time &r)
void clear()
Clear the time.
std::ostream & operator<<(std::ostream &out, const Time &time)
const Time & operator=(const Time &other)
const Time & operator=(const timeval &tv)
const Time & operator=(double new_time)
void _set(bool monotonic)
Internal time set function.
std::string date(const std::string &format="") const
void setWallclock()
Use this to set the time to the actual current time.
static const long NSEC_PER_MSEC
time_t mkutctime(struct tm *time)
bool operator>=(const Time &l, const Time &r)
bool operator==(const Time &l, const Time &r)
uint64_t Tick
Tick count type.
static const long NSEC_PER_USEC
void unserialize(const std::string &base, CheckpointIn &cp)
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
static const long NSEC_PER_SEC
const Time & operator+=(const Time &other)
std::ostream CheckpointOut
void sleep(const Time &time)
Bitfield< 31, 29 > format
Time(uint64_t sec, uint64_t nsec)
bool operator<=(const Time &l, const Time &r)
bool operator>(const Time &l, const Time &r)
const Time & operator-=(const Time &other)
void serialize(const std::string &base, CheckpointOut &cp) const
void setTick(Tick ticks)
Set the current time from a value measured in Ticks.
bool operator!=(const Time &l, const Time &r)
void setTimer()
Use this to set time for the purposes of time measurement (use a monotonic clock if it is available...
Tick getTick() const
Get the current time from a value measured in Ticks.
bool operator<(const Time &l, const Time &r)
time_t sec() const
Accessors for getting and setting the current clock.
const Time & operator=(const timespec &ts)
Time operator-(const Time &l, const Time &r)