32 #ifndef __BASE_TIME_HH__
33 #define __BASE_TIME_HH__
56 void _set(
bool monotonic);
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
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_t mkutctime(struct tm *time)
void clear()
Clear the time.
void sleep(const Time &time)
bool operator<(const Time &l, const Time &r)
time_t sec() const
Accessors for getting and setting the current clock.
const Time & operator=(const Time &other)
const Time & operator=(const timeval &tv)
std::string date(const std::string &format="") const
void serialize(const std::string &base, CheckpointOut &cp) const
void set(time_t _sec, long _nsec)
Set the current time.
Time operator-(const Time &l, const Time &r)
const Time & operator=(double new_time)
void _set(bool monotonic)
Internal time set function.
void setWallclock()
Use this to set the time to the actual current time.
static const long NSEC_PER_MSEC
bool operator<=(const Time &l, const Time &r)
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.
std::ostream & operator<<(std::ostream &out, const Time &time)
bool operator>(const Time &l, const Time &r)
static const long NSEC_PER_SEC
const Time & operator+=(const Time &other)
std::ostream CheckpointOut
Bitfield< 31, 29 > format
Time(uint64_t sec, uint64_t nsec)
bool operator!=(const Time &l, const Time &r)
const Time & operator-=(const Time &other)
Time operator+(const Time &l, const Time &r)
Tick getTick() const
Get the current time from a value measured in Ticks.
void setTick(Tick ticks)
Set the current time from a value measured in Ticks.
void setTimer()
Use this to set time for the purposes of time measurement (use a monotonic clock if it is available...
const Time & operator=(const timespec &ts)