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

chore: uptime logic optimize

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