提交 8a9ed8e2 编写于 作者: S Shengliang Guan

TD-1207

上级 ac49a78d
......@@ -124,8 +124,8 @@ void bnStartTimer(int32_t mseconds) {
bool updateSoon = (mseconds != -1);
if (updateSoon) {
mTrace("balance function will be called after %" PRId64 " ms", mseconds);
taosTmrReset(bnProcessTimer, mseconds, (void *)mseconds, tsMnodeTmr, &tsBnThread.timer);
mTrace("balance function will be called after %d ms", mseconds);
taosTmrReset(bnProcessTimer, mseconds, (void *)(int64_t)mseconds, tsMnodeTmr, &tsBnThread.timer);
} else {
taosTmrReset(bnProcessTimer, tsStatusInterval * 1000, NULL, tsMnodeTmr, &tsBnThread.timer);
}
......
......@@ -45,6 +45,21 @@ static char tsProcMemFile[25] = {0};
static char tsProcIOFile[25] = {0};
static float tsPageSizeKB = 0;
static void taosGetProcInfos() {
tsPageSize = sysconf(_SC_PAGESIZE);
tsOpenMax = sysconf(_SC_OPEN_MAX);
tsStreamMax = sysconf(_SC_STREAM_MAX);
tsProcId = (pid_t)syscall(SYS_gettid);
tsPageSizeKB = (float)(sysconf(_SC_PAGESIZE)) / 1024;
snprintf(tsProcMemFile, 25, "/proc/%d/status", tsProcId);
snprintf(tsProcCpuFile, 25, "/proc/%d/stat", tsProcId);
snprintf(tsProcIOFile, 25, "/proc/%d/io", tsProcId);
}
static int32_t taosGetTotalMemory() { return (int32_t)((float)sysconf(_SC_PHYS_PAGES) * tsPageSizeKB / 1024); }
bool taosGetSysMemory(float *memoryUsedMB) {
float memoryAvailMB = (float)sysconf(_SC_AVPHYS_PAGES) * tsPageSizeKB / 1024;
*memoryUsedMB = (float)tsTotalMemoryMB - memoryAvailMB;
......@@ -105,7 +120,8 @@ static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
}
char cpu[10] = {0};
sscanf(line, "%s %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system, &cpuInfo->idle);
sscanf(line, "%s %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system,
&cpuInfo->idle);
tfree(line);
fclose(fp);
......@@ -131,7 +147,8 @@ static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
for (int i = 0, blank = 0; line[i] != 0; ++i) {
if (line[i] == ' ') blank++;
if (blank == PROCESS_ITEM) {
sscanf(line + i + 1, "%" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, &cpuInfo->utime, &cpuInfo->stime, &cpuInfo->cutime, &cpuInfo->cstime);
sscanf(line + i + 1, "%" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, &cpuInfo->utime, &cpuInfo->stime,
&cpuInfo->cutime, &cpuInfo->cstime);
break;
}
}
......@@ -162,7 +179,7 @@ static void taosGetSystemTimezone() {
char buf[68] = {0};
if (f != NULL) {
int len = fread(buf, 64, 1, f);
if(len < 64 && ferror(f)) {
if (len < 64 && ferror(f)) {
fclose(f);
uError("read /etc/timezone error, reason:%s", strerror(errno));
return;
......@@ -258,6 +275,8 @@ static void taosGetSystemLocale() { // get and set default locale
}
}
static int32_t taosGetCpuCores() { return (int32_t)sysconf(_SC_NPROCESSORS_ONLN); }
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) {
static uint64_t lastSysUsed = 0;
static uint64_t lastSysTotal = 0;
......@@ -303,8 +322,6 @@ bool taosGetDisk() {
if (tscEmbedded) {
if (statvfs(tsDataDir, &info)) {
//tsTotalDataDirGB = 0;
//tsAvailDataDirGB = 0;
uError("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
return false;
} else {
......@@ -314,8 +331,6 @@ bool taosGetDisk() {
}
if (statvfs(tsLogDir, &info)) {
//tsTotalLogDirGB = 0;
//tsAvailLogDirGB = 0;
uError("failed to get disk size, logDir:%s errno:%s", tsLogDir, strerror(errno));
return false;
} else {
......@@ -324,8 +339,6 @@ bool taosGetDisk() {
}
if (statvfs("/tmp", &info)) {
//tsTotalTmpDirGB = 0;
//tsAvailTmpDirectorySpace = 0;
uError("failed to get disk size, tmpDir:/tmp errno:%s", strerror(errno));
return false;
} else {
......@@ -344,7 +357,6 @@ static bool taosGetCardInfo(int64_t *bytes) {
return false;
}
size_t len = 2048;
char * line = calloc(1, len);
......@@ -490,18 +502,10 @@ bool taosGetProcIO(float *readKB, float *writeKB) {
}
void taosGetSystemInfo() {
tsNumOfCores = (int32_t)sysconf(_SC_NPROCESSORS_ONLN);
tsPageSize = sysconf(_SC_PAGESIZE);
tsOpenMax = sysconf(_SC_OPEN_MAX);
tsStreamMax = sysconf(_SC_STREAM_MAX);
taosGetProcInfos();
tsProcId = (pid_t)syscall(SYS_gettid);
tsPageSizeKB = (float)(sysconf(_SC_PAGESIZE)) / 1024;
tsTotalMemoryMB = (int32_t)((float)sysconf(_SC_PHYS_PAGES) * tsPageSizeKB / 1024);
snprintf(tsProcMemFile, 25, "/proc/%d/status", tsProcId);
snprintf(tsProcCpuFile, 25, "/proc/%d/stat", tsProcId);
snprintf(tsProcIOFile, 25, "/proc/%d/io", tsProcId);
tsNumOfCores = taosGetCpuCores();
tsTotalMemoryMB = taosGetTotalMemory();
float tmp1, tmp2;
taosGetSysMemory(&tmp1);
......@@ -578,11 +582,11 @@ void taosSetCoreDump() {
struct rlimit rlim;
struct rlimit rlim_new;
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
#ifndef _ALPINE
#ifndef _ALPINE
uInfo("the old unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
#else
#else
uInfo("the old unlimited para: rlim_cur=%llu, rlim_max=%llu", rlim.rlim_cur, rlim.rlim_max);
#endif
#endif
rlim_new.rlim_cur = RLIM_INFINITY;
rlim_new.rlim_max = RLIM_INFINITY;
if (setrlimit(RLIMIT_CORE, &rlim_new) != 0) {
......@@ -594,16 +598,17 @@ void taosSetCoreDump() {
}
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
#ifndef _ALPINE
#ifndef _ALPINE
uInfo("the new unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
#else
#else
uInfo("the new unlimited para: rlim_cur=%llu, rlim_max=%llu", rlim.rlim_cur, rlim.rlim_max);
#endif
#endif
}
#ifndef _TD_ARM_
// 2. set the path for saving core file
struct __sysctl_args args;
int old_usespid = 0;
size_t old_len = 0;
int new_usespid = 1;
......@@ -613,7 +618,7 @@ void taosSetCoreDump() {
memset(&args, 0, sizeof(struct __sysctl_args));
args.name = name;
args.nlen = sizeof(name)/sizeof(name[0]);
args.nlen = sizeof(name) / sizeof(name[0]);
args.oldval = &old_usespid;
args.oldlenp = &old_len;
args.newval = &new_usespid;
......@@ -627,12 +632,11 @@ void taosSetCoreDump() {
uInfo("The old core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
old_usespid = 0;
old_len = 0;
memset(&args, 0, sizeof(struct __sysctl_args));
args.name = name;
args.nlen = sizeof(name)/sizeof(name[0]);
args.nlen = sizeof(name) / sizeof(name[0]);
args.oldval = &old_usespid;
args.oldlenp = &old_len;
......@@ -644,7 +648,6 @@ void taosSetCoreDump() {
uInfo("The new core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
#endif
}
bool taosGetSystemUid(char *uid) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册