|
|
@@ -1,6 +1,7 @@
|
|
|
#include "utils.h"
|
|
|
#include <QDateTime>
|
|
|
#include <QElapsedTimer>
|
|
|
+#include <time.h>
|
|
|
|
|
|
Utils::Utils(QObject *parent)
|
|
|
: QObject{parent}
|
|
|
@@ -15,6 +16,7 @@ QString Utils::timestamp()
|
|
|
|
|
|
qint64 Utils::currentNanoTimestamp()
|
|
|
{
|
|
|
+#if 0
|
|
|
static QElapsedTimer timer;
|
|
|
static qint64 baseNano = 0;
|
|
|
static bool initialized = false;
|
|
|
@@ -30,4 +32,10 @@ qint64 Utils::currentNanoTimestamp()
|
|
|
|
|
|
// 当前 epoch 纳秒时间戳 = 基准时间 + 已经过的纳秒
|
|
|
return baseNano + timer.nsecsElapsed();
|
|
|
+#endif
|
|
|
+
|
|
|
+ struct timespec ts;
|
|
|
+ clock_gettime(CLOCK_REALTIME, &ts);
|
|
|
+ qint64 timestamp = ts.tv_sec * 1000000000LL + ts.tv_nsec;
|
|
|
+ return timestamp;
|
|
|
}
|