diff --git a/util/include/util/tc_timeprovider.h b/util/include/util/tc_timeprovider.h index 782db6e..027761f 100644 --- a/util/include/util/tc_timeprovider.h +++ b/util/include/util/tc_timeprovider.h @@ -28,6 +28,7 @@ namespace tars { #define TNOW TC_TimeProvider::getInstance()->getNow() #define TNOWMS TC_TimeProvider::getInstance()->getNowMs() +#define TNOWUS TC_TimeProvider::getInstance()->getNowUs() ///////////////////////////////////////////////// /** @@ -95,6 +96,14 @@ public: */ uint64_t getNowMs(); + /** + * @brief 获取us时间. + * + * @para timeval + * @return void + */ + uint64_t getNowUs(); + protected: static TC_TimeProvider *g_tp; diff --git a/util/src/tc_timeprovider.cpp b/util/src/tc_timeprovider.cpp index 7a745ee..e240efd 100644 --- a/util/src/tc_timeprovider.cpp +++ b/util/src/tc_timeprovider.cpp @@ -114,6 +114,14 @@ uint64_t TC_TimeProvider::getNowMs() return tv.tv_sec * (int64_t)1000 + tv.tv_usec / 1000; } +uint64_t TC_TimeProvider::getNowUs() +{ + struct timeval tv; + getNow(&tv); + + return tv.tv_sec * (int64_t)1000000 + tv.tv_usec; +} + void TC_TimeProvider::run() { memset(_tsc, 0x00, sizeof(_tsc));