Fixedd CTM for sedwards. happy birthday to me

svn path=/trunk/; revision=14815
This commit is contained in:
Alex Ionescu 2005-04-26 13:17:44 +00:00
parent d54cf3af82
commit c6c78c3133

View file

@ -353,12 +353,12 @@ void PerfDataRefresh()
ULONG Idx, Idx2; ULONG Idx, Idx2;
HANDLE hProcess; HANDLE hProcess;
HANDLE hProcessToken; HANDLE hProcessToken;
PSYSTEM_PROCESSES pSPI; PSYSTEM_PROCESS_INFORMATION pSPI;
PPERFDATA pPDOld; PPERFDATA pPDOld;
TCHAR szTemp[MAX_PATH]; TCHAR szTemp[MAX_PATH];
DWORD dwSize; DWORD dwSize;
double CurrentKernelTime; double CurrentKernelTime;
PSYSTEM_PROCESSORTIME_INFO SysProcessorTimeInfo; PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SysProcessorTimeInfo;
SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo; SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo; SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo;
@ -374,18 +374,18 @@ void PerfDataRefresh()
return; return;
#endif #endif
// Get processor information // Get processor information
SysProcessorTimeInfo = (PSYSTEM_PROCESSORTIME_INFO)malloc(sizeof(SYSTEM_PROCESSORTIME_INFO) * SystemBasicInfo.NumberProcessors); SysProcessorTimeInfo = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)malloc(sizeof(PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * SystemBasicInfo.NumberProcessors);
status = NtQuerySystemInformation(SystemProcessorTimes, SysProcessorTimeInfo, sizeof(SYSTEM_PROCESSORTIME_INFO) * SystemBasicInfo.NumberProcessors, &ulSize); status = NtQuerySystemInformation(SystemProcessorTimes, SysProcessorTimeInfo, sizeof(PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * SystemBasicInfo.NumberProcessors, &ulSize);
// Get process information // Get process information
PsaCaptureProcessesAndThreads((PSYSTEM_PROCESSES *)&pBuffer); PsaCaptureProcessesAndThreads((PSYSTEM_PROCESS_INFORMATION *)&pBuffer);
#ifdef TIMES #ifdef TIMES
for (CurrentKernelTime=0, Idx=0; Idx<SystemBasicInfo.NumberProcessors; Idx++) { for (CurrentKernelTime=0, Idx=0; Idx<SystemBasicInfo.NumberProcessors; Idx++) {
CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].TotalProcessorTime); CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].KernelTime);
CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].TotalDPCTime); CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].DpcTime);
CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].TotalInterruptTime); CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].InterruptTime);
} }
// If it's a first call - skip idle time calcs // If it's a first call - skip idle time calcs
@ -416,7 +416,7 @@ void PerfDataRefresh()
// returns NULL) // returns NULL)
ProcessCountOld = ProcessCount; ProcessCountOld = ProcessCount;
ProcessCount = 0; ProcessCount = 0;
pSPI = PsaWalkFirstProcess((PSYSTEM_PROCESSES)pBuffer); pSPI = PsaWalkFirstProcess((PSYSTEM_PROCESS_INFORMATION)pBuffer);
while (pSPI) { while (pSPI) {
ProcessCount++; ProcessCount++;
pSPI = PsaWalkNextProcess(pSPI); pSPI = PsaWalkNextProcess(pSPI);
@ -428,13 +428,13 @@ void PerfDataRefresh()
} }
pPerfDataOld = pPerfData; pPerfDataOld = pPerfData;
pPerfData = (PPERFDATA)malloc(sizeof(PERFDATA) * ProcessCount); pPerfData = (PPERFDATA)malloc(sizeof(PERFDATA) * ProcessCount);
pSPI = PsaWalkFirstProcess((PSYSTEM_PROCESSES)pBuffer); pSPI = PsaWalkFirstProcess((PSYSTEM_PROCESS_INFORMATION)pBuffer);
for (Idx=0; Idx<ProcessCount; Idx++) { for (Idx=0; Idx<ProcessCount; Idx++) {
// Get the old perf data for this process (if any) // Get the old perf data for this process (if any)
// 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->ProcessId) { if (pPerfDataOld[Idx2].ProcessId == pSPI->UniqueProcessId) {
pPDOld = &pPerfDataOld[Idx2]; pPDOld = &pPerfDataOld[Idx2];
break; break;
} }
@ -443,9 +443,9 @@ void PerfDataRefresh()
// Clear out process perf data structure // Clear out process perf data structure
memset(&pPerfData[Idx], 0, sizeof(PERFDATA)); memset(&pPerfData[Idx], 0, sizeof(PERFDATA));
if (pSPI->ProcessName.Buffer) { if (pSPI->ImageName.Buffer) {
wcsncpy(pPerfData[Idx].ImageName, pSPI->ProcessName.Buffer, pSPI->ProcessName.Length / sizeof(WCHAR)); wcsncpy(pPerfData[Idx].ImageName, pSPI->ImageName.Buffer, pSPI->ImageName.Length / sizeof(WCHAR));
pPerfData[Idx].ImageName[pSPI->ProcessName.Length / sizeof(WCHAR)] = 0; pPerfData[Idx].ImageName[pSPI->ImageName.Length / sizeof(WCHAR)] = 0;
} }
else else
{ {
@ -456,7 +456,7 @@ void PerfDataRefresh()
#endif #endif
} }
pPerfData[Idx].ProcessId = pSPI->ProcessId; pPerfData[Idx].ProcessId = pSPI->UniqueProcessId;
if (pPDOld) { if (pPDOld) {
#ifdef TIMES #ifdef TIMES
@ -472,27 +472,27 @@ void PerfDataRefresh()
} }
pPerfData[Idx].CPUTime.QuadPart = pSPI->UserTime.QuadPart + pSPI->KernelTime.QuadPart; pPerfData[Idx].CPUTime.QuadPart = pSPI->UserTime.QuadPart + pSPI->KernelTime.QuadPart;
pPerfData[Idx].WorkingSetSizeBytes = pSPI->VmCounters.WorkingSetSize; pPerfData[Idx].WorkingSetSizeBytes = pSPI->WorkingSetSize;
pPerfData[Idx].PeakWorkingSetSizeBytes = pSPI->VmCounters.PeakWorkingSetSize; pPerfData[Idx].PeakWorkingSetSizeBytes = pSPI->PeakWorkingSetSize;
if (pPDOld) if (pPDOld)
pPerfData[Idx].WorkingSetSizeDelta = labs((LONG)pSPI->VmCounters.WorkingSetSize - (LONG)pPDOld->WorkingSetSizeBytes); pPerfData[Idx].WorkingSetSizeDelta = labs((LONG)pSPI->WorkingSetSize - (LONG)pPDOld->WorkingSetSizeBytes);
else else
pPerfData[Idx].WorkingSetSizeDelta = 0; pPerfData[Idx].WorkingSetSizeDelta = 0;
pPerfData[Idx].PageFaultCount = pSPI->VmCounters.PageFaultCount; pPerfData[Idx].PageFaultCount = pSPI->PageFaultCount;
if (pPDOld) if (pPDOld)
pPerfData[Idx].PageFaultCountDelta = labs((LONG)pSPI->VmCounters.PageFaultCount - (LONG)pPDOld->PageFaultCount); pPerfData[Idx].PageFaultCountDelta = labs((LONG)pSPI->PageFaultCount - (LONG)pPDOld->PageFaultCount);
else else
pPerfData[Idx].PageFaultCountDelta = 0; pPerfData[Idx].PageFaultCountDelta = 0;
pPerfData[Idx].VirtualMemorySizeBytes = pSPI->VmCounters.VirtualSize; pPerfData[Idx].VirtualMemorySizeBytes = pSPI->VirtualSize;
pPerfData[Idx].PagedPoolUsagePages = pSPI->VmCounters.QuotaPagedPoolUsage; pPerfData[Idx].PagedPoolUsagePages = pSPI->QuotaPagedPoolUsage;
pPerfData[Idx].NonPagedPoolUsagePages = pSPI->VmCounters.QuotaNonPagedPoolUsage; pPerfData[Idx].NonPagedPoolUsagePages = pSPI->QuotaNonPagedPoolUsage;
pPerfData[Idx].BasePriority = pSPI->BasePriority; pPerfData[Idx].BasePriority = pSPI->BasePriority;
pPerfData[Idx].HandleCount = pSPI->HandleCount; pPerfData[Idx].HandleCount = pSPI->HandleCount;
pPerfData[Idx].ThreadCount = pSPI->ThreadCount; pPerfData[Idx].ThreadCount = pSPI->NumberOfThreads;
//pPerfData[Idx].SessionId = pSPI->SessionId; //pPerfData[Idx].SessionId = pSPI->SessionId;
#ifdef EXTRA_INFO #ifdef EXTRA_INFO
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pSPI->ProcessId); hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pSPI->UniqueProcessId);
if (hProcess) { if (hProcess) {
if (OpenProcessToken(hProcess, TOKEN_QUERY|TOKEN_DUPLICATE|TOKEN_IMPERSONATE, &hProcessToken)) { if (OpenProcessToken(hProcess, TOKEN_QUERY|TOKEN_DUPLICATE|TOKEN_IMPERSONATE, &hProcessToken)) {
ImpersonateLoggedOnUser(hProcessToken); ImpersonateLoggedOnUser(hProcessToken);