提交 3cfa4906 编写于 作者: K kailixu

chore: uptime logic optimize

上级 ce842ec8
......@@ -90,6 +90,7 @@ extern bool tsMndSkipGrant;
// dnode
extern int64_t tsDndStart;
extern int64_t tsDndStartOsUptime;
extern int64_t tsDndUpTime;
// monitor
......
......@@ -41,6 +41,7 @@ extern "C" {
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/shm.h>
#include <sys/sysinfo.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/time.h>
......
......@@ -18,6 +18,10 @@
#include "os.h"
// #include <linux/unistd.h> /* for _syscallX macros/related stuff */
// #include <linux/kernel.h> /* for struct sysinfo */
#ifdef __cplusplus
extern "C" {
#endif
......@@ -35,6 +39,7 @@ typedef struct {
bool taosCheckSystemIsLittleEnd();
void taosGetSystemInfo();
int64_t taosGetOsUptime();
int32_t taosGetEmail(char *email, int32_t maxLen);
int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t maxLen);
int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores);
......
......@@ -374,6 +374,7 @@ int mainWindows(int argc, char **argv) {
dInfo("start to init service");
dmSetSignalHandle();
tsDndStart = taosGetTimestampMs();
tsDndStartOsUptime = taosGetOsUptime();
int32_t code = dmRun();
dInfo("shutting down the service");
......
......@@ -24,6 +24,10 @@ static void *dmStatusThreadFp(void *param) {
const static int16_t TRIM_FREQ = 30;
int32_t trimCount = 0;
int32_t upTimeCount = 0;
int64_t upTime = 0;
int64_t thrdTime = 0;
while (1) {
taosMsleep(200);
if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
......@@ -39,10 +43,18 @@ static void *dmStatusThreadFp(void *param) {
if (trimCount == 0) {
taosMemoryTrim(0);
}
cost = taosGetTimestampMs() - curTime;
if ((upTimeCount = (++upTimeCount & 7)) == 0) {
upTime = (taosGetOsUptime() - tsDndStartOsUptime) * 1000;
}
}
tsDndUpTime += 200;
if (cost > 0) tsDndUpTime += cost; // TODO: use /proc/uptime to replace the upTime calculation for linux
thrdTime += 200;
cost = taosGetTimestampMs() - curTime;
if (cost > 0) thrdTime += cost;
tsDndUpTime = upTime > thrdTime ? upTime : thrdTime;
printf("upTime:%" PRIi64 " thrdTime:%" PRIi64 " tsDndUpTime:%" PRIi64 " delta:%" PRIi64 "\n", upTime, thrdTime,
tsDndUpTime, upTime - thrdTime);
}
return NULL;
......
......@@ -961,6 +961,20 @@ char *taosGetCmdlineByPID(int pid) {
#endif
}
int64_t taosGetOsUptime() {
#ifdef WINDOWS
return 0;
// #else
// #elif defined(_TD_DARWIN_64)
// return 0;
#else
struct sysinfo info;
if (0 == sysinfo(&info)) {
return info.uptime;
};
#endif
}
void taosSetCoreDump(bool enable) {
if (!enable) return;
#ifdef WINDOWS
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册