From 0b310ff3850dcaf06e69c205349c722ed998f2ec Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Tue, 11 Jun 2024 13:21:11 +0800 Subject: [PATCH] fix: build error on windows --- inc/bench.h | 2 ++ src/benchInsert.c | 4 +--- src/benchUtil.c | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/inc/bench.h b/inc/bench.h index 2e9d9951..52874d66 100644 --- a/inc/bench.h +++ b/inc/bench.h @@ -1154,6 +1154,8 @@ int32_t benchParseSingleOpt(int32_t key, char* arg); void printErrCmdCodeStr(char *cmd, int32_t code, TAOS_RES *res); +int32_t benchGetTotalMemory(int64_t *totalKB); + #ifndef LINUX int32_t benchParseArgsNoArgp(int argc, char* argv[]); #endif diff --git a/src/benchInsert.c b/src/benchInsert.c index 106fedb7..64d0a65b 100644 --- a/src/benchInsert.c +++ b/src/benchInsert.c @@ -493,8 +493,6 @@ int32_t getVgroupsOfDb(SBenchConn *conn, SDataBase *database) { } #endif // TD_VER_COMPATIBLE_3_0_0_0 -// export from taos osSysinfo.c -int32_t taosGetTotalMemory(int64_t *totalKB); int32_t toolsGetDefaultVGroups() { int32_t cores = toolsGetNumberOfCores(); @@ -503,7 +501,7 @@ int32_t toolsGetDefaultVGroups() { } int64_t MemKB = 0; - taosGetTotalMemory(&MemKB); + benchGetTotalMemory(&MemKB); infoPrint("check local machine CPU: %d Memory:%d MB \n", cores, (int32_t)(MemKB/1024)); if (MemKB <= 2*1024*1024) { // 2G diff --git a/src/benchUtil.c b/src/benchUtil.c index 156e6a7f..5ebe0913 100644 --- a/src/benchUtil.c +++ b/src/benchUtil.c @@ -1253,3 +1253,22 @@ FORCE_INLINE void printErrCmdCodeStr(char *cmd, int32_t code, TAOS_RES *res) { taos_free_result(res); } +int32_t benchGetTotalMemory(int64_t *totalKB) { +#ifdef WINDOWS + MEMORYSTATUSEX memsStat; + memsStat.dwLength = sizeof(memsStat); + if (!GlobalMemoryStatusEx(&memsStat)) { + return -1; + } + + *totalKB = memsStat.ullTotalPhys / 1024; + return 0; +#elif defined(_TD_DARWIN_64) + *totalKB = 0; + return 0; +#else + int64_t tsPageSizeKB = sysconf(_SC_PAGESIZE) / 1024; + *totalKB = (int64_t)(sysconf(_SC_PHYS_PAGES) * tsPageSizeKB); + return 0; +#endif +}