mirror of
https://github.com/reactos/reactos.git
synced 2024-12-26 00:54:40 +00:00
- corrected typo in epsapi.h
- CTM: cleaned up to use EPSAPI and the ReactOS DDK svn path=/trunk/; revision=4529
This commit is contained in:
parent
1b1afc9539
commit
336f8e82c1
4 changed files with 36 additions and 236 deletions
|
@ -1,7 +1,7 @@
|
|||
/* $Id: epsapi.h,v 1.1 2003/04/13 03:24:27 hyperion Exp $
|
||||
/* $Id: epsapi.h,v 1.2 2003/04/13 03:57:41 hyperion Exp $
|
||||
*/
|
||||
/*
|
||||
* internal/psapi.h
|
||||
* epsapi.h
|
||||
*
|
||||
* Process Status Helper API, native interface
|
||||
*
|
||||
|
|
|
@ -12,7 +12,7 @@ TARGET_APPTYPE = console
|
|||
|
||||
TARGET_NAME = ctm
|
||||
|
||||
TARGET_SDKLIBS = ntdll.a
|
||||
TARGET_SDKLIBS = epsapi.a ntdll.a
|
||||
|
||||
TARGET_OBJECTS = $(TARGET_NAME).o
|
||||
|
||||
|
|
|
@ -37,6 +37,9 @@
|
|||
#include <process.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ddk/ntddk.h>
|
||||
#include <epsapi.h>
|
||||
|
||||
#include "ctm.h"
|
||||
|
||||
#define MAX_PROC 17
|
||||
|
@ -69,11 +72,13 @@ int scrolled=0; // offset from which process start showing
|
|||
|
||||
#define NEW_CONSOLE
|
||||
|
||||
void *PsaiMalloc(SIZE_T size) { return malloc(size); }
|
||||
void *PsaiRealloc(void *ptr, SIZE_T size) { return realloc(ptr, size); }
|
||||
void PsaiFree(void *ptr) { free(ptr); }
|
||||
|
||||
// Prototypes
|
||||
unsigned int GetKeyPressed();
|
||||
|
||||
|
||||
|
||||
void GetInputOutputHandles()
|
||||
{
|
||||
#ifdef NEW_CONSOLE
|
||||
|
@ -311,14 +316,14 @@ void PerfDataRefresh()
|
|||
ULONG Idx, Idx2;
|
||||
HANDLE hProcess;
|
||||
HANDLE hProcessToken;
|
||||
PSYSTEM_PROCESS_INFORMATION pSPI;
|
||||
PSYSTEM_PROCESSES pSPI;
|
||||
PPERFDATA pPDOld;
|
||||
TCHAR szTemp[MAX_PATH];
|
||||
DWORD dwSize;
|
||||
double CurrentKernelTime;
|
||||
PSYSTEM_PROCESSORTIME_INFO SysProcessorTimeInfo;
|
||||
SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
|
||||
SYSTEM_TIME_INFORMATION SysTimeInfo;
|
||||
SYSTEM_PERFORMANCE_INFO SysPerfInfo;
|
||||
SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo;
|
||||
|
||||
#ifdef TIMES
|
||||
// Get new system time
|
||||
|
@ -333,27 +338,11 @@ void PerfDataRefresh()
|
|||
#endif
|
||||
// Get processor information
|
||||
SysProcessorTimeInfo = (PSYSTEM_PROCESSORTIME_INFO)malloc(sizeof(SYSTEM_PROCESSORTIME_INFO) * 1/*SystemBasicInfo.bKeNumberProcessors*/);
|
||||
status = NtQuerySystemInformation(SystemProcessorTimeInformation, SysProcessorTimeInfo, sizeof(SYSTEM_PROCESSORTIME_INFO) * 1/*SystemBasicInfo.bKeNumberProcessors*/, &ulSize);
|
||||
status = NtQuerySystemInformation(SystemProcessorTimes, SysProcessorTimeInfo, sizeof(SYSTEM_PROCESSORTIME_INFO) * 1/*SystemBasicInfo.bKeNumberProcessors*/, &ulSize);
|
||||
|
||||
|
||||
// Get process information
|
||||
// We don't know how much data there is so just keep
|
||||
// increasing the buffer size until the call succeeds
|
||||
BufferSize = 0;
|
||||
do
|
||||
{
|
||||
BufferSize += 0x10000;
|
||||
//pBuffer = new BYTE[BufferSize];
|
||||
pBuffer = (LPBYTE)malloc(BufferSize);
|
||||
|
||||
status = NtQuerySystemInformation(SystemProcessInformation, pBuffer, BufferSize, &ulSize);
|
||||
|
||||
if (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
|
||||
//delete[] pBuffer;
|
||||
free(pBuffer);
|
||||
}
|
||||
|
||||
} while (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
|
||||
PsaCaptureProcessesAndThreads((PSYSTEM_PROCESSES *)&pBuffer);
|
||||
|
||||
#ifdef TIMES
|
||||
for (CurrentKernelTime=0, Idx=0; Idx<1/*SystemBasicInfo.bKeNumberProcessors*/; Idx++) {
|
||||
|
@ -367,7 +356,7 @@ void PerfDataRefresh()
|
|||
// CurrentValue = NewValue - OldValue
|
||||
dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) - Li2Double(liOldIdleTime);
|
||||
dbKernelTime = CurrentKernelTime - OldKernelTime;
|
||||
dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime);
|
||||
dbSystemTime = Li2Double(SysTimeInfo.CurrentTime) - Li2Double(liOldSystemTime);
|
||||
|
||||
// CurrentCpuIdle = IdleTime / SystemTime
|
||||
dbIdleTime = dbIdleTime / dbSystemTime;
|
||||
|
@ -380,21 +369,20 @@ void PerfDataRefresh()
|
|||
|
||||
// Store new CPU's idle and system time
|
||||
liOldIdleTime = SysPerfInfo.liIdleTime;
|
||||
liOldSystemTime = SysTimeInfo.liKeSystemTime;
|
||||
liOldSystemTime = SysTimeInfo.CurrentTime;
|
||||
OldKernelTime = CurrentKernelTime;
|
||||
#endif
|
||||
|
||||
// Determine the process count
|
||||
// We loop through the data we got from NtQuerySystemInformation
|
||||
// and count how many structures there are (until RelativeOffset is 0)
|
||||
// We loop through the data we got from PsaCaptureProcessesAndThreads
|
||||
// and count how many structures there are (until PsaWalkNextProcess
|
||||
// returns NULL)
|
||||
ProcessCountOld = ProcessCount;
|
||||
ProcessCount = 0;
|
||||
pSPI = (PSYSTEM_PROCESS_INFORMATION)pBuffer;
|
||||
pSPI = PsaWalkFirstProcess((PSYSTEM_PROCESSES)pBuffer);
|
||||
while (pSPI) {
|
||||
ProcessCount++;
|
||||
if (pSPI->RelativeOffset == 0)
|
||||
break;
|
||||
pSPI = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pSPI + pSPI->RelativeOffset);
|
||||
pSPI = PsaWalkNextProcess(pSPI);
|
||||
}
|
||||
|
||||
// Now alloc a new PERFDATA array and fill in the data
|
||||
|
@ -405,7 +393,7 @@ void PerfDataRefresh()
|
|||
pPerfDataOld = pPerfData;
|
||||
//pPerfData = new PERFDATA[ProcessCount];
|
||||
pPerfData = (PPERFDATA)malloc(sizeof(PERFDATA) * ProcessCount);
|
||||
pSPI = (PSYSTEM_PROCESS_INFORMATION)pBuffer;
|
||||
pSPI = PsaWalkFirstProcess((PSYSTEM_PROCESSES)pBuffer);
|
||||
for (Idx=0; Idx<ProcessCount; Idx++) {
|
||||
// Get the old perf data for this process (if any)
|
||||
// so that we can establish delta values
|
||||
|
@ -420,8 +408,8 @@ void PerfDataRefresh()
|
|||
// Clear out process perf data structure
|
||||
memset(&pPerfData[Idx], 0, sizeof(PERFDATA));
|
||||
|
||||
if (pSPI->Name.Buffer)
|
||||
wcsncpy(pPerfData[Idx].ImageName, pSPI->Name.Buffer, pSPI->Name.MaximumLength);
|
||||
if (pSPI->ProcessName.Buffer)
|
||||
wcsncpy(pPerfData[Idx].ImageName, pSPI->ProcessName.Buffer, pSPI->ProcessName.MaximumLength);
|
||||
else
|
||||
wcscpy(pPerfData[Idx].ImageName, L"System Idle Process");
|
||||
|
||||
|
@ -441,24 +429,24 @@ void PerfDataRefresh()
|
|||
}
|
||||
|
||||
pPerfData[Idx].CPUTime.QuadPart = pSPI->UserTime.QuadPart + pSPI->KernelTime.QuadPart;
|
||||
pPerfData[Idx].WorkingSetSizeBytes = pSPI->TotalWorkingSetSizeBytes;
|
||||
pPerfData[Idx].PeakWorkingSetSizeBytes = pSPI->PeakWorkingSetSizeBytes;
|
||||
pPerfData[Idx].WorkingSetSizeBytes = pSPI->VmCounters.WorkingSetSize;
|
||||
pPerfData[Idx].PeakWorkingSetSizeBytes = pSPI->VmCounters.PeakWorkingSetSize;
|
||||
if (pPDOld)
|
||||
pPerfData[Idx].WorkingSetSizeDelta = labs((LONG)pSPI->TotalWorkingSetSizeBytes - (LONG)pPDOld->WorkingSetSizeBytes);
|
||||
pPerfData[Idx].WorkingSetSizeDelta = labs((LONG)pSPI->VmCounters.WorkingSetSize - (LONG)pPDOld->WorkingSetSizeBytes);
|
||||
else
|
||||
pPerfData[Idx].WorkingSetSizeDelta = 0;
|
||||
pPerfData[Idx].PageFaultCount = pSPI->PageFaultCount;
|
||||
pPerfData[Idx].PageFaultCount = pSPI->VmCounters.PageFaultCount;
|
||||
if (pPDOld)
|
||||
pPerfData[Idx].PageFaultCountDelta = labs((LONG)pSPI->PageFaultCount - (LONG)pPDOld->PageFaultCount);
|
||||
pPerfData[Idx].PageFaultCountDelta = labs((LONG)pSPI->VmCounters.PageFaultCount - (LONG)pPDOld->PageFaultCount);
|
||||
else
|
||||
pPerfData[Idx].PageFaultCountDelta = 0;
|
||||
pPerfData[Idx].VirtualMemorySizeBytes = pSPI->TotalVirtualSizeBytes;
|
||||
pPerfData[Idx].PagedPoolUsagePages = pSPI->TotalPagedPoolUsagePages;
|
||||
pPerfData[Idx].NonPagedPoolUsagePages = pSPI->TotalNonPagedPoolUsagePages;
|
||||
pPerfData[Idx].VirtualMemorySizeBytes = pSPI->VmCounters.VirtualSize;
|
||||
pPerfData[Idx].PagedPoolUsagePages = pSPI->VmCounters.QuotaPagedPoolUsage;
|
||||
pPerfData[Idx].NonPagedPoolUsagePages = pSPI->VmCounters.QuotaNonPagedPoolUsage;
|
||||
pPerfData[Idx].BasePriority = pSPI->BasePriority;
|
||||
pPerfData[Idx].HandleCount = pSPI->HandleCount;
|
||||
pPerfData[Idx].ThreadCount = pSPI->ThreadCount;
|
||||
pPerfData[Idx].SessionId = pSPI->SessionId;
|
||||
//pPerfData[Idx].SessionId = pSPI->SessionId;
|
||||
|
||||
#ifdef EXTRA_INFO
|
||||
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pSPI->ProcessId);
|
||||
|
@ -491,10 +479,10 @@ int MultiByteToWideChar(
|
|||
pPerfData[Idx].UserTime.QuadPart = pSPI->UserTime.QuadPart;
|
||||
pPerfData[Idx].KernelTime.QuadPart = pSPI->KernelTime.QuadPart;
|
||||
#endif
|
||||
pSPI = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pSPI + pSPI->RelativeOffset);
|
||||
pSPI = PsaWalkNextProcess(pSPI);
|
||||
}
|
||||
//delete[] pBuffer;
|
||||
free(pBuffer);
|
||||
PsaFreeCapture(pBuffer);
|
||||
|
||||
free(SysProcessorTimeInfo);
|
||||
}
|
||||
|
|
|
@ -24,38 +24,6 @@
|
|||
#ifndef TMTM_H
|
||||
#define TMTM_H
|
||||
|
||||
// keys
|
||||
/*
|
||||
#define VK_Q 0x51
|
||||
#define VK_K 0x4B
|
||||
#define VK_Y 0x59
|
||||
#define VK_LEFT 0x25
|
||||
#define VK_UP 0x26
|
||||
#define VK_RIGHT 0x27
|
||||
#define VK_DOWN 0x28
|
||||
*/
|
||||
|
||||
//typedef ULARGE_INTEGER TIME, *PTIME;
|
||||
|
||||
/*
|
||||
|
||||
typedef struct _UNICODE_STRING {
|
||||
USHORT Length;
|
||||
USHORT MaximumLength;
|
||||
PWSTR Buffer;
|
||||
} UNICODE_STRING, *PUNICODE_STRING;
|
||||
|
||||
*/
|
||||
|
||||
#define SystemBasicInformation 0
|
||||
#define SystemPerformanceInformation 2
|
||||
#define SystemTimeInformation 3
|
||||
#define SystemProcessInformation 5
|
||||
#define SystemProcessorTimeInformation 8
|
||||
#define SystemHandleInformation 16
|
||||
#define SystemPageFileInformation 18
|
||||
#define SystemCacheInformation 21
|
||||
|
||||
#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart))
|
||||
|
||||
typedef struct _PERFDATA
|
||||
|
@ -85,160 +53,4 @@ typedef struct _PERFDATA
|
|||
TIME KernelTime;
|
||||
} PERFDATA, *PPERFDATA;
|
||||
|
||||
typedef struct SYSTEM_PROCESS_INFORMATION
|
||||
{
|
||||
ULONG RelativeOffset;
|
||||
ULONG ThreadCount;
|
||||
ULONG Unused1 [6];
|
||||
TIME CreateTime;
|
||||
TIME UserTime;
|
||||
TIME KernelTime;
|
||||
UNICODE_STRING Name;
|
||||
ULONG BasePriority;
|
||||
ULONG ProcessId;
|
||||
ULONG ParentProcessId;
|
||||
ULONG HandleCount;
|
||||
ULONG SessionId;
|
||||
ULONG Unused2;
|
||||
ULONG PeakVirtualSizeBytes;
|
||||
ULONG TotalVirtualSizeBytes;
|
||||
ULONG PageFaultCount;
|
||||
ULONG PeakWorkingSetSizeBytes;
|
||||
ULONG TotalWorkingSetSizeBytes;
|
||||
ULONG PeakPagedPoolUsagePages;
|
||||
ULONG TotalPagedPoolUsagePages;
|
||||
ULONG PeakNonPagedPoolUsagePages;
|
||||
ULONG TotalNonPagedPoolUsagePages;
|
||||
ULONG TotalPageFileUsageBytes;
|
||||
ULONG PeakPageFileUsageBytes;
|
||||
ULONG TotalPrivateBytes;
|
||||
//SYSTEM_THREAD_INFORMATION ThreadSysInfo [1];
|
||||
} SYSTEM_PROCESS_INFORMATION, *PSYSTEM_PROCESS_INFORMATION;
|
||||
|
||||
/*
|
||||
typedef
|
||||
struct _SYSTEM_PROCESSORTIME_INFO
|
||||
{
|
||||
LARGE_INTEGER IdleTime;
|
||||
LARGE_INTEGER KernelTime;
|
||||
LARGE_INTEGER UserTime;
|
||||
LARGE_INTEGER DpcTime;
|
||||
LARGE_INTEGER InterruptTime;
|
||||
ULONG InterruptCount;
|
||||
ULONG Unused;
|
||||
|
||||
} SYSTEM_PROCESSORTIME_INFO, *PSYSTEM_PROCESSORTIME_INFO;
|
||||
*/
|
||||
|
||||
|
||||
// SystemPerformanceInfo (2)
|
||||
typedef struct SYSTEM_PERFORMANCE_INFORMATION
|
||||
{
|
||||
LARGE_INTEGER liIdleTime; //TotalProcessorTime
|
||||
LARGE_INTEGER IoReadTransferCount;
|
||||
LARGE_INTEGER IoWriteTransferCount;
|
||||
LARGE_INTEGER IoOtherTransferCount;
|
||||
ULONG IoReadOperationCount;
|
||||
ULONG IoWriteOperationCount;
|
||||
ULONG IoOtherOperationCount;
|
||||
ULONG MmAvailablePages;
|
||||
ULONG MmTotalCommitedPages;
|
||||
ULONG MmTotalCommitLimit;
|
||||
ULONG MmPeakLimit;
|
||||
ULONG PageFaults;
|
||||
ULONG WriteCopies;
|
||||
ULONG TransitionFaults;
|
||||
ULONG Unknown1;
|
||||
ULONG DemandZeroFaults;
|
||||
ULONG PagesInput;
|
||||
ULONG PagesRead;
|
||||
ULONG Unknown2;
|
||||
ULONG Unknown3;
|
||||
ULONG PagesOutput;
|
||||
ULONG PageWrites;
|
||||
ULONG Unknown4;
|
||||
ULONG Unknown5;
|
||||
ULONG PoolPagedBytes;
|
||||
ULONG PoolNonPagedBytes;
|
||||
ULONG Unknown6;
|
||||
ULONG Unknown7;
|
||||
ULONG Unknown8;
|
||||
ULONG Unknown9;
|
||||
ULONG MmTotalSystemFreePtes;
|
||||
ULONG MmSystemCodepage;
|
||||
ULONG MmTotalSystemDriverPages;
|
||||
ULONG MmTotalSystemCodePages;
|
||||
ULONG Unknown10;
|
||||
ULONG Unknown11;
|
||||
ULONG Unknown12;
|
||||
ULONG MmSystemCachePage;
|
||||
ULONG MmPagedPoolPage;
|
||||
ULONG MmSystemDriverPage;
|
||||
ULONG CcFastReadNoWait;
|
||||
ULONG CcFastReadWait;
|
||||
ULONG CcFastReadResourceMiss;
|
||||
ULONG CcFastReadNotPossible;
|
||||
ULONG CcFastMdlReadNoWait;
|
||||
ULONG CcFastMdlReadWait;
|
||||
ULONG CcFastMdlReadResourceMiss;
|
||||
ULONG CcFastMdlReadNotPossible;
|
||||
ULONG CcMapDataNoWait;
|
||||
ULONG CcMapDataWait;
|
||||
ULONG CcMapDataNoWaitMiss;
|
||||
ULONG CcMapDataWaitMiss;
|
||||
ULONG CcPinMappedDataCount;
|
||||
ULONG CcPinReadNoWait;
|
||||
ULONG CcPinReadWait;
|
||||
ULONG CcPinReadNoWaitMiss;
|
||||
ULONG CcPinReadWaitMiss;
|
||||
ULONG CcCopyReadNoWait;
|
||||
ULONG CcCopyReadWait;
|
||||
ULONG CcCopyReadNoWaitMiss;
|
||||
ULONG CcCopyReadWaitMiss;
|
||||
ULONG CcMdlReadNoWait;
|
||||
ULONG CcMdlReadWait;
|
||||
ULONG CcMdlReadNoWaitMiss;
|
||||
ULONG CcMdlReadWaitMiss;
|
||||
ULONG CcReadaheadIos;
|
||||
ULONG CcLazyWriteIos;
|
||||
ULONG CcLazyWritePages;
|
||||
ULONG CcDataFlushes;
|
||||
ULONG CcDataPages;
|
||||
ULONG ContextSwitches;
|
||||
ULONG Unknown13;
|
||||
ULONG Unknown14;
|
||||
ULONG SystemCalls;
|
||||
|
||||
} SYSTEM_PERFORMANCE_INFORMATION, *PSYSTEM_PERFORMANCE_INFORMATION;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
LARGE_INTEGER liKeBootTime;
|
||||
LARGE_INTEGER liKeSystemTime;
|
||||
LARGE_INTEGER liExpTimeZoneBias;
|
||||
ULONG uCurrentTimeZoneId;
|
||||
DWORD dwReserved;
|
||||
} SYSTEM_TIME_INFORMATION;
|
||||
|
||||
|
||||
// ntdll!NtQuerySystemInformation (NT specific!)
|
||||
//
|
||||
// The function copies the system information of the
|
||||
// specified type into a buffer
|
||||
//
|
||||
// NTSYSAPI
|
||||
// NTSTATUS
|
||||
// NTAPI
|
||||
// NtQuerySystemInformation(
|
||||
// IN UINT SystemInformationClass, // information type
|
||||
// OUT PVOID SystemInformation, // pointer to buffer
|
||||
// IN ULONG SystemInformationLength, // buffer size in bytes
|
||||
// OUT PULONG ReturnLength OPTIONAL // pointer to a 32-bit
|
||||
// // variable that receives
|
||||
// // the number of bytes
|
||||
// // written to the buffer
|
||||
// );
|
||||
typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue