osSysinfo
This commit is contained in:
parent
a7da6a7d51
commit
82d83b2e6b
|
@ -130,6 +130,12 @@ extern int64_t tsRandErrScope;
|
||||||
extern threadlocal bool tsEnableRandErr;
|
extern threadlocal bool tsEnableRandErr;
|
||||||
|
|
||||||
#define TAOS_UNUSED(expr) (void)(expr)
|
#define TAOS_UNUSED(expr) (void)(expr)
|
||||||
|
#define TAOS_SKIP_ERROR(expr) \
|
||||||
|
{ \
|
||||||
|
int32_t _code = terrno; \
|
||||||
|
(void)(expr); \
|
||||||
|
terrno = _code; \
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,15 +39,17 @@ 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);
|
||||||
void taosGetCpuCores(float *numOfCores, bool physical);
|
int32_t taosGetCpuCores(float *numOfCores, bool physical);
|
||||||
void taosGetCpuUsage(double *cpu_system, double *cpu_engine);
|
int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine);
|
||||||
int32_t taosGetCpuInstructions(char* sse42, char* avx, char* avx2, char* fma, char* avx512);
|
int32_t taosGetCpuInstructions(char* sse42, char* avx, char* avx2, char* fma, char* avx512);
|
||||||
int32_t taosGetTotalMemory(int64_t *totalKB);
|
int32_t taosGetTotalMemory(int64_t *totalKB);
|
||||||
int32_t taosGetProcMemory(int64_t *usedKB);
|
int32_t taosGetProcMemory(int64_t *usedKB);
|
||||||
int32_t taosGetSysMemory(int64_t *usedKB);
|
int32_t taosGetSysMemory(int64_t *usedKB);
|
||||||
int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize);
|
int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize);
|
||||||
void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes);
|
int32_t taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes);
|
||||||
void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes);
|
void taosSetDefaultProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes);
|
||||||
|
int32_t taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes);
|
||||||
|
void taosSetDefaultCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes);
|
||||||
|
|
||||||
void taosKillSystem();
|
void taosKillSystem();
|
||||||
int32_t taosGetSystemUUID(char *uid, int32_t uidlen);
|
int32_t taosGetSystemUUID(char *uid, int32_t uidlen);
|
||||||
|
|
|
@ -156,6 +156,7 @@ int32_t taosGetErrSize();
|
||||||
#define TSDB_CODE_OUT_OF_BUFFER TAOS_DEF_ERROR_CODE(0, 0x0137)
|
#define TSDB_CODE_OUT_OF_BUFFER TAOS_DEF_ERROR_CODE(0, 0x0137)
|
||||||
#define TSDB_CODE_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x0138)
|
#define TSDB_CODE_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x0138)
|
||||||
#define TSDB_CODE_SOCKET_ERROR TAOS_DEF_ERROR_CODE(0, 0x0139)
|
#define TSDB_CODE_SOCKET_ERROR TAOS_DEF_ERROR_CODE(0, 0x0139)
|
||||||
|
#define TSDB_CODE_UNSUPPORT_OS TAOS_DEF_ERROR_CODE(0, 0x013A)
|
||||||
|
|
||||||
//client
|
//client
|
||||||
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200)
|
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200)
|
||||||
|
|
|
@ -55,14 +55,36 @@ void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool need
|
||||||
}
|
}
|
||||||
|
|
||||||
void dmGetMonitorSystemInfo(SMonSysInfo *pInfo) {
|
void dmGetMonitorSystemInfo(SMonSysInfo *pInfo) {
|
||||||
taosGetCpuUsage(&pInfo->cpu_system, &pInfo->cpu_engine);
|
int32_t code = 0;
|
||||||
taosGetCpuCores(&pInfo->cpu_cores, false);
|
code = taosGetCpuUsage(&pInfo->cpu_system, &pInfo->cpu_engine);
|
||||||
(void)taosGetProcMemory(&pInfo->mem_engine);
|
if (code != 0) {
|
||||||
(void)taosGetSysMemory(&pInfo->mem_system);
|
dError("failed to get cpu usage since %s", tstrerror(code));
|
||||||
|
}
|
||||||
|
code = taosGetCpuCores(&pInfo->cpu_cores, false);
|
||||||
|
if (code != 0) {
|
||||||
|
dError("failed to get cpu cores since %s", tstrerror(code));
|
||||||
|
}
|
||||||
|
code = taosGetProcMemory(&pInfo->mem_engine);
|
||||||
|
if (code != 0) {
|
||||||
|
dError("failed to get proc memory since %s", tstrerror(code));
|
||||||
|
}
|
||||||
|
code = taosGetSysMemory(&pInfo->mem_system);
|
||||||
|
if (code != 0) {
|
||||||
|
dError("failed to get sys memory since %s", tstrerror(code));
|
||||||
|
}
|
||||||
pInfo->mem_total = tsTotalMemoryKB;
|
pInfo->mem_total = tsTotalMemoryKB;
|
||||||
pInfo->disk_engine = 0;
|
pInfo->disk_engine = 0;
|
||||||
pInfo->disk_used = tsDataSpace.size.used;
|
pInfo->disk_used = tsDataSpace.size.used;
|
||||||
pInfo->disk_total = tsDataSpace.size.total;
|
pInfo->disk_total = tsDataSpace.size.total;
|
||||||
taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out);
|
code = taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out);
|
||||||
taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk);
|
if (code != 0) {
|
||||||
|
dError("failed to get card info since %s", tstrerror(code));
|
||||||
|
taosSetDefaultCardInfoDelta(&pInfo->net_in, &pInfo->net_out);
|
||||||
|
}
|
||||||
|
code = taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk);
|
||||||
|
if (code != 0) {
|
||||||
|
dError("failed to get proc io delta since %s", tstrerror(code));
|
||||||
|
taosSetDefaultProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,8 +323,8 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosCloseDir(&pDir);
|
TAOS_UNUSED(taosCloseDir(&pDir));
|
||||||
(void)rmdir(dirname);
|
TAOS_UNUSED(rmdir(dirname));
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
|
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
|
||||||
|
|
|
@ -190,10 +190,10 @@ int64_t taosCopyFile(const char *from, const char *to) {
|
||||||
|
|
||||||
_err:
|
_err:
|
||||||
|
|
||||||
if (pFileFrom != NULL) TAOS_UNUSED(taosCloseFile(&pFileFrom));
|
if (pFileFrom != NULL) TAOS_SKIP_ERROR(taosCloseFile(&pFileFrom));
|
||||||
if (pFileTo != NULL) TAOS_UNUSED(taosCloseFile(&pFileTo));
|
if (pFileTo != NULL) TAOS_SKIP_ERROR(taosCloseFile(&pFileTo));
|
||||||
/* coverity[+retval] */
|
/* coverity[+retval] */
|
||||||
TAOS_UNUSED(taosRemoveFile(to));
|
TAOS_SKIP_ERROR(taosRemoveFile(to));
|
||||||
|
|
||||||
terrno = code;
|
terrno = code;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1485,14 +1485,14 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) {
|
||||||
cmp_end:
|
cmp_end:
|
||||||
|
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
(void)close(fd);
|
TAOS_SKIP_ERROR(close(fd));
|
||||||
}
|
}
|
||||||
if (pSrcFile) {
|
if (pSrcFile) {
|
||||||
TAOS_UNUSED(taosCloseFile(&pSrcFile));
|
TAOS_SKIP_ERROR(taosCloseFile(&pSrcFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dstFp) {
|
if (dstFp) {
|
||||||
TAOS_UNUSED(gzclose(dstFp));
|
TAOS_SKIP_ERROR(gzclose(dstFp));
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMemoryFree(data);
|
taosMemoryFree(data);
|
||||||
|
|
|
@ -135,9 +135,14 @@ void taosGetSystemLocale(char *outLocale, char *outCharset) {
|
||||||
str++;
|
str++;
|
||||||
|
|
||||||
char *revisedCharset = taosCharsetReplace(str);
|
char *revisedCharset = taosCharsetReplace(str);
|
||||||
|
|
||||||
|
if (NULL == revisedCharset) {
|
||||||
|
(void)strcpy(outCharset, "UTF-8");
|
||||||
|
} else {
|
||||||
tstrncpy(outCharset, revisedCharset, TD_CHARSET_LEN);
|
tstrncpy(outCharset, revisedCharset, TD_CHARSET_LEN);
|
||||||
|
|
||||||
taosMemoryFree(revisedCharset);
|
taosMemoryFree(revisedCharset);
|
||||||
|
}
|
||||||
// printf("charset not configured, set to system default:%s", outCharset);
|
// printf("charset not configured, set to system default:%s", outCharset);
|
||||||
} else {
|
} else {
|
||||||
strcpy(outCharset, "UTF-8");
|
strcpy(outCharset, "UTF-8");
|
||||||
|
|
|
@ -179,10 +179,8 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
|
||||||
char line[1024];
|
char line[1024];
|
||||||
ssize_t bytes = taosGetsFile(pFile, sizeof(line), line);
|
ssize_t bytes = taosGetsFile(pFile, sizeof(line), line);
|
||||||
if (bytes < 0) {
|
if (bytes < 0) {
|
||||||
code = terrno;
|
TAOS_SKIP_ERROR(taosCloseFile(&pFile));
|
||||||
(void)taosCloseFile(&pFile);
|
return terrno;
|
||||||
terrno = code;
|
|
||||||
return code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char cpu[10] = {0};
|
char cpu[10] = {0};
|
||||||
|
@ -230,9 +228,7 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
|
||||||
char line[1024] = {0};
|
char line[1024] = {0};
|
||||||
ssize_t bytes = taosGetsFile(pFile, sizeof(line), line);
|
ssize_t bytes = taosGetsFile(pFile, sizeof(line), line);
|
||||||
if (bytes < 0) {
|
if (bytes < 0) {
|
||||||
code = terrno;
|
TAOS_SKIP_ERROR(taosCloseFile(&pFile));
|
||||||
(void)taosCloseFile(&pFile);
|
|
||||||
terrno = code;
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +246,7 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosCloseFile(&pFile);
|
TAOS_SKIP_ERROR(taosCloseFile(&pFile));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -427,7 +423,7 @@ int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t
|
||||||
if (++cnt >= 3) break;
|
if (++cnt >= 3) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosCloseFile(&pFile);
|
TAOS_SKIP_ERROR(taosCloseFile(&pFile));
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -497,13 +493,13 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
|
||||||
if (strncmp(line, "processor", 9) == 0) coreCount += 1;
|
if (strncmp(line, "processor", 9) == 0) coreCount += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosCloseFile(&pFile);
|
TAOS_SKIP_ERROR(taosCloseFile(&pFile));
|
||||||
|
|
||||||
if (code != 0 && (done & 1) == 0) {
|
if (code != 0 && (done & 1) == 0) {
|
||||||
TdFilePtr pFile1 = taosOpenFile("/proc/device-tree/model", TD_FILE_READ | TD_FILE_STREAM);
|
TdFilePtr pFile1 = taosOpenFile("/proc/device-tree/model", TD_FILE_READ | TD_FILE_STREAM);
|
||||||
if (pFile1 != NULL) {
|
if (pFile1 != NULL) {
|
||||||
ssize_t bytes = taosGetsFile(pFile1, maxLen, cpuModel);
|
ssize_t bytes = taosGetsFile(pFile1, maxLen, cpuModel);
|
||||||
(void)taosCloseFile(&pFile);
|
TAOS_SKIP_ERROR(taosCloseFile(&pFile));
|
||||||
if (bytes > 0) {
|
if (bytes > 0) {
|
||||||
code = 0;
|
code = 0;
|
||||||
done |= 1;
|
done |= 1;
|
||||||
|
@ -535,9 +531,9 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
|
||||||
// Returns the container's CPU quota if successful, otherwise returns the physical CPU cores
|
// Returns the container's CPU quota if successful, otherwise returns the physical CPU cores
|
||||||
static int32_t taosCntrGetCpuCores(float *numOfCores) {
|
static int32_t taosCntrGetCpuCores(float *numOfCores) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
return -1;
|
return TSDB_CODE_UNSUPPORT_OS;
|
||||||
#elif defined(_TD_DARWIN_64)
|
#elif defined(_TD_DARWIN_64)
|
||||||
return -1;
|
return TSDB_CODE_UNSUPPORT_OS;
|
||||||
#else
|
#else
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
if (!(pFile = taosOpenFile(tsCpuQuotaFile, TD_FILE_READ | TD_FILE_STREAM))) {
|
if (!(pFile = taosOpenFile(tsCpuQuotaFile, TD_FILE_READ | TD_FILE_STREAM))) {
|
||||||
|
@ -545,11 +541,11 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) {
|
||||||
}
|
}
|
||||||
char qline[32] = {0};
|
char qline[32] = {0};
|
||||||
if (taosGetsFile(pFile, sizeof(qline), qline) <= 0) {
|
if (taosGetsFile(pFile, sizeof(qline), qline) <= 0) {
|
||||||
(void)taosCloseFile(&pFile);
|
TAOS_SKIP_ERROR(taosCloseFile(&pFile));
|
||||||
goto _sys;
|
goto _sys;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosCloseFile(&pFile);
|
TAOS_SKIP_ERROR(taosCloseFile(&pFile));
|
||||||
float quota = taosStr2Float(qline, NULL);
|
float quota = taosStr2Float(qline, NULL);
|
||||||
if (quota < 0) {
|
if (quota < 0) {
|
||||||
goto _sys;
|
goto _sys;
|
||||||
|
@ -561,11 +557,11 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) {
|
||||||
|
|
||||||
char pline[32] = {0};
|
char pline[32] = {0};
|
||||||
if (taosGetsFile(pFile, sizeof(pline), pline) <= 0) {
|
if (taosGetsFile(pFile, sizeof(pline), pline) <= 0) {
|
||||||
(void)taosCloseFile(&pFile);
|
TAOS_SKIP_ERROR(taosCloseFile(&pFile));
|
||||||
goto _sys;
|
goto _sys;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosCloseFile(&pFile);
|
TAOS_SKIP_ERROR(taosCloseFile(&pFile));
|
||||||
|
|
||||||
float period = taosStr2Float(pline, NULL);
|
float period = taosStr2Float(pline, NULL);
|
||||||
float quotaCores = quota / period;
|
float quotaCores = quota / period;
|
||||||
|
@ -575,10 +571,16 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) {
|
||||||
} else {
|
} else {
|
||||||
*numOfCores = sysCores;
|
*numOfCores = sysCores;
|
||||||
}
|
}
|
||||||
|
if(*numOfCores <= 0) {
|
||||||
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
|
}
|
||||||
goto _end;
|
goto _end;
|
||||||
|
|
||||||
_sys:
|
_sys:
|
||||||
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
if(*numOfCores <= 0) {
|
||||||
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
|
}
|
||||||
|
|
||||||
_end:
|
_end:
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -586,26 +588,35 @@ _end:
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosGetCpuCores(float *numOfCores, bool physical) {
|
int32_t taosGetCpuCores(float *numOfCores, bool physical) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
SYSTEM_INFO info;
|
SYSTEM_INFO info;
|
||||||
GetSystemInfo(&info);
|
GetSystemInfo(&info);
|
||||||
*numOfCores = info.dwNumberOfProcessors;
|
*numOfCores = info.dwNumberOfProcessors;
|
||||||
return;
|
return 0;
|
||||||
#elif defined(_TD_DARWIN_64)
|
#elif defined(_TD_DARWIN_64)
|
||||||
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
if(*numOfCores <= 0) {
|
||||||
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
if (physical) {
|
if (physical) {
|
||||||
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
*numOfCores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
} else {
|
if(*numOfCores <= 0) {
|
||||||
(void)taosCntrGetCpuCores(numOfCores);
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
return;
|
} else {
|
||||||
|
int code= taosCntrGetCpuCores(numOfCores);
|
||||||
|
if(code != 0) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosGetCpuUsage(double *cpu_system, double *cpu_engine) {
|
int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine) {
|
||||||
static int64_t lastSysUsed = -1;
|
static int64_t lastSysUsed = -1;
|
||||||
static int64_t lastSysTotal = -1;
|
static int64_t lastSysTotal = -1;
|
||||||
static int64_t lastProcTotal = -1;
|
static int64_t lastProcTotal = -1;
|
||||||
|
@ -639,6 +650,7 @@ void taosGetCpuUsage(double *cpu_system, double *cpu_engine) {
|
||||||
lastSysTotal = curSysTotal;
|
lastSysTotal = curSysTotal;
|
||||||
lastProcTotal = curProcTotal;
|
lastProcTotal = curProcTotal;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define __cpuid_fix(level, a, b, c, d) \
|
#define __cpuid_fix(level, a, b, c, d) \
|
||||||
|
@ -860,7 +872,7 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int
|
||||||
if (readIndex >= 4) break;
|
if (readIndex >= 4) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosCloseFile(&pFile);
|
TAOS_SKIP_ERROR(taosCloseFile(&pFile));
|
||||||
|
|
||||||
if (readIndex < 4) {
|
if (readIndex < 4) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -870,7 +882,7 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) {
|
int32_t taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) {
|
||||||
static int64_t last_rchars = -1;
|
static int64_t last_rchars = -1;
|
||||||
static int64_t last_wchars = -1;
|
static int64_t last_wchars = -1;
|
||||||
static int64_t last_read_bytes = -1;
|
static int64_t last_read_bytes = -1;
|
||||||
|
@ -879,7 +891,8 @@ void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, i
|
||||||
static int64_t cur_wchars = 0;
|
static int64_t cur_wchars = 0;
|
||||||
static int64_t cur_read_bytes = 0;
|
static int64_t cur_read_bytes = 0;
|
||||||
static int64_t cur_write_bytes = 0;
|
static int64_t cur_write_bytes = 0;
|
||||||
if (taosGetProcIO(&cur_rchars, &cur_wchars, &cur_read_bytes, &cur_write_bytes) == 0) {
|
int32_t code = taosGetProcIO(&cur_rchars, &cur_wchars, &cur_read_bytes, &cur_write_bytes);
|
||||||
|
if (code == 0) {
|
||||||
if(last_rchars >=0 && last_wchars >=0 && last_read_bytes >=0 && last_write_bytes >= 0){
|
if(last_rchars >=0 && last_wchars >=0 && last_read_bytes >=0 && last_write_bytes >= 0){
|
||||||
*rchars = cur_rchars - last_rchars;
|
*rchars = cur_rchars - last_rchars;
|
||||||
*wchars = cur_wchars - last_wchars;
|
*wchars = cur_wchars - last_wchars;
|
||||||
|
@ -897,11 +910,15 @@ void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, i
|
||||||
last_read_bytes = cur_read_bytes;
|
last_read_bytes = cur_read_bytes;
|
||||||
last_write_bytes = cur_write_bytes;
|
last_write_bytes = cur_write_bytes;
|
||||||
} else {
|
} else {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
void taosSetDefaultProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) {
|
||||||
*rchars = 0;
|
*rchars = 0;
|
||||||
*wchars = 0;
|
*wchars = 0;
|
||||||
*read_bytes = 0;
|
*read_bytes = 0;
|
||||||
*write_bytes = 0;
|
*write_bytes = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
||||||
|
@ -953,18 +970,19 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
||||||
*transmit_bytes += o_tbytes;
|
*transmit_bytes += o_tbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosCloseFile(&pFile);
|
TAOS_SKIP_ERROR(taosCloseFile(&pFile));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
int32_t taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
||||||
static int64_t last_receive_bytes = -1;
|
static int64_t last_receive_bytes = -1;
|
||||||
static int64_t last_transmit_bytes = -1;
|
static int64_t last_transmit_bytes = -1;
|
||||||
int64_t cur_receive_bytes = 0;
|
int64_t cur_receive_bytes = 0;
|
||||||
int64_t cur_transmit_bytes = 0;
|
int64_t cur_transmit_bytes = 0;
|
||||||
if (taosGetCardInfo(&cur_receive_bytes, &cur_transmit_bytes) == 0) {
|
int32_t code = taosGetCardInfo(&cur_receive_bytes, &cur_transmit_bytes);
|
||||||
|
if (code == 0) {
|
||||||
if(last_receive_bytes >= 0 && last_transmit_bytes >= 0){
|
if(last_receive_bytes >= 0 && last_transmit_bytes >= 0){
|
||||||
*receive_bytes = cur_receive_bytes - last_receive_bytes;
|
*receive_bytes = cur_receive_bytes - last_receive_bytes;
|
||||||
*transmit_bytes = cur_transmit_bytes - last_transmit_bytes;
|
*transmit_bytes = cur_transmit_bytes - last_transmit_bytes;
|
||||||
|
@ -977,9 +995,13 @@ void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
||||||
last_receive_bytes = cur_receive_bytes;
|
last_receive_bytes = cur_receive_bytes;
|
||||||
last_transmit_bytes = cur_transmit_bytes;
|
last_transmit_bytes = cur_transmit_bytes;
|
||||||
} else {
|
} else {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
void taosSetDefaultCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
||||||
*receive_bytes = 0;
|
*receive_bytes = 0;
|
||||||
*transmit_bytes = 0;
|
*transmit_bytes = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosKillSystem() {
|
void taosKillSystem() {
|
||||||
|
|
Loading…
Reference in New Issue