2017-08-24 22:48:42 +00:00
|
|
|
//
|
|
|
|
|
// Copyright 2017 Ettus Research (National Instruments Corp.)
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0+
|
|
|
|
|
//
|
|
|
|
|
|
2018-04-06 18:36:04 +00:00
|
|
|
#include <uhdlib/utils/system_time.hpp>
|
2017-08-24 22:48:42 +00:00
|
|
|
|
|
|
|
|
using namespace uhd;
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CLOCK_GETTIME
|
2020-03-03 20:52:17 +00:00
|
|
|
# include <time.h>
|
|
|
|
|
time_spec_t uhd::get_system_time(void)
|
|
|
|
|
{
|
|
|
|
|
timespec ts;
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
2017-08-24 22:48:42 +00:00
|
|
|
return time_spec_t(ts.tv_sec, ts.tv_nsec, 1e9);
|
|
|
|
|
}
|
|
|
|
|
#endif /* HAVE_CLOCK_GETTIME */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_MACH_ABSOLUTE_TIME
|
2020-03-03 20:52:17 +00:00
|
|
|
# include <mach/mach_time.h>
|
|
|
|
|
time_spec_t uhd::get_system_time(void)
|
|
|
|
|
{
|
|
|
|
|
mach_timebase_info_data_t info;
|
|
|
|
|
mach_timebase_info(&info);
|
|
|
|
|
intmax_t nanosecs = mach_absolute_time() * info.numer / info.denom;
|
2017-08-24 22:48:42 +00:00
|
|
|
return time_spec_t::from_ticks(nanosecs, 1e9);
|
|
|
|
|
}
|
|
|
|
|
#endif /* HAVE_MACH_ABSOLUTE_TIME */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_QUERY_PERFORMANCE_COUNTER
|
2020-03-03 20:52:17 +00:00
|
|
|
# include <Windows.h>
|
|
|
|
|
time_spec_t uhd::get_system_time(void)
|
|
|
|
|
{
|
2017-08-24 22:48:42 +00:00
|
|
|
LARGE_INTEGER counts, freq;
|
|
|
|
|
QueryPerformanceCounter(&counts);
|
|
|
|
|
QueryPerformanceFrequency(&freq);
|
|
|
|
|
return time_spec_t::from_ticks(counts.QuadPart, double(freq.QuadPart));
|
|
|
|
|
}
|
|
|
|
|
#endif /* HAVE_QUERY_PERFORMANCE_COUNTER */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_MICROSEC_CLOCK
|
2020-03-03 20:52:17 +00:00
|
|
|
# include <boost/date_time/posix_time/posix_time.hpp>
|
2017-08-24 22:48:42 +00:00
|
|
|
namespace pt = boost::posix_time;
|
2020-03-03 20:52:17 +00:00
|
|
|
time_spec_t uhd::get_system_time(void)
|
|
|
|
|
{
|
|
|
|
|
pt::ptime time_now = pt::microsec_clock::universal_time();
|
2017-08-24 22:48:42 +00:00
|
|
|
pt::time_duration time_dur = time_now - pt::from_time_t(0);
|
2020-03-03 20:52:17 +00:00
|
|
|
return time_spec_t(int64_t(time_dur.total_seconds()),
|
2017-08-24 22:48:42 +00:00
|
|
|
long(time_dur.fractional_seconds()),
|
2020-03-03 20:52:17 +00:00
|
|
|
double(pt::time_duration::ticks_per_second()));
|
2017-08-24 22:48:42 +00:00
|
|
|
}
|
|
|
|
|
#endif /* HAVE_MICROSEC_CLOCK */
|