mirror of
https://github.com/reactos/reactos.git
synced 2024-12-26 17:14:41 +00:00
- 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
This commit is contained in:
parent
946594bdc0
commit
c087372392
2 changed files with 30 additions and 22 deletions
|
@ -78,7 +78,7 @@ double dbIdleTime;
|
||||||
double dbKernelTime;
|
double dbKernelTime;
|
||||||
double dbSystemTime;
|
double dbSystemTime;
|
||||||
LARGE_INTEGER liOldIdleTime = {{0,0}};
|
LARGE_INTEGER liOldIdleTime = {{0,0}};
|
||||||
double OldKernelTime = 0;
|
LARGE_INTEGER liOldKernelTime = {{0,0}};
|
||||||
LARGE_INTEGER liOldSystemTime = {{0,0}};
|
LARGE_INTEGER liOldSystemTime = {{0,0}};
|
||||||
|
|
||||||
PPERFDATA pPerfDataOld = NULL; // Older perf data (saved to establish delta values)
|
PPERFDATA pPerfDataOld = NULL; // Older perf data (saved to establish delta values)
|
||||||
|
@ -357,43 +357,47 @@ void PerfDataRefresh()
|
||||||
PPERFDATA pPDOld;
|
PPERFDATA pPDOld;
|
||||||
TCHAR szTemp[MAX_PATH];
|
TCHAR szTemp[MAX_PATH];
|
||||||
DWORD dwSize;
|
DWORD dwSize;
|
||||||
double CurrentKernelTime;
|
#ifdef TIMES
|
||||||
|
LARGE_INTEGER liCurrentKernelTime;
|
||||||
|
LARGE_INTEGER liCurrentIdleTime;
|
||||||
|
LARGE_INTEGER liCurrentTime;
|
||||||
|
#endif
|
||||||
PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SysProcessorTimeInfo;
|
PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SysProcessorTimeInfo;
|
||||||
SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
|
SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo;
|
||||||
SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo;
|
|
||||||
|
|
||||||
#ifdef TIMES
|
#ifdef TIMES
|
||||||
// Get new system time
|
// Get new system time
|
||||||
status = NtQuerySystemInformation(SystemTimeInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0);
|
status = NtQuerySystemInformation(SystemTimeInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0);
|
||||||
if (status != NO_ERROR)
|
if (status != NO_ERROR)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Get new CPU's idle time
|
|
||||||
status = NtQuerySystemInformation(SystemPerformanceInformation, &SysPerfInfo, sizeof(SysPerfInfo), NULL);
|
|
||||||
if (status != NO_ERROR)
|
|
||||||
return;
|
|
||||||
#endif
|
#endif
|
||||||
// Get processor information
|
// Get processor information
|
||||||
SysProcessorTimeInfo = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)malloc(sizeof(PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * SystemBasicInfo.NumberProcessors);
|
SysProcessorTimeInfo = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)malloc(sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * SystemBasicInfo.NumberProcessors);
|
||||||
status = NtQuerySystemInformation(SystemProcessorTimes, SysProcessorTimeInfo, sizeof(PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * SystemBasicInfo.NumberProcessors, &ulSize);
|
status = NtQuerySystemInformation(SystemProcessorPerformanceInformation, SysProcessorTimeInfo, sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * SystemBasicInfo.NumberProcessors, &ulSize);
|
||||||
|
|
||||||
|
|
||||||
// Get process information
|
// Get process information
|
||||||
PsaCaptureProcessesAndThreads((PSYSTEM_PROCESS_INFORMATION *)&pBuffer);
|
PsaCaptureProcessesAndThreads((PSYSTEM_PROCESS_INFORMATION *)&pBuffer);
|
||||||
|
|
||||||
#ifdef TIMES
|
#ifdef TIMES
|
||||||
for (CurrentKernelTime=0, Idx=0; Idx<SystemBasicInfo.NumberProcessors; Idx++) {
|
liCurrentKernelTime.QuadPart = 0;
|
||||||
CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].KernelTime);
|
liCurrentIdleTime.QuadPart = 0;
|
||||||
CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].DpcTime);
|
for (Idx=0; Idx<SystemBasicInfo.NumberProcessors; Idx++) {
|
||||||
CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].InterruptTime);
|
liCurrentKernelTime.QuadPart += SysProcessorTimeInfo[Idx].KernelTime.QuadPart;
|
||||||
|
liCurrentKernelTime.QuadPart += SysProcessorTimeInfo[Idx].DpcTime.QuadPart;
|
||||||
|
liCurrentKernelTime.QuadPart += SysProcessorTimeInfo[Idx].InterruptTime.QuadPart;
|
||||||
|
liCurrentIdleTime.QuadPart += SysProcessorTimeInfo[Idx].IdleTime.QuadPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's a first call - skip idle time calcs
|
// If it's a first call - skip idle time calcs
|
||||||
if (liOldIdleTime.QuadPart != 0) {
|
if (liOldIdleTime.QuadPart != 0) {
|
||||||
// CurrentValue = NewValue - OldValue
|
// CurrentValue = NewValue - OldValue
|
||||||
dbIdleTime = Li2Double(SysPerfInfo.IdleTime) - Li2Double(liOldIdleTime);
|
liCurrentTime.QuadPart = liCurrentIdleTime.QuadPart - liOldIdleTime.QuadPart;
|
||||||
dbKernelTime = CurrentKernelTime - OldKernelTime;
|
dbIdleTime = Li2Double(liCurrentTime);
|
||||||
dbSystemTime = Li2Double(SysTimeInfo.CurrentTime) - Li2Double(liOldSystemTime);
|
liCurrentTime.QuadPart = liCurrentKernelTime.QuadPart - liOldKernelTime.QuadPart;
|
||||||
|
dbKernelTime = Li2Double(liCurrentTime);
|
||||||
|
liCurrentTime.QuadPart = SysTimeInfo.CurrentTime.QuadPart - liOldSystemTime.QuadPart;
|
||||||
|
dbSystemTime = Li2Double(liCurrentTime);
|
||||||
|
|
||||||
// CurrentCpuIdle = IdleTime / SystemTime
|
// CurrentCpuIdle = IdleTime / SystemTime
|
||||||
dbIdleTime = dbIdleTime / dbSystemTime;
|
dbIdleTime = dbIdleTime / dbSystemTime;
|
||||||
|
@ -405,9 +409,9 @@ void PerfDataRefresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store new CPU's idle and system time
|
// Store new CPU's idle and system time
|
||||||
liOldIdleTime = SysPerfInfo.IdleTime;
|
liOldIdleTime = liCurrentIdleTime;
|
||||||
liOldSystemTime = SysTimeInfo.CurrentTime;
|
liOldSystemTime = SysTimeInfo.CurrentTime;
|
||||||
OldKernelTime = CurrentKernelTime;
|
liOldKernelTime = liCurrentKernelTime;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Determine the process count
|
// Determine the process count
|
||||||
|
@ -434,7 +438,9 @@ void PerfDataRefresh()
|
||||||
// so that we can establish delta values
|
// so that we can establish delta values
|
||||||
pPDOld = NULL;
|
pPDOld = NULL;
|
||||||
for (Idx2=0; Idx2<ProcessCountOld; Idx2++) {
|
for (Idx2=0; Idx2<ProcessCountOld; Idx2++) {
|
||||||
if (pPerfDataOld[Idx2].ProcessId == pSPI->UniqueProcessId) {
|
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];
|
pPDOld = &pPerfDataOld[Idx2];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -456,7 +462,8 @@ void PerfDataRefresh()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
pPerfData[Idx].ProcessId = pSPI->UniqueProcessId;
|
pPerfData[Idx].ProcessId = (ULONG)(pSPI->UniqueProcessId);
|
||||||
|
pPerfData[Idx].CreateTime = pSPI->CreateTime;
|
||||||
|
|
||||||
if (pPDOld) {
|
if (pPDOld) {
|
||||||
#ifdef TIMES
|
#ifdef TIMES
|
||||||
|
|
|
@ -51,6 +51,7 @@ typedef struct _PERFDATA
|
||||||
|
|
||||||
TIME UserTime;
|
TIME UserTime;
|
||||||
TIME KernelTime;
|
TIME KernelTime;
|
||||||
|
LARGE_INTEGER CreateTime;
|
||||||
} PERFDATA, *PPERFDATA;
|
} PERFDATA, *PPERFDATA;
|
||||||
|
|
||||||
#define SystemTimeInformation 3
|
#define SystemTimeInformation 3
|
||||||
|
|
Loading…
Reference in a new issue