Skip to content

Commit

Permalink
fix: monitor returns nanosecond timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
LiShunGang committed Jul 21, 2023
1 parent 9a1b5da commit 075b823
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions source/libs/monitor/src/monMain.c
Expand Up @@ -166,7 +166,7 @@ static SMonInfo *monCreateMonitorInfo() {
return NULL;
}

pMonitor->curTime = taosGetTimestampMs();
pMonitor->curTime = taosGetTimestampNs();
pMonitor->lastTime = tsMonitor.lastTime;
return pMonitor;
}
Expand All @@ -176,7 +176,7 @@ static void monGenBasicJson(SMonInfo *pMonitor) {

SJson *pJson = pMonitor->pJson;
char buf[40] = {0};
taosFormatUtcTime(buf, sizeof(buf), pMonitor->curTime, TSDB_TIME_PRECISION_MILLI);
taosFormatUtcTime(buf, sizeof(buf), pMonitor->curTime, TSDB_TIME_PRECISION_NANO);

tjsonAddStringToObject(pJson, "ts", buf);
tjsonAddDoubleToObject(pJson, "dnode_id", pInfo->dnode_id);
Expand Down Expand Up @@ -332,7 +332,7 @@ static void monGenDnodeJson(SMonInfo *pMonitor) {
return;
}

double interval = (pMonitor->curTime - pMonitor->lastTime) / 1000.0;
double interval = (pMonitor->curTime - pMonitor->lastTime) / (double)TSDB_TICK_PER_SECOND(TSDB_TIME_PRECISION_NANO);
if (pMonitor->curTime - pMonitor->lastTime == 0) {
interval = 1;
}
Expand Down Expand Up @@ -498,7 +498,7 @@ static void monGenLogJson(SMonInfo *pMonitor) {
SMonLogItem *pLogItem = taosArrayGet(pLog->logs, i);

char buf[40] = {0};
taosFormatUtcTime(buf, sizeof(buf), pLogItem->ts, TSDB_TIME_PRECISION_MILLI);
taosFormatUtcTime(buf, sizeof(buf), pLogItem->ts, TSDB_TIME_PRECISION_NANO);

tjsonAddStringToObject(pLogJson, "ts", buf);
tjsonAddStringToObject(pLogJson, "level", monLogLevelStr(pLogItem->level));
Expand Down
24 changes: 12 additions & 12 deletions source/util/src/tlog.c
Expand Up @@ -156,7 +156,7 @@ int32_t taosInitSlowLog() {

tsLogObj.slowHandle = taosLogBuffNew(LOG_SLOW_BUF_SIZE);
if (tsLogObj.slowHandle == NULL) return -1;

taosUmaskFile(0);
tsLogObj.slowHandle->pFile = taosOpenFile(fullName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
if (tsLogObj.slowHandle->pFile == NULL) {
Expand Down Expand Up @@ -527,7 +527,7 @@ void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char

if (tsLogFp && level <= DEBUG_INFO) {
buffer[writeLen - 1] = 0;
(*tsLogFp)(taosGetTimestampMs(), level, buffer + len);
(*tsLogFp)(taosGetTimestampNs(), level, buffer + len);
}
}

Expand Down Expand Up @@ -572,7 +572,7 @@ void taosPrintSlowLog(const char *format, ...) {
} else {
taosWriteFile(tsLogObj.slowHandle->pFile, buffer, len);
}

taosMemoryFree(buffer);
}

Expand Down Expand Up @@ -765,12 +765,12 @@ static void taosWriteLog(SLogBuff *pLogBuf) {
static void *taosAsyncOutputLog(void *param) {
SLogBuff *pLogBuf = (SLogBuff *)tsLogObj.logHandle;
SLogBuff *pSlowBuf = (SLogBuff *)tsLogObj.slowHandle;

setThreadName("log");
int32_t count = 0;
int32_t updateCron = 0;
int32_t writeInterval = 0;

while (1) {
writeInterval = TMIN(pLogBuf->writeInterval, pSlowBuf->writeInterval);
count += writeInterval;
Expand Down Expand Up @@ -852,15 +852,15 @@ void taosLogCrashInfo(char* nodeType, char* pMsg, int64_t msgLen, int signum, vo
int64_t writeSize = taosWriteFile(pFile, &msgLen, sizeof(msgLen));
if (sizeof(msgLen) != writeSize) {
taosUnLockFile(pFile);
taosPrintLog(flags, level, dflag, "failed to write len to file:%s,%p wlen:%" PRId64 " tlen:%lu since %s",
taosPrintLog(flags, level, dflag, "failed to write len to file:%s,%p wlen:%" PRId64 " tlen:%lu since %s",
filepath, pFile, writeSize, sizeof(msgLen), terrstr());
goto _return;
}

writeSize = taosWriteFile(pFile, pMsg, msgLen);
if (msgLen != writeSize) {
taosUnLockFile(pFile);
taosPrintLog(flags, level, dflag, "failed to write file:%s,%p wlen:%" PRId64 " tlen:%" PRId64 " since %s",
taosPrintLog(flags, level, dflag, "failed to write file:%s,%p wlen:%" PRId64 " tlen:%" PRId64 " since %s",
filepath, pFile, writeSize, msgLen, terrstr());
goto _return;
}
Expand Down Expand Up @@ -922,7 +922,7 @@ void taosReadCrashInfo(char* filepath, char** pMsg, int64_t* pMsgLen, TdFilePtr*
taosPrintLog(flags, level, dflag, "failed to open file:%s since %s", filepath, terrstr());
return;
}

taosLockFile(pFile);
} else {
pFile = *pFd;
Expand All @@ -933,7 +933,7 @@ void taosReadCrashInfo(char* filepath, char** pMsg, int64_t* pMsgLen, TdFilePtr*
if (sizeof(msgLen) != readSize) {
truncateFile = true;
if (readSize < 0) {
taosPrintLog(flags, level, dflag, "failed to read len from file:%s,%p wlen:%" PRId64 " tlen:%lu since %s",
taosPrintLog(flags, level, dflag, "failed to read len from file:%s,%p wlen:%" PRId64 " tlen:%lu since %s",
filepath, pFile, readSize, sizeof(msgLen), terrstr());
}
goto _return;
Expand All @@ -944,11 +944,11 @@ void taosReadCrashInfo(char* filepath, char** pMsg, int64_t* pMsgLen, TdFilePtr*
taosPrintLog(flags, level, dflag, "failed to malloc buf, size:%" PRId64, msgLen);
goto _return;
}

readSize = taosReadFile(pFile, buf, msgLen);
if (msgLen != readSize) {
truncateFile = true;
taosPrintLog(flags, level, dflag, "failed to read file:%s,%p wlen:%" PRId64 " tlen:%" PRId64 " since %s",
taosPrintLog(flags, level, dflag, "failed to read file:%s,%p wlen:%" PRId64 " tlen:%" PRId64 " since %s",
filepath, pFile, readSize, msgLen, terrstr());
goto _return;
}
Expand Down Expand Up @@ -977,7 +977,7 @@ void taosReleaseCrashLogFile(TdFilePtr pFile, bool truncateFile) {
if (truncateFile) {
taosFtruncateFile(pFile, 0);
}

taosUnLockFile(pFile);
taosCloseFile(&pFile);
}
Expand Down

0 comments on commit 075b823

Please sign in to comment.