提交 ff7109fc 编写于 作者: Y YuQing

add function: get_current_time_ns

上级 85354b6e
......@@ -2536,15 +2536,30 @@ bool is_private_ip(const char* ip)
return false;
}
int64_t get_current_time_ns()
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts) != 0)
{
logError("file: "__FILE__", line: %d, "
"call clock_gettime fail, "
"errno: %d, error info: %s",
__LINE__, errno, STRERROR(errno));
return errno != 0 ? errno : EPERM;
}
return ((int64_t)ts.tv_sec * 1000 * 1000 * 1000LL + (int64_t)ts.tv_nsec);
}
int64_t get_current_time_us()
{
struct timeval tv;
if (gettimeofday(&tv, NULL) != 0)
{
logError("file: "__FILE__", line: %d, " \
"call gettimeofday fail, " \
"errno: %d, error info: %s", \
logError("file: "__FILE__", line: %d, "
"call gettimeofday fail, "
"errno: %d, error info: %s",
__LINE__, errno, STRERROR(errno));
return errno != 0 ? errno : EPERM;
}
......
......@@ -711,6 +711,10 @@ double get_line_distance_km(const double lat1, const double lon1,
*/
bool is_private_ip(const char* ip);
/** get current time in ns
* return: current time
*/
int64_t get_current_time_ns();
/** get current time in us
* return: current time
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册