%CPU and Memory footprint question
-
In a multithreaded VC++ program, how can I find %of CPU/ thread from within the program and report it? Also how can I find the memory footprint of the process from within the program? Is it possible? (Not using any external tools like perfmon, just using C++ code from the program itself)
-
In a multithreaded VC++ program, how can I find %of CPU/ thread from within the program and report it? Also how can I find the memory footprint of the process from within the program? Is it possible? (Not using any external tools like perfmon, just using C++ code from the program itself)
For memory usage check out
GetProcessMemoryInfo()
(NT 4 or later) --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas." -- Buffy -
For memory usage check out
GetProcessMemoryInfo()
(NT 4 or later) --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas." -- BuffyThanks. How to find the %CPU/thread? HANDLE hProcess; PROCESS_MEMORY_COUNTERS pmc; DWORD processID = GetCurrentProcessId (); hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); if (NULL == hProcess) return; if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) { printf( "\tPeakWorkingSetSize: 0x%08X\n", pmc.PeakWorkingSetSize ); }
-
Thanks. How to find the %CPU/thread? HANDLE hProcess; PROCESS_MEMORY_COUNTERS pmc; DWORD processID = GetCurrentProcessId (); hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); if (NULL == hProcess) return; if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) { printf( "\tPeakWorkingSetSize: 0x%08X\n", pmc.PeakWorkingSetSize ); }
I found that using PDH these can be done. Was wondering if this can be done for individual processes, from within the program. HQUERY m_hQuery; // the query to the PDH PdhOpenQuery(NULL, 1, &m_hQuery); PdhAddCounter(....) How to use above function for individual processes?