From c087372392972693cd9f4683ae902360b68d9a93 Mon Sep 17 00:00:00 2001 From: Hartmut Birr Date: Tue, 26 Apr 2005 16:28:38 +0000 Subject: [PATCH] - Used SysProcessorTimeInfo to calculate the idle time. - Fixed the allocation of SysProcessorTimeInfo. - Used the process creation time as second unique id. svn path=/trunk/; revision=14817 --- rosapps/sysutils/ctm/ctm.c | 51 ++++++++++++++++++++++---------------- rosapps/sysutils/ctm/ctm.h | 1 + 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/rosapps/sysutils/ctm/ctm.c b/rosapps/sysutils/ctm/ctm.c index 0db033de35a..ad58130fd10 100644 --- a/rosapps/sysutils/ctm/ctm.c +++ b/rosapps/sysutils/ctm/ctm.c @@ -78,7 +78,7 @@ double dbIdleTime; double dbKernelTime; double dbSystemTime; LARGE_INTEGER liOldIdleTime = {{0,0}}; -double OldKernelTime = 0; +LARGE_INTEGER liOldKernelTime = {{0,0}}; LARGE_INTEGER liOldSystemTime = {{0,0}}; PPERFDATA pPerfDataOld = NULL; // Older perf data (saved to establish delta values) @@ -357,43 +357,47 @@ void PerfDataRefresh() PPERFDATA pPDOld; TCHAR szTemp[MAX_PATH]; DWORD dwSize; - double CurrentKernelTime; +#ifdef TIMES + LARGE_INTEGER liCurrentKernelTime; + LARGE_INTEGER liCurrentIdleTime; + LARGE_INTEGER liCurrentTime; +#endif PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SysProcessorTimeInfo; - SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo; - SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo; + SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo; #ifdef TIMES // Get new system time status = NtQuerySystemInformation(SystemTimeInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0); if (status != NO_ERROR) return; - - // Get new CPU's idle time - status = NtQuerySystemInformation(SystemPerformanceInformation, &SysPerfInfo, sizeof(SysPerfInfo), NULL); - if (status != NO_ERROR) - return; #endif // Get processor information - SysProcessorTimeInfo = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)malloc(sizeof(PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * SystemBasicInfo.NumberProcessors); - status = NtQuerySystemInformation(SystemProcessorTimes, SysProcessorTimeInfo, sizeof(PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * SystemBasicInfo.NumberProcessors, &ulSize); + SysProcessorTimeInfo = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)malloc(sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * SystemBasicInfo.NumberProcessors); + status = NtQuerySystemInformation(SystemProcessorPerformanceInformation, SysProcessorTimeInfo, sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * SystemBasicInfo.NumberProcessors, &ulSize); // Get process information PsaCaptureProcessesAndThreads((PSYSTEM_PROCESS_INFORMATION *)&pBuffer); #ifdef TIMES - for (CurrentKernelTime=0, Idx=0; IdxUniqueProcessId) { + if (pPerfDataOld[Idx2].ProcessId == (ULONG)(pSPI->UniqueProcessId) && + /* check also for the creation time, a new process may have an id of an old one */ + pPerfDataOld[Idx2].CreateTime.QuadPart == pSPI->CreateTime.QuadPart) { pPDOld = &pPerfDataOld[Idx2]; break; } @@ -456,7 +462,8 @@ void PerfDataRefresh() #endif } - pPerfData[Idx].ProcessId = pSPI->UniqueProcessId; + pPerfData[Idx].ProcessId = (ULONG)(pSPI->UniqueProcessId); + pPerfData[Idx].CreateTime = pSPI->CreateTime; if (pPDOld) { #ifdef TIMES diff --git a/rosapps/sysutils/ctm/ctm.h b/rosapps/sysutils/ctm/ctm.h index b4633fd2d8a..ec1bf311bb1 100644 --- a/rosapps/sysutils/ctm/ctm.h +++ b/rosapps/sysutils/ctm/ctm.h @@ -51,6 +51,7 @@ typedef struct _PERFDATA TIME UserTime; TIME KernelTime; + LARGE_INTEGER CreateTime; } PERFDATA, *PPERFDATA; #define SystemTimeInformation 3 -- 2.17.1