Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: build error on windows benchTotalMemory #753

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions inc/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/benchInsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,31 @@ int32_t getVgroupsOfDb(SBenchConn *conn, SDataBase *database) {
}
#endif // TD_VER_COMPATIBLE_3_0_0_0

int32_t toolsGetDefaultVGroups() {
int32_t cores = toolsGetNumberOfCores();
if (cores < 3 ) {
return 1;
}

int64_t MemKB = 0;
benchGetTotalMemory(&MemKB);

infoPrint("check local machine CPU: %d Memory:%d MB \n", cores, (int32_t)(MemKB/1024));
if (MemKB <= 2*1024*1024) { // 2G
return 1;
} else if (MemKB <= 4*1024*1024) { // 4G
return 2;
} else if (MemKB <= 8*1024*1024) { // 8G
return 3;
} else if (MemKB <= 16*1024*1024) { // 16G
return 4;
} else if (MemKB <= 32*1024*1024) { // 32G
return 5;
} else {
return cores / 2;
}
}

int geneDbCreateCmd(SDataBase *database, char *command, int remainVnodes) {
int dataLen = 0;
int n;
Expand Down
19 changes: 19 additions & 0 deletions src/benchUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading