5 #ifndef BASE_TIME_UTIL_H__
6 #define BASE_TIME_UTIL_H__
10 #include <boost/date_time/posix_time/posix_time.hpp>
11 #include <boost/date_time/posix_time/posix_time_types.hpp>
15 if (clock_gettime(CLOCK_REALTIME, &ts) != 0) {
19 return ts.tv_sec * 1000000 + ts.tv_nsec/1000;
31 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
35 return ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
39 typedef boost::posix_time::time_duration::sec_type sec_type;
40 typedef boost::posix_time::time_duration::fractional_seconds_type frac_type;
42 int64_t tps = boost::posix_time::time_duration::ticks_per_second();
43 sec_type seconds =
static_cast<sec_type
>(tusec / 1000000);
44 frac_type frac_seconds =
45 static_cast<frac_type
>(tps / 1000000 * (tusec % 1000000));
47 boost::posix_time::ptime pt(
48 boost::gregorian::date(1970, 1, 1),
49 boost::posix_time::time_duration(0, 0, seconds, frac_seconds));
63 std::ostringstream os;
64 boost::posix_time::time_duration duration;
66 duration = boost::posix_time::microseconds(usecs);
71 #endif // BASE_TIME_UTIL_H__
static boost::posix_time::ptime UTCUsecToPTime(uint64_t tusec)
static const std::string duration_usecs_to_string(const uint64_t usecs)
static time_t UTCTimestamp()
static uint64_t UTCTimestampUsec()
static uint64_t ClockMonotonicUsec()
static std::string UTCUsecToString(uint64_t tstamp)