reactos/base/applications/taskmgr/perfdata.h
Hermès Bélusca-Maïto 129f10ea26 [TASKMGR] Cherry pick Hermes fixes
** WIP ** [TASKMGR] Get rid of thread-oriented updates. Just do it synchronously on WM_TIMER.

** WIP ** Merge RefreshPerformancePage() and PerformancePageRefreshThread(), now that we removed the separate performance page refreshing thread.

- Use _ui64tow() instead of _ultow() for converting ULONGLONGs into
  a string representation.

- Isolate the update of the status bar.

- Isolate the actual graphs redrawing. The idea for later is to not
  trigger any redrawings (and run unnecessary code) if the page is deactivated.

[TASKMGR] No need to get and save global handles for all the controls in the performance page.

... and especially for controls that are used only in one place.
Only handles to the graph controls are sufficient. For the others,
we can manage by using dialog control IDs.

- Rename AdjustFrameSize() 'pos' parameter to be more explicit.

** WIP ** Group trios of Memory performance getters together, as they are always used in succession.

- Group PerfDataGetCommitCharge[Total|Limit|Peak]K() together into
  PerfDataGetCommitChargeK().

- Group PerfDataGetKernelMemory[Total|Paged|NonPaged]K() together
  into PerfDataGetKernelMemoryK().

- Group PerfDataGetPhysicalMemory[Total|Available|SystemCache]K()
  together into PerfDataGetPhysicalMemoryK().

- Use these new Mem performance getters.

[TASKMGR] Use owner-drawn performance graphs.

- Use owner-drawn buttons to implement correct graph painting while
  maintaining the 3D appearance. As done on Windows (TM)

  Why using buttons (that should be disabled btw.)?
  Because we want, if the graphs fail to be created (due to e.g.
  lack of resources), to show a descriptive label of what's missing.

  This also allow the graphs to be drawn **properly** inside a 3D-border window.

- Redraw graphs on WM_DRAWITEM.

- Don't need to subclass button controls.

- Use DeferWindowPos() to avoid controls blinking on resize.

- Fix the problem of the buttons resizing as "1/x": this was due to
  the fact, using GetClientRect + Mapping, did't take the border into
  account. Instead, use GetWindowRect + a different coord mapping to
  fix all that.

- Remove some dead code.

- Rename the remaining ridiculously long variable names.

** WIP ** CPU/Mem meters: keep a separate copy of the CPU/Mem perf values.

+ Use structure for keeping state.

** WIP ** Add support for multiple-CPU stats. (In progress, needs code cleanup.)

In particular, use SystemProcessorTimeInfo to calculate the idle time
as done in ROSAPPS' ctm.exe, see commit c0873723.

See also https://ladydebug.com/blog/codes/cpuusage_win.htm

+ Fix the problem of NtQuerySystemInformation(SystemPerformanceInformation)
  that shows up when running a 32-bit build under Windows 7 x64.

** WIP ** Investigating showing physical memory in the MEM gauge.
2025-02-01 16:36:33 +02:00

112 lines
3.3 KiB
C

/*
* PROJECT: ReactOS Task Manager
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
* PURPOSE: Performance Counters
* COPYRIGHT: Copyright 1999-2001 Brian Palmer <brianp@reactos.org>
* Copyright 2014 Ismael Ferreras Morezuelas <swyterzone+ros@gmail.com>
*/
#pragma once
#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart))
typedef struct _PERFDATA
{
WCHAR ImageName[MAX_PATH];
HANDLE ProcessId;
WCHAR UserName[MAX_PATH];
ULONG SessionId;
ULONG CPUUsage;
LARGE_INTEGER CPUTime;
ULONG WorkingSetSizeBytes;
ULONG PeakWorkingSetSizeBytes;
ULONG WorkingSetSizeDelta;
ULONG PageFaultCount;
ULONG PageFaultCountDelta;
ULONG VirtualMemorySizeBytes;
ULONG PagedPoolUsagePages;
ULONG NonPagedPoolUsagePages;
ULONG BasePriority;
ULONG HandleCount;
ULONG ThreadCount;
ULONG USERObjectCount;
ULONG GDIObjectCount;
IO_COUNTERS IOCounters;
LARGE_INTEGER UserTime;
LARGE_INTEGER KernelTime;
} PERFDATA, *PPERFDATA;
typedef struct _CMD_LINE_CACHE
{
DWORD idx;
LPWSTR str;
ULONG len;
struct _CMD_LINE_CACHE* pnext;
} CMD_LINE_CACHE, *PCMD_LINE_CACHE;
BOOL PerfDataInitialize(VOID);
VOID PerfDataUninitialize(VOID);
VOID PerfDataRefresh(VOID);
VOID PerfDataAcquireLock(VOID);
VOID PerfDataReleaseLock(VOID);
BOOL PerfDataGet(ULONG Index, PPERFDATA *lppData);
ULONG PerfDataGetProcessIndex(ULONG pid);
ULONG PerfDataGetProcessCount(void);
ULONG PerfDataGetProcessorCount(VOID);
ULONG PerfDataGetProcessorUsage(VOID);
ULONG PerfDataGetProcessorSystemUsage(VOID);
/****/
ULONG PerfDataGetProcessorUsagePerCPU(ULONG CPUIndex);
ULONG PerfDataGetProcessorSystemUsagePerCPU(ULONG CPUIndex);
/****/
BOOL PerfDataGetImageName(ULONG Index, LPWSTR lpImageName, ULONG nMaxCount);
ULONG PerfDataGetProcessId(ULONG Index);
BOOL PerfDataGetUserName(ULONG Index, LPWSTR lpUserName, ULONG nMaxCount);
BOOL PerfDataGetCommandLine(ULONG Index, LPWSTR lpCommandLine, ULONG nMaxCount);
void PerfDataDeallocCommandLineCache();
ULONG PerfDataGetSessionId(ULONG Index);
ULONG PerfDataGetCPUUsage(ULONG Index);
LARGE_INTEGER PerfDataGetCPUTime(ULONG Index);
ULONG PerfDataGetWorkingSetSizeBytes(ULONG Index);
ULONG PerfDataGetPeakWorkingSetSizeBytes(ULONG Index);
ULONG PerfDataGetWorkingSetSizeDelta(ULONG Index);
ULONG PerfDataGetPageFaultCount(ULONG Index);
ULONG PerfDataGetPageFaultCountDelta(ULONG Index);
ULONG PerfDataGetVirtualMemorySizeBytes(ULONG Index);
ULONG PerfDataGetPagedPoolUsagePages(ULONG Index);
ULONG PerfDataGetNonPagedPoolUsagePages(ULONG Index);
ULONG PerfDataGetBasePriority(ULONG Index);
ULONG PerfDataGetHandleCount(ULONG Index);
ULONG PerfDataGetThreadCount(ULONG Index);
ULONG PerfDataGetUSERObjectCount(ULONG Index);
ULONG PerfDataGetGDIObjectCount(ULONG Index);
BOOL PerfDataGetIOCounters(ULONG Index, PIO_COUNTERS pIoCounters);
VOID
PerfDataGetCommitChargeK(
_Out_opt_ PULONGLONG Total,
_Out_opt_ PULONGLONG Limit,
_Out_opt_ PULONGLONG Peak);
VOID
PerfDataGetKernelMemoryK(
_Out_opt_ PULONGLONG MemTotal,
_Out_opt_ PULONGLONG MemPaged,
_Out_opt_ PULONGLONG MemNonPaged);
VOID
PerfDataGetPhysicalMemoryK(
_Out_opt_ PULONGLONG MemTotal,
_Out_opt_ PULONGLONG MemAvailable,
_Out_opt_ PULONGLONG MemSysCache);
ULONG PerfDataGetSystemHandleCount(void);
ULONG PerfDataGetTotalThreadCount(void);