mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 23:12:56 +00:00
- 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
This commit is contained in:
parent
c30d55149e
commit
a30a353dcb
2 changed files with 19 additions and 24 deletions
|
@ -16,6 +16,8 @@ TARGET_SDKLIBS = epsapi.a ntdll.a
|
||||||
|
|
||||||
TARGET_OBJECTS = $(TARGET_NAME).o
|
TARGET_OBJECTS = $(TARGET_NAME).o
|
||||||
|
|
||||||
|
TARGET_CFLAGS = -DUNICODE -D_UNICODE
|
||||||
|
|
||||||
include $(PATH_TO_TOP)/rules.mak
|
include $(PATH_TO_TOP)/rules.mak
|
||||||
|
|
||||||
include $(TOOLS_PATH)/helper.mk
|
include $(TOOLS_PATH)/helper.mk
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
#define UNICODE
|
|
||||||
#define _UNICODE
|
|
||||||
|
|
||||||
/* Console Task Manager
|
/* Console Task Manager
|
||||||
|
|
||||||
ctm.c - main program file
|
ctm.c - main program file
|
||||||
|
@ -90,6 +87,7 @@ PPERFDATA pPerfData = NULL; // Most recent copy of perf data
|
||||||
int selection=0;
|
int selection=0;
|
||||||
int scrolled=0; // offset from which process start showing
|
int scrolled=0; // offset from which process start showing
|
||||||
int first = 0; // first time in DisplayScreen
|
int first = 0; // first time in DisplayScreen
|
||||||
|
SYSTEM_BASIC_INFORMATION SystemBasicInfo;
|
||||||
|
|
||||||
#define NEW_CONSOLE
|
#define NEW_CONSOLE
|
||||||
|
|
||||||
|
@ -287,7 +285,7 @@ int ProcessKeys(int numEvents)
|
||||||
do {
|
do {
|
||||||
GetNumberOfConsoleInputEvents(hStdin, &pId);
|
GetNumberOfConsoleInputEvents(hStdin, &pId);
|
||||||
key = GetKeyPressed(pId);
|
key = GetKeyPressed(pId);
|
||||||
} while (key == 0);
|
} while (key != KEY_YES && key != KEY_NO);
|
||||||
|
|
||||||
if (key == KEY_YES)
|
if (key == KEY_YES)
|
||||||
{
|
{
|
||||||
|
@ -341,6 +339,11 @@ int ProcessKeys(int numEvents)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PerfInit()
|
||||||
|
{
|
||||||
|
NtQuerySystemInformation(SystemBasicInformation, &SystemBasicInfo, sizeof(SystemBasicInfo), 0);
|
||||||
|
}
|
||||||
|
|
||||||
void PerfDataRefresh()
|
void PerfDataRefresh()
|
||||||
{
|
{
|
||||||
LONG status;
|
LONG status;
|
||||||
|
@ -371,15 +374,15 @@ void PerfDataRefresh()
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
// Get processor information
|
// Get processor information
|
||||||
SysProcessorTimeInfo = (PSYSTEM_PROCESSORTIME_INFO)malloc(sizeof(SYSTEM_PROCESSORTIME_INFO) * 1/*SystemBasicInfo.bKeNumberProcessors*/);
|
SysProcessorTimeInfo = (PSYSTEM_PROCESSORTIME_INFO)malloc(sizeof(SYSTEM_PROCESSORTIME_INFO) * SystemBasicInfo.NumberProcessors);
|
||||||
status = NtQuerySystemInformation(SystemProcessorTimes, SysProcessorTimeInfo, sizeof(SYSTEM_PROCESSORTIME_INFO) * 1/*SystemBasicInfo.bKeNumberProcessors*/, &ulSize);
|
status = NtQuerySystemInformation(SystemProcessorTimes, SysProcessorTimeInfo, sizeof(SYSTEM_PROCESSORTIME_INFO) * SystemBasicInfo.NumberProcessors, &ulSize);
|
||||||
|
|
||||||
|
|
||||||
// Get process information
|
// Get process information
|
||||||
PsaCaptureProcessesAndThreads((PSYSTEM_PROCESSES *)&pBuffer);
|
PsaCaptureProcessesAndThreads((PSYSTEM_PROCESSES *)&pBuffer);
|
||||||
|
|
||||||
#ifdef TIMES
|
#ifdef TIMES
|
||||||
for (CurrentKernelTime=0, Idx=0; Idx<1/*SystemBasicInfo.bKeNumberProcessors*/; Idx++) {
|
for (CurrentKernelTime=0, Idx=0; Idx<SystemBasicInfo.NumberProcessors; Idx++) {
|
||||||
CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].TotalProcessorTime);
|
CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].TotalProcessorTime);
|
||||||
CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].TotalDPCTime);
|
CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].TotalDPCTime);
|
||||||
CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].TotalInterruptTime);
|
CurrentKernelTime += Li2Double(SysProcessorTimeInfo[Idx].TotalInterruptTime);
|
||||||
|
@ -397,8 +400,8 @@ void PerfDataRefresh()
|
||||||
dbKernelTime = dbKernelTime / dbSystemTime;
|
dbKernelTime = dbKernelTime / dbSystemTime;
|
||||||
|
|
||||||
// CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors
|
// CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors
|
||||||
dbIdleTime = 100.0 - dbIdleTime * 100.0; /* / (double)SystemBasicInfo.bKeNumberProcessors;// + 0.5; */
|
dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SystemBasicInfo.NumberProcessors;// + 0.5;
|
||||||
dbKernelTime = 100.0 - dbKernelTime * 100.0; /* / (double)SystemBasicInfo.bKeNumberProcessors;// + 0.5; */
|
dbKernelTime = 100.0 - dbKernelTime * 100.0 / (double)SystemBasicInfo.NumberProcessors;// + 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store new CPU's idle and system time
|
// Store new CPU's idle and system time
|
||||||
|
@ -460,7 +463,7 @@ void PerfDataRefresh()
|
||||||
double CurTime = Li2Double(pSPI->KernelTime) + Li2Double(pSPI->UserTime);
|
double CurTime = Li2Double(pSPI->KernelTime) + Li2Double(pSPI->UserTime);
|
||||||
double OldTime = Li2Double(pPDOld->KernelTime) + Li2Double(pPDOld->UserTime);
|
double OldTime = Li2Double(pPDOld->KernelTime) + Li2Double(pPDOld->UserTime);
|
||||||
double CpuTime = (CurTime - OldTime) / dbSystemTime;
|
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;
|
pPerfData[Idx].CPUUsage = (ULONG)CpuTime;
|
||||||
#else
|
#else
|
||||||
|
@ -537,9 +540,6 @@ unsigned int GetKeyPressed(int events)
|
||||||
|
|
||||||
for (i=0; i<events; i++)
|
for (i=0; i<events; i++)
|
||||||
{
|
{
|
||||||
if (!ReadConsoleInput(hStdin, &record, 0, &bytesRead)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (!ReadConsoleInput(hStdin, &record, 1, &bytesRead)) {
|
if (!ReadConsoleInput(hStdin, &record, 1, &bytesRead)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -599,6 +599,8 @@ int main(int *argc, char **argv)
|
||||||
lpSeparator[columnRightPositions[i]] = _T('+');
|
lpSeparator[columnRightPositions[i]] = _T('+');
|
||||||
}
|
}
|
||||||
lpSeparator[columnRightPositions[4] + 1] = _T('\0');
|
lpSeparator[columnRightPositions[4] + 1] = _T('\0');
|
||||||
|
lpHeader[columnRightPositions[4] + 1] = _T('\0');
|
||||||
|
|
||||||
|
|
||||||
if (!LoadString(hInst, IDS_APP_TITLE, lpTitle, 80))
|
if (!LoadString(hInst, IDS_APP_TITLE, lpTitle, 80))
|
||||||
lpTitle[0] = _T('\0');
|
lpTitle[0] = _T('\0');
|
||||||
|
@ -644,6 +646,8 @@ int main(int *argc, char **argv)
|
||||||
SetConsoleMode(hStdin, 0); //FIXME: Should check for error!
|
SetConsoleMode(hStdin, 0); //FIXME: Should check for error!
|
||||||
SetConsoleMode(hStdout, 0); //FIXME: Should check for error!
|
SetConsoleMode(hStdout, 0); //FIXME: Should check for error!
|
||||||
|
|
||||||
|
PerfInit();
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
DWORD numEvents;
|
DWORD numEvents;
|
||||||
|
@ -651,12 +655,8 @@ int main(int *argc, char **argv)
|
||||||
PerfDataRefresh();
|
PerfDataRefresh();
|
||||||
DisplayScreen();
|
DisplayScreen();
|
||||||
|
|
||||||
//WriteConsole(hStdin, " ", 1, &numEvents, NULL); // TODO: Make another way (this is ugly, I know)
|
|
||||||
#if 0
|
|
||||||
/* WaitForSingleObject for console handles is not implemented in ROS */
|
/* WaitForSingleObject for console handles is not implemented in ROS */
|
||||||
WaitForSingleObject(hStdin, 1000);
|
WaitForSingleObject(hStdin, 1000);
|
||||||
#endif
|
|
||||||
|
|
||||||
GetNumberOfConsoleInputEvents(hStdin, &numEvents);
|
GetNumberOfConsoleInputEvents(hStdin, &numEvents);
|
||||||
|
|
||||||
if (numEvents > 0)
|
if (numEvents > 0)
|
||||||
|
@ -664,13 +664,6 @@ int main(int *argc, char **argv)
|
||||||
if (ProcessKeys(numEvents) == TRUE)
|
if (ProcessKeys(numEvents) == TRUE)
|
||||||
break;
|
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();
|
RestoreConsole();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue