From a30a353dcbae277d60e3391f086e53c9f2d43cfa Mon Sep 17 00:00:00 2001 From: Hartmut Birr Date: Sat, 15 Jan 2005 20:28:19 +0000 Subject: [PATCH] - Fixed some minor bugs. - Moved the definition for unicode compiling to the make file. - Wait on the input handle instead to poll it every 40ms. - Use the number of cpus for time calculations. svn path=/trunk/; revision=13067 --- rosapps/sysutils/ctm/Makefile | 2 ++ rosapps/sysutils/ctm/ctm.c | 41 +++++++++++++++-------------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/rosapps/sysutils/ctm/Makefile b/rosapps/sysutils/ctm/Makefile index a5c4dcd531d..de2fb6809d5 100644 --- a/rosapps/sysutils/ctm/Makefile +++ b/rosapps/sysutils/ctm/Makefile @@ -16,6 +16,8 @@ TARGET_SDKLIBS = epsapi.a ntdll.a TARGET_OBJECTS = $(TARGET_NAME).o +TARGET_CFLAGS = -DUNICODE -D_UNICODE + include $(PATH_TO_TOP)/rules.mak include $(TOOLS_PATH)/helper.mk diff --git a/rosapps/sysutils/ctm/ctm.c b/rosapps/sysutils/ctm/ctm.c index 41cda52686e..85cbd998221 100644 --- a/rosapps/sysutils/ctm/ctm.c +++ b/rosapps/sysutils/ctm/ctm.c @@ -1,6 +1,3 @@ -#define UNICODE -#define _UNICODE - /* Console Task Manager ctm.c - main program file @@ -90,6 +87,7 @@ PPERFDATA pPerfData = NULL; // Most recent copy of perf data int selection=0; int scrolled=0; // offset from which process start showing int first = 0; // first time in DisplayScreen +SYSTEM_BASIC_INFORMATION SystemBasicInfo; #define NEW_CONSOLE @@ -287,7 +285,7 @@ int ProcessKeys(int numEvents) do { GetNumberOfConsoleInputEvents(hStdin, &pId); key = GetKeyPressed(pId); - } while (key == 0); + } while (key != KEY_YES && key != KEY_NO); if (key == KEY_YES) { @@ -341,6 +339,11 @@ int ProcessKeys(int numEvents) return FALSE; } +void PerfInit() +{ + NtQuerySystemInformation(SystemBasicInformation, &SystemBasicInfo, sizeof(SystemBasicInfo), 0); +} + void PerfDataRefresh() { LONG status; @@ -371,15 +374,15 @@ void PerfDataRefresh() return; #endif // Get processor information - SysProcessorTimeInfo = (PSYSTEM_PROCESSORTIME_INFO)malloc(sizeof(SYSTEM_PROCESSORTIME_INFO) * 1/*SystemBasicInfo.bKeNumberProcessors*/); - status = NtQuerySystemInformation(SystemProcessorTimes, SysProcessorTimeInfo, sizeof(SYSTEM_PROCESSORTIME_INFO) * 1/*SystemBasicInfo.bKeNumberProcessors*/, &ulSize); + SysProcessorTimeInfo = (PSYSTEM_PROCESSORTIME_INFO)malloc(sizeof(SYSTEM_PROCESSORTIME_INFO) * SystemBasicInfo.NumberProcessors); + status = NtQuerySystemInformation(SystemProcessorTimes, SysProcessorTimeInfo, sizeof(SYSTEM_PROCESSORTIME_INFO) * SystemBasicInfo.NumberProcessors, &ulSize); // Get process information PsaCaptureProcessesAndThreads((PSYSTEM_PROCESSES *)&pBuffer); #ifdef TIMES - for (CurrentKernelTime=0, Idx=0; Idx<1/*SystemBasicInfo.bKeNumberProcessors*/; Idx++) { + for (CurrentKernelTime=0, Idx=0; IdxKernelTime) + Li2Double(pSPI->UserTime); double OldTime = Li2Double(pPDOld->KernelTime) + Li2Double(pPDOld->UserTime); double CpuTime = (CurTime - OldTime) / dbSystemTime; - CpuTime = CpuTime * 100.0; /* / (double)SystemBasicInfo.bKeNumberProcessors;// + 0.5;*/ + CpuTime = CpuTime * 100.0 / (double)SystemBasicInfo.NumberProcessors; // + 0.5; pPerfData[Idx].CPUUsage = (ULONG)CpuTime; #else @@ -537,9 +540,6 @@ unsigned int GetKeyPressed(int events) for (i=0; i 0) @@ -664,13 +664,6 @@ int main(int *argc, char **argv) if (ProcessKeys(numEvents) == TRUE) break; } -#if 1 - else - { - /* Should be removed, if WaitForSingleObject is implemented for console handles */ - Sleep(40); // TODO: Should be done more efficient (might be another thread handling input/etc)*/ - } -#endif } RestoreConsole();