diff --git a/tests/stress_tests/common/tests_utils.cpp b/tests/stress_tests/common/tests_utils.cpp index f872400d897..82cd7c5ab68 100644 --- a/tests/stress_tests/common/tests_utils.cpp +++ b/tests/stress_tests/common/tests_utils.cpp @@ -94,7 +94,7 @@ void runTest(const std::function &tests_pip #if DEBUG_MODE tests_pipeline(params.model, params.device, params.numiters); #else - int status = run_in_processes(params.numprocesses, _runTest, tests_pipeline, params); + int status = run_in_processes(params.numprocesses, [&](){ _runTest(tests_pipeline, params); }); ASSERT_EQ(status, 0) << "Test failed with exitcode " << std::to_string(status); #endif } diff --git a/tests/stress_tests/common/tests_utils.h b/tests/stress_tests/common/tests_utils.h index 62cd8137a14..42cb40fcdf0 100644 --- a/tests/stress_tests/common/tests_utils.h +++ b/tests/stress_tests/common/tests_utils.h @@ -11,8 +11,7 @@ #include #include #include -#include -#include + enum TestStatus { diff --git a/tests/stress_tests/common/utils.cpp b/tests/stress_tests/common/utils.cpp index 4baa8c0f1bb..33a8b392a19 100644 --- a/tests/stress_tests/common/utils.cpp +++ b/tests/stress_tests/common/utils.cpp @@ -7,6 +7,16 @@ #include #include +#ifdef _WIN32 +#include +#include +#include +#else +#include +#include +#endif + + std::string OS_PATH_JOIN(std::initializer_list list) { if (!list.size()) return ""; @@ -37,13 +47,52 @@ static int parseLine(std::string line) { } #ifdef _WIN32 +static PROCESS_MEMORY_COUNTERS getMemoryInfo() { + static PROCESS_MEMORY_COUNTERS pmc; + pmc.cb = sizeof(PROCESS_MEMORY_COUNTERS); + GetProcessMemoryInfo(GetCurrentProcess(),&pmc, pmc.cb); + return pmc; +} + size_t getVmSizeInKB() { - // TODO rewrite for Virtual Memory - PROCESS_MEMORY_COUNTERS pmc; - pmc.cb = sizeof(PROCESS_MEMORY_COUNTERS); - GetProcessMemoryInfo(GetCurrentProcess(),&pmc, pmc.cb); - return pmc.WorkingSetSize; - } + return getMemoryInfo().PagefileUsage / 1024; + } + +size_t getVmPeakInKB() { + return getMemoryInfo().PeakPagefileUsage / 1024; + } + +size_t getVmRSSInKB() { + return getMemoryInfo().WorkingSetSize / 1024; + } + +size_t getVmHWMInKB() { + return getMemoryInfo().PeakWorkingSetSize / 1024; + } + +size_t getThreadsNum() { + // first determine the id of the current process + DWORD const id = GetCurrentProcessId(); + + // then get a process list snapshot. + HANDLE const snapshot = CreateToolhelp32Snapshot( TH32CS_SNAPALL, 0 ); + + // initialize the process entry structure. + PROCESSENTRY32 entry = { 0 }; + entry.dwSize = sizeof( entry ); + + // get the first process info. + BOOL ret = true; + ret = Process32First( snapshot, &entry ); + while( ret && entry.th32ProcessID != id ) { + ret = Process32Next( snapshot, &entry ); + } + CloseHandle( snapshot ); + return ret + ? entry.cntThreads + : -1; + } + #else size_t getSystemDataByName(char *name){ FILE* file = fopen("/proc/self/status", "r"); @@ -70,6 +119,35 @@ size_t getThreadsNum() {return getSystemDataByName((char*) "Threads:");} #endif +int run_in_processes(const int &numprocesses, const std::function &function) { +#ifdef _WIN32 + // TODO: implement run in separate process by using WinAPI + function; + return 0; +#else + std::vector child_pids(numprocesses); + + for (int i = 0; i < numprocesses; i++) { + child_pids[i] = fork(); + if (child_pids[i] == 0) { + function; + exit(EXIT_SUCCESS); + } + } + + int status = 0; + for (int i = 0; i < numprocesses; i++) { + int _status = 0; + waitpid(child_pids[i], &_status, WSTOPPED); + if (_status) { + log_err("Process run # " << i << " failed with exitcode " << _status); + status = _status; + } + } + return status; +#endif +} + void auto_expand_env_vars(std::string &input) { const static std::string pattern1 = "${", pattern2 = "}"; size_t pattern1_pos, pattern2_pos, envvar_start_pos, envvar_finish_pos; diff --git a/tests/stress_tests/common/utils.h b/tests/stress_tests/common/utils.h index 407c9f77cdd..499da23c0ab 100644 --- a/tests/stress_tests/common/utils.h +++ b/tests/stress_tests/common/utils.h @@ -9,8 +9,6 @@ #include #include #include -#include -#include #ifdef _WIN32 #define OS_SEP std::string("\\") @@ -39,29 +37,7 @@ size_t getVmRSSInKB(); size_t getVmHWMInKB(); size_t getThreadsNum(); -template -int run_in_processes(const int &numprocesses, Function const &function, Args ... args) { - std::vector child_pids(numprocesses); - - for (int i = 0; i < numprocesses; i++) { - child_pids[i] = fork(); - if (child_pids[i] == 0) { - function(args...); - exit(EXIT_SUCCESS); - } - } - - int status = 0; - for (int i = 0; i < numprocesses; i++) { - int _status = 0; - waitpid(child_pids[i], &_status, WSTOPPED); - if (_status) { - log_err("Process run # " << i << " failed with exitcode " << _status); - status = _status; - } - } - return status; -} +int run_in_processes(const int &numprocesses, const std::function &function); template inline void run_in_threads(const int &numthreads, Function const &function, Args ... args) { diff --git a/tests/stress_tests/memcheck_tests/tests_utils.h b/tests/stress_tests/memcheck_tests/tests_utils.h index 2ca9210c350..2f40b21f406 100644 --- a/tests/stress_tests/memcheck_tests/tests_utils.h +++ b/tests/stress_tests/memcheck_tests/tests_utils.h @@ -6,6 +6,7 @@ #include "../common/tests_utils.h" +#include #include // Measure values