Skip to content

Commit d4b4d9e

Browse files
committed
Add EnableScaleCpuGraph setting, Add CPU graph scaling support winsiderss#873
1 parent 1cbff53 commit d4b4d9e

File tree

6 files changed

+157
-14
lines changed

6 files changed

+157
-14
lines changed

ProcessHacker/include/phsettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ EXT ULONG PhCsUseColorServiceStop;
8585
EXT ULONG PhCsColorServiceStop;
8686

8787
EXT ULONG PhCsImageCoherencyScanLevel;
88+
EXT ULONG PhCsEnableScaleCpuGraph;
8889

8990
#define PH_SET_INTEGER_CACHED_SETTING(Name, Value) (PhSetIntegerSetting(TEXT(#Name), PhCs##Name = (Value)))
9091

ProcessHacker/include/sysinfo.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ PhSiSizeLabelYFunction(
158158
_In_ FLOAT Value,
159159
_In_ FLOAT Parameter
160160
);
161+
162+
PHAPPAPI
163+
PPH_STRING
164+
NTAPI
165+
PhSiDoubleLabelYFunction(
166+
_In_ PPH_GRAPH_DRAW_INFO DrawInfo,
167+
_In_ ULONG DataIndex,
168+
_In_ FLOAT Value,
169+
_In_ FLOAT Parameter
170+
);
161171
// end_phapppub
162172

163173
VOID PhShowSystemInformationDialog(

ProcessHacker/prpgperf.c

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Process properties: Performance page
44
*
55
* Copyright (C) 2009-2016 wj32
6-
* Copyright (C) 2019-2020 dmex
6+
* Copyright (C) 2019-2021 dmex
77
*
88
* This file is part of Process Hacker.
99
*
@@ -149,7 +149,7 @@ INT_PTR CALLBACK PhpProcessPerformanceDlgProc(
149149

150150
if (header->hwndFrom == performanceContext->CpuGraphHandle)
151151
{
152-
drawInfo->Flags = PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_USE_LINE_2;
152+
drawInfo->Flags = PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_USE_LINE_2 | (PhCsEnableScaleCpuGraph ? PH_GRAPH_LABEL_MAX_Y : 0);
153153
PhSiSetColorsGraphDrawInfo(drawInfo, PhCsColorCpuKernel, PhCsColorCpuUser);
154154

155155
PhGraphStateGetDrawInfo(
@@ -164,6 +164,38 @@ INT_PTR CALLBACK PhpProcessPerformanceDlgProc(
164164
performanceContext->CpuGraphState.Data1, drawInfo->LineDataCount);
165165
PhCopyCircularBuffer_FLOAT(&processItem->CpuUserHistory,
166166
performanceContext->CpuGraphState.Data2, drawInfo->LineDataCount);
167+
168+
if (PhCsEnableScaleCpuGraph)
169+
{
170+
FLOAT max = 0;
171+
172+
for (ULONG i = 0; i < drawInfo->LineDataCount; i++)
173+
{
174+
FLOAT data = performanceContext->CpuGraphState.Data1[i] +
175+
performanceContext->CpuGraphState.Data2[i]; // HACK
176+
177+
if (max < data)
178+
max = data;
179+
}
180+
181+
if (max != 0)
182+
{
183+
PhDivideSinglesBySingle(
184+
performanceContext->CpuGraphState.Data1,
185+
max,
186+
drawInfo->LineDataCount
187+
);
188+
PhDivideSinglesBySingle(
189+
performanceContext->CpuGraphState.Data2,
190+
max,
191+
drawInfo->LineDataCount
192+
);
193+
}
194+
195+
drawInfo->LabelYFunction = PhSiDoubleLabelYFunction;
196+
drawInfo->LabelYFunctionParameter = max;
197+
}
198+
167199
performanceContext->CpuGraphState.Valid = TRUE;
168200
}
169201

@@ -330,18 +362,21 @@ INT_PTR CALLBACK PhpProcessPerformanceDlgProc(
330362
{
331363
FLOAT cpuKernel;
332364
FLOAT cpuUser;
333-
PH_FORMAT format[3];
365+
PH_FORMAT format[7];
334366

335367
cpuKernel = PhGetItemCircularBuffer_FLOAT(&processItem->CpuKernelHistory, getTooltipText->Index);
336368
cpuUser = PhGetItemCircularBuffer_FLOAT(&processItem->CpuUserHistory, getTooltipText->Index);
337369

338-
// %.2f%%\n%s
370+
// %.2f%% (K: %.2f%%, U: %.2f%%)%s\n%s
339371
PhInitFormatF(&format[0], ((DOUBLE)cpuKernel + cpuUser) * 100, 2);
340-
PhInitFormatS(&format[1], L"%\n");
341-
PhInitFormatSR(&format[2], PH_AUTO_T(PH_STRING, PhGetStatisticsTimeString(processItem, getTooltipText->Index))->sr);
342-
343-
PhMoveReference(&performanceContext->CpuGraphState.TooltipText,
344-
PhFormat(format, RTL_NUMBER_OF(format), 64));
372+
PhInitFormatS(&format[1], L"% (K: ");
373+
PhInitFormatF(&format[2], (DOUBLE)cpuKernel * 100, 2);
374+
PhInitFormatS(&format[3], L"%, U: ");
375+
PhInitFormatF(&format[4], (DOUBLE)cpuUser * 100, 2);
376+
PhInitFormatS(&format[5], L"%)\n");
377+
PhInitFormatSR(&format[6], PH_AUTO_T(PH_STRING, PhGetStatisticsTimeString(processItem, getTooltipText->Index))->sr);
378+
379+
PhMoveReference(&performanceContext->CpuGraphState.TooltipText, PhFormat(format, RTL_NUMBER_OF(format), 160));
345380
}
346381

347382
getTooltipText->Text = performanceContext->CpuGraphState.TooltipText->sr;

ProcessHacker/settings.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ VOID PhAddDefaultSettings(
4949
PhpAddIntegerSetting(L"EnableNetworkResolve", L"1");
5050
PhpAddIntegerSetting(L"EnableNetworkResolveDoH", L"0");
5151
PhpAddIntegerSetting(L"EnablePlugins", L"1");
52+
PhpAddIntegerSetting(L"EnableScaleCpuGraph", L"0");
5253
PhpAddIntegerSetting(L"EnableServiceNonPoll", L"0");
5354
PhpAddIntegerSetting(L"EnableStage2", L"1");
5455
PhpAddIntegerSetting(L"EnableServiceStage2", L"0");
@@ -352,6 +353,7 @@ VOID PhUpdateCachedSettings(
352353
PH_UPDATE_SETTING(ColorFanRpm);
353354

354355
PH_UPDATE_SETTING(ImageCoherencyScanLevel);
356+
PH_UPDATE_SETTING(EnableScaleCpuGraph);
355357

356358
PhEnableNetworkResolveDoHSupport = !!PhGetIntegerSetting(L"EnableNetworkResolveDoH");
357359
PhEnableVersionShortText = !!PhGetIntegerSetting(L"EnableVersionSupport");

ProcessHacker/sysinfo.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* System Information window
44
*
55
* Copyright (C) 2011-2016 wj32
6-
* Copyright (C) 2017-2020 dmex
6+
* Copyright (C) 2017-2021 dmex
77
*
88
* This file is part of Process Hacker.
99
*
@@ -1004,6 +1004,32 @@ PPH_STRING PhSiSizeLabelYFunction(
10041004
}
10051005
}
10061006

1007+
PPH_STRING PhSiDoubleLabelYFunction(
1008+
_In_ PPH_GRAPH_DRAW_INFO DrawInfo,
1009+
_In_ ULONG DataIndex,
1010+
_In_ FLOAT Value,
1011+
_In_ FLOAT Parameter
1012+
)
1013+
{
1014+
DOUBLE value;
1015+
1016+
value = (DOUBLE)((DOUBLE)Value * Parameter);
1017+
1018+
if (value != 0)
1019+
{
1020+
PH_FORMAT format[2];
1021+
1022+
PhInitFormatF(&format[0], value * 100, 2);
1023+
PhInitFormatC(&format[1], L'%');
1024+
1025+
return PhFormat(format, RTL_NUMBER_OF(format), 0);
1026+
}
1027+
else
1028+
{
1029+
return PhReferenceEmptyString();
1030+
}
1031+
}
1032+
10071033
VOID PhSipRegisterDialog(
10081034
_In_ HWND DialogWindowHandle
10091035
)
@@ -1257,7 +1283,7 @@ VOID PhSipDrawRestoreSummaryPanel(
12571283
DrawItemStruct->rcItem.bottom - DrawItemStruct->rcItem.top
12581284
};
12591285

1260-
if (!(hdc = GetWindowDC(DrawItemStruct->hwndItem)))
1286+
if (!(hdc = GetDC(DrawItemStruct->hwndItem)))
12611287
return;
12621288

12631289
bufferDc = CreateCompatibleDC(hdc);
@@ -1345,7 +1371,7 @@ VOID PhSipDrawSeparator(
13451371
DrawItemStruct->rcItem.bottom - DrawItemStruct->rcItem.top
13461372
};
13471373

1348-
if (!(hdc = GetWindowDC(DrawItemStruct->hwndItem)))
1374+
if (!(hdc = GetDC(DrawItemStruct->hwndItem)))
13491375
return;
13501376

13511377
bufferDc = CreateCompatibleDC(hdc);

ProcessHacker/syssccpu.c

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,37 @@ BOOLEAN PhSipCpuSectionCallback(
117117
if (!drawInfo)
118118
break;
119119

120-
drawInfo->Flags = PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_USE_LINE_2;
120+
drawInfo->Flags = PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_USE_LINE_2 | (PhCsEnableScaleCpuGraph ? PH_GRAPH_LABEL_MAX_Y : 0);
121121
Section->Parameters->ColorSetupFunction(drawInfo, PhCsColorCpuKernel, PhCsColorCpuUser);
122122
PhGetDrawInfoGraphBuffers(&Section->GraphState.Buffers, drawInfo, PhCpuKernelHistory.Count);
123123

124124
if (!Section->GraphState.Valid)
125125
{
126126
PhCopyCircularBuffer_FLOAT(&PhCpuKernelHistory, Section->GraphState.Data1, drawInfo->LineDataCount);
127127
PhCopyCircularBuffer_FLOAT(&PhCpuUserHistory, Section->GraphState.Data2, drawInfo->LineDataCount);
128+
129+
if (PhCsEnableScaleCpuGraph)
130+
{
131+
FLOAT max = 0;
132+
133+
for (ULONG i = 0; i < drawInfo->LineDataCount; i++)
134+
{
135+
FLOAT data = Section->GraphState.Data1[i] + Section->GraphState.Data2[i]; // HACK
136+
137+
if (max < data)
138+
max = data;
139+
}
140+
141+
if (max != 0)
142+
{
143+
PhDivideSinglesBySingle(Section->GraphState.Data1, max, drawInfo->LineDataCount);
144+
PhDivideSinglesBySingle(Section->GraphState.Data2, max, drawInfo->LineDataCount);
145+
}
146+
147+
drawInfo->LabelYFunction = PhSiDoubleLabelYFunction;
148+
drawInfo->LabelYFunctionParameter = max;
149+
}
150+
128151
Section->GraphState.Valid = TRUE;
129152
}
130153
}
@@ -598,7 +621,7 @@ VOID PhSipNotifyCpuGraph(
598621
PPH_GRAPH_GETDRAWINFO getDrawInfo = (PPH_GRAPH_GETDRAWINFO)Header;
599622
PPH_GRAPH_DRAW_INFO drawInfo = getDrawInfo->DrawInfo;
600623

601-
drawInfo->Flags = PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_USE_LINE_2;
624+
drawInfo->Flags = PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_USE_LINE_2 | (PhCsEnableScaleCpuGraph ? PH_GRAPH_LABEL_MAX_Y : 0);
602625
PhSiSetColorsGraphDrawInfo(drawInfo, PhCsColorCpuKernel, PhCsColorCpuUser);
603626

604627
if (Index == ULONG_MAX)
@@ -613,6 +636,29 @@ VOID PhSipNotifyCpuGraph(
613636
{
614637
PhCopyCircularBuffer_FLOAT(&PhCpuKernelHistory, CpuGraphState.Data1, drawInfo->LineDataCount);
615638
PhCopyCircularBuffer_FLOAT(&PhCpuUserHistory, CpuGraphState.Data2, drawInfo->LineDataCount);
639+
640+
if (PhCsEnableScaleCpuGraph)
641+
{
642+
FLOAT max = 0;
643+
644+
for (ULONG i = 0; i < drawInfo->LineDataCount; i++)
645+
{
646+
FLOAT data = CpuGraphState.Data1[i] + CpuGraphState.Data2[i]; // HACK
647+
648+
if (max < data)
649+
max = data;
650+
}
651+
652+
if (max != 0)
653+
{
654+
PhDivideSinglesBySingle(CpuGraphState.Data1, max, drawInfo->LineDataCount);
655+
PhDivideSinglesBySingle(CpuGraphState.Data2, max, drawInfo->LineDataCount);
656+
}
657+
658+
drawInfo->LabelYFunction = PhSiDoubleLabelYFunction;
659+
drawInfo->LabelYFunctionParameter = max;
660+
}
661+
616662
CpuGraphState.Valid = TRUE;
617663
}
618664
}
@@ -628,6 +674,29 @@ VOID PhSipNotifyCpuGraph(
628674
{
629675
PhCopyCircularBuffer_FLOAT(&PhCpusKernelHistory[Index], CpusGraphState[Index].Data1, drawInfo->LineDataCount);
630676
PhCopyCircularBuffer_FLOAT(&PhCpusUserHistory[Index], CpusGraphState[Index].Data2, drawInfo->LineDataCount);
677+
678+
if (PhCsEnableScaleCpuGraph)
679+
{
680+
FLOAT max = 0;
681+
682+
for (ULONG i = 0; i < drawInfo->LineDataCount; i++)
683+
{
684+
FLOAT data = CpusGraphState[Index].Data1[i] + CpusGraphState[Index].Data2[i]; // HACK
685+
686+
if (max < data)
687+
max = data;
688+
}
689+
690+
if (max != 0)
691+
{
692+
PhDivideSinglesBySingle(CpusGraphState[Index].Data1, max, drawInfo->LineDataCount);
693+
PhDivideSinglesBySingle(CpusGraphState[Index].Data2, max, drawInfo->LineDataCount);
694+
}
695+
696+
drawInfo->LabelYFunction = PhSiDoubleLabelYFunction;
697+
drawInfo->LabelYFunctionParameter = max;
698+
}
699+
631700
CpusGraphState[Index].Valid = TRUE;
632701
}
633702

0 commit comments

Comments
 (0)