6d330ca52f
Create controls at their initial layout sizes and reduce system information panel flicker. Recover GPU/NPU monitoring after adapter restarts, correct sensor aggregation, and optimize graph updates. Restrict upload destinations, bound updater downloads, use monotonic transfer timing, and fix resource leaks and firewall cache races.
1153 lines
38 KiB
C
1153 lines
38 KiB
C
/*
|
|
* Copyright (c) 2022 Winsider Seminars & Solutions, Inc. All rights reserved.
|
|
*
|
|
* This file is part of System Informer.
|
|
*
|
|
* Authors:
|
|
*
|
|
* dmex 2021-2026
|
|
*
|
|
*/
|
|
|
|
#include "devices.h"
|
|
|
|
_Function_class_(PH_GRAPH_MESSAGE_CALLBACK)
|
|
BOOLEAN RaplDeviceGraphMessageCallback(
|
|
_In_ HWND WindowHandle,
|
|
_In_ ULONG Message,
|
|
_In_ PVOID Parameter1,
|
|
_In_ PVOID Parameter2,
|
|
_In_ PVOID Context
|
|
);
|
|
|
|
/**
|
|
* Handles the embedded RAPL summary panel dialog.
|
|
*
|
|
* \param WindowHandle Dialog window handle.
|
|
* \param WindowMessage Window message identifier.
|
|
* \param wParam Message-specific wParam value.
|
|
* \param lParam Message-specific lParam value.
|
|
*
|
|
* \return Dialog procedure result.
|
|
*/
|
|
INT_PTR CALLBACK RaplDevicePanelDialogProc(
|
|
_In_ HWND WindowHandle,
|
|
_In_ UINT WindowMessage,
|
|
_In_ WPARAM wParam,
|
|
_In_ LPARAM lParam
|
|
)
|
|
{
|
|
PDV_RAPL_SYSINFO_CONTEXT context = NULL;
|
|
|
|
if (WindowMessage == WM_INITDIALOG)
|
|
{
|
|
context = (PDV_RAPL_SYSINFO_CONTEXT)lParam;
|
|
|
|
PhSetWindowContext(WindowHandle, PH_WINDOW_CONTEXT_DEFAULT, context);
|
|
}
|
|
else
|
|
{
|
|
context = PhGetWindowContext(WindowHandle, PH_WINDOW_CONTEXT_DEFAULT);
|
|
}
|
|
|
|
if (context == NULL)
|
|
return FALSE;
|
|
|
|
switch (WindowMessage)
|
|
{
|
|
case WM_INITDIALOG:
|
|
{
|
|
PhInitializeThemeWindowGroupBoxes(WindowHandle);
|
|
context->RaplDeviceProcessorUsageLabel = GetDlgItem(WindowHandle, IDC_PACKAGE_L);
|
|
context->RaplDeviceCoreUsageLabel = GetDlgItem(WindowHandle, IDC_CORE_L);
|
|
context->RaplDeviceDimmUsageLabel = GetDlgItem(WindowHandle, IDC_DIMM_L);
|
|
context->RaplDeviceGpuLimitLabel = GetDlgItem(WindowHandle, IDC_GPUDISCRETE_L);
|
|
context->RaplDeviceComponentUsageLabel = GetDlgItem(WindowHandle, IDC_CPUCOMP_L);
|
|
context->RaplDeviceTotalUsageLabel = GetDlgItem(WindowHandle, IDC_TOTALPOWER_L);
|
|
}
|
|
break;
|
|
case WM_NCDESTROY:
|
|
{
|
|
PhRemoveWindowContext(WindowHandle, PH_WINDOW_CONTEXT_DEFAULT);
|
|
}
|
|
break;
|
|
case WM_CTLCOLORBTN:
|
|
return HANDLE_WM_CTLCOLORBTN(WindowHandle, wParam, lParam, PhWindowThemeControlColor);
|
|
case WM_CTLCOLORDLG:
|
|
return HANDLE_WM_CTLCOLORDLG(WindowHandle, wParam, lParam, PhWindowThemeControlColor);
|
|
case WM_CTLCOLORSTATIC:
|
|
return HANDLE_WM_CTLCOLORSTATIC(WindowHandle, wParam, lParam, PhWindowThemeControlColor);
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
/**
|
|
* Initializes DPI-dependent layout values for the RAPL dialog.
|
|
*
|
|
* \param Context RAPL sysinfo context.
|
|
*/
|
|
VOID RaplDeviceInitializeDialogDpi(
|
|
_In_ PDV_RAPL_SYSINFO_CONTEXT Context
|
|
)
|
|
{
|
|
Context->GraphPadding = PhScaleToDisplay(RAPL_GRAPH_PADDING, Context->SysinfoSection->Parameters->WindowDpi);
|
|
}
|
|
|
|
/**
|
|
* Initializes graph state objects for all RAPL graphs.
|
|
*
|
|
* \param Context RAPL sysinfo context.
|
|
*/
|
|
VOID RaplDeviceInitializeGraphStates(
|
|
_Inout_ PDV_RAPL_SYSINFO_CONTEXT Context
|
|
)
|
|
{
|
|
PhInitializeGraphState(&Context->ProcessorGraphState);
|
|
PhInitializeGraphState(&Context->CoreGraphState);
|
|
PhInitializeGraphState(&Context->DimmGraphState);
|
|
PhInitializeGraphState(&Context->TotalGraphState);
|
|
}
|
|
|
|
/**
|
|
* Creates the graph controls used by the RAPL device dialog.
|
|
*
|
|
* \param Context RAPL sysinfo context.
|
|
*/
|
|
VOID RaplDeviceGetGraphRects(
|
|
_In_ PDV_RAPL_SYSINFO_CONTEXT Context,
|
|
_Out_writes_(4) RECT LabelRects[4],
|
|
_Out_writes_(4) RECT GraphRects[4]
|
|
)
|
|
{
|
|
RECT clientRect;
|
|
RECT labelRect;
|
|
RECT marginRect;
|
|
LONG graphWidth;
|
|
LONG graphHeight;
|
|
LONG graphPadding;
|
|
LONG y;
|
|
|
|
marginRect = Context->GraphMarginScaled;
|
|
graphPadding = Context->GraphPadding;
|
|
|
|
PhGetClientRect(Context->WindowHandle, &clientRect);
|
|
PhGetClientRect(Context->PackageGraphLabelHandle, &labelRect);
|
|
graphWidth = clientRect.right - marginRect.left - marginRect.right;
|
|
graphHeight = (clientRect.bottom - marginRect.top - marginRect.bottom - labelRect.bottom * 4 - graphPadding * 5) / 4;
|
|
y = marginRect.top;
|
|
|
|
for (ULONG i = 0; i < 4; i++)
|
|
{
|
|
LabelRects[i].left = marginRect.left;
|
|
LabelRects[i].top = y;
|
|
LabelRects[i].right = marginRect.left + labelRect.right;
|
|
LabelRects[i].bottom = y + labelRect.bottom;
|
|
y += labelRect.bottom + graphPadding;
|
|
|
|
GraphRects[i].left = marginRect.left;
|
|
GraphRects[i].top = y;
|
|
GraphRects[i].right = marginRect.left + graphWidth;
|
|
GraphRects[i].bottom = y + graphHeight;
|
|
y += graphHeight + graphPadding;
|
|
}
|
|
|
|
GraphRects[3].bottom = clientRect.bottom - marginRect.bottom;
|
|
}
|
|
|
|
VOID RaplDeviceCreateGraphs(
|
|
_Inout_ PDV_RAPL_SYSINFO_CONTEXT Context
|
|
)
|
|
{
|
|
PH_GRAPH_CREATEPARAMS graphCreateParams;
|
|
RECT labelRects[4];
|
|
RECT graphRects[4];
|
|
|
|
Context->PackageGraphLabelHandle = GetDlgItem(Context->WindowHandle, IDC_PACKAGE_L);
|
|
Context->CoreGraphLabelHandle = GetDlgItem(Context->WindowHandle, IDC_CORE_L);
|
|
Context->DimmGraphLabelHandle = GetDlgItem(Context->WindowHandle, IDC_DIMM_L);
|
|
Context->TotalGraphLabelHandle = GetDlgItem(Context->WindowHandle, IDC_TOTAL_L);
|
|
|
|
RaplDeviceGetGraphRects(Context, labelRects, graphRects);
|
|
|
|
memset(&graphCreateParams, 0, sizeof(PH_GRAPH_CREATEPARAMS));
|
|
graphCreateParams.Size = sizeof(PH_GRAPH_CREATEPARAMS);
|
|
graphCreateParams.Callback = RaplDeviceGraphMessageCallback;
|
|
graphCreateParams.Context = Context;
|
|
|
|
Context->ProcessorGraphHandle = PhCreateWindow(
|
|
PH_GRAPH_CLASSNAME,
|
|
NULL,
|
|
WS_VISIBLE | WS_CHILD | WS_BORDER | WS_CLIPSIBLINGS,
|
|
graphRects[0].left,
|
|
graphRects[0].top,
|
|
graphRects[0].right - graphRects[0].left,
|
|
graphRects[0].bottom - graphRects[0].top,
|
|
Context->WindowHandle,
|
|
NULL,
|
|
NULL,
|
|
&graphCreateParams
|
|
);
|
|
Graph_SetTooltip(Context->ProcessorGraphHandle, TRUE);
|
|
|
|
Context->CoreGraphHandle = PhCreateWindow(
|
|
PH_GRAPH_CLASSNAME,
|
|
NULL,
|
|
WS_VISIBLE | WS_CHILD | WS_BORDER | WS_CLIPSIBLINGS,
|
|
graphRects[1].left,
|
|
graphRects[1].top,
|
|
graphRects[1].right - graphRects[1].left,
|
|
graphRects[1].bottom - graphRects[1].top,
|
|
Context->WindowHandle,
|
|
NULL,
|
|
NULL,
|
|
&graphCreateParams
|
|
);
|
|
Graph_SetTooltip(Context->CoreGraphHandle, TRUE);
|
|
|
|
Context->DimmGraphHandle = PhCreateWindow(
|
|
PH_GRAPH_CLASSNAME,
|
|
NULL,
|
|
WS_VISIBLE | WS_CHILD | WS_BORDER | WS_CLIPSIBLINGS,
|
|
graphRects[2].left,
|
|
graphRects[2].top,
|
|
graphRects[2].right - graphRects[2].left,
|
|
graphRects[2].bottom - graphRects[2].top,
|
|
Context->WindowHandle,
|
|
NULL,
|
|
NULL,
|
|
&graphCreateParams
|
|
);
|
|
Graph_SetTooltip(Context->DimmGraphHandle, TRUE);
|
|
|
|
Context->TotalGraphHandle = PhCreateWindow(
|
|
PH_GRAPH_CLASSNAME,
|
|
NULL,
|
|
WS_VISIBLE | WS_CHILD | WS_BORDER | WS_CLIPSIBLINGS,
|
|
graphRects[3].left,
|
|
graphRects[3].top,
|
|
graphRects[3].right - graphRects[3].left,
|
|
graphRects[3].bottom - graphRects[3].top,
|
|
Context->WindowHandle,
|
|
NULL,
|
|
NULL,
|
|
&graphCreateParams
|
|
);
|
|
Graph_SetTooltip(Context->TotalGraphHandle, TRUE);
|
|
}
|
|
|
|
/**
|
|
* Invalidates all RAPL graph states and requests redraws.
|
|
*
|
|
* \param Context RAPL sysinfo context.
|
|
*/
|
|
VOID RaplDeviceUpdateGraphs(
|
|
_Inout_ PDV_RAPL_SYSINFO_CONTEXT Context
|
|
)
|
|
{
|
|
Context->ProcessorGraphState.Valid = FALSE;
|
|
Context->ProcessorGraphState.TooltipIndex = ULONG_MAX;
|
|
Graph_Update(Context->ProcessorGraphHandle);
|
|
|
|
Context->CoreGraphState.Valid = FALSE;
|
|
Context->CoreGraphState.TooltipIndex = ULONG_MAX;
|
|
Graph_Update(Context->CoreGraphHandle);
|
|
|
|
Context->DimmGraphState.Valid = FALSE;
|
|
Context->DimmGraphState.TooltipIndex = ULONG_MAX;
|
|
Graph_Update(Context->DimmGraphHandle);
|
|
|
|
Context->TotalGraphState.Valid = FALSE;
|
|
Context->TotalGraphState.TooltipIndex = ULONG_MAX;
|
|
Graph_Update(Context->TotalGraphHandle);
|
|
}
|
|
|
|
/**
|
|
* Updates the text labels shown in the RAPL device panel.
|
|
*
|
|
* \param Context RAPL sysinfo context.
|
|
*/
|
|
VOID RaplDeviceUpdatePanel(
|
|
_Inout_ PDV_RAPL_SYSINFO_CONTEXT Context
|
|
)
|
|
{
|
|
PH_FORMAT format[2];
|
|
WCHAR formatBuffer[512];
|
|
|
|
PhInitFormatF(&format[0], Context->DeviceEntry->CurrentProcessorPower, 2);
|
|
PhInitFormatS(&format[1], L" W");
|
|
|
|
if (PhFormatToBuffer(format, RTL_NUMBER_OF(format), formatBuffer, sizeof(formatBuffer), NULL))
|
|
PhSetWindowText(Context->RaplDeviceProcessorUsageLabel, formatBuffer);
|
|
else
|
|
PhSetWindowText(Context->RaplDeviceProcessorUsageLabel, L"N/A");
|
|
|
|
PhInitFormatF(&format[0], Context->DeviceEntry->CurrentCorePower, 2);
|
|
PhInitFormatS(&format[1], L" W");
|
|
|
|
if (PhFormatToBuffer(format, RTL_NUMBER_OF(format), formatBuffer, sizeof(formatBuffer), NULL))
|
|
PhSetWindowText(Context->RaplDeviceCoreUsageLabel, formatBuffer);
|
|
else
|
|
PhSetWindowText(Context->RaplDeviceCoreUsageLabel, L"N/A");
|
|
|
|
PhInitFormatF(&format[0], Context->DeviceEntry->CurrentDramPower, 2);
|
|
PhInitFormatS(&format[1], L" W");
|
|
|
|
if (PhFormatToBuffer(format, RTL_NUMBER_OF(format), formatBuffer, sizeof(formatBuffer), NULL))
|
|
PhSetWindowText(Context->RaplDeviceDimmUsageLabel, formatBuffer);
|
|
else
|
|
PhSetWindowText(Context->RaplDeviceDimmUsageLabel, L"N/A");
|
|
|
|
PhInitFormatF(&format[0], Context->DeviceEntry->CurrentDiscreteGpuPower, 2);
|
|
PhInitFormatS(&format[1], L" W");
|
|
|
|
if (PhFormatToBuffer(format, RTL_NUMBER_OF(format), formatBuffer, sizeof(formatBuffer), NULL))
|
|
PhSetWindowText(Context->RaplDeviceGpuLimitLabel, formatBuffer);
|
|
else
|
|
PhSetWindowText(Context->RaplDeviceGpuLimitLabel, L"N/A");
|
|
|
|
PhInitFormatF(&format[0], Context->DeviceEntry->CurrentComponentPower, 2);
|
|
PhInitFormatS(&format[1], L" W");
|
|
|
|
if (PhFormatToBuffer(format, RTL_NUMBER_OF(format), formatBuffer, sizeof(formatBuffer), NULL))
|
|
PhSetWindowText(Context->RaplDeviceComponentUsageLabel, formatBuffer);
|
|
else
|
|
PhSetWindowText(Context->RaplDeviceComponentUsageLabel, L"N/A");
|
|
|
|
PhInitFormatF(&format[0], Context->DeviceEntry->CurrentTotalPower, 2);
|
|
PhInitFormatS(&format[1], L" W");
|
|
|
|
if (PhFormatToBuffer(format, RTL_NUMBER_OF(format), formatBuffer, sizeof(formatBuffer), NULL))
|
|
PhSetWindowText(Context->RaplDeviceTotalUsageLabel, formatBuffer);
|
|
else
|
|
PhSetWindowText(Context->RaplDeviceTotalUsageLabel, L"N/A");
|
|
}
|
|
|
|
/**
|
|
* Lays out the RAPL graph controls inside the dialog.
|
|
*
|
|
* \param Context RAPL sysinfo context.
|
|
*/
|
|
VOID RaplDeviceLayoutGraphs(
|
|
_Inout_ PDV_RAPL_SYSINFO_CONTEXT Context
|
|
)
|
|
{
|
|
RECT labelRects[4];
|
|
RECT graphRects[4];
|
|
HDWP deferHandle;
|
|
|
|
Context->ProcessorGraphState.Valid = FALSE;
|
|
Context->ProcessorGraphState.TooltipIndex = ULONG_MAX;
|
|
Context->CoreGraphState.Valid = FALSE;
|
|
Context->CoreGraphState.TooltipIndex = ULONG_MAX;
|
|
Context->DimmGraphState.Valid = FALSE;
|
|
Context->DimmGraphState.TooltipIndex = ULONG_MAX;
|
|
Context->TotalGraphState.Valid = FALSE;
|
|
Context->TotalGraphState.TooltipIndex = ULONG_MAX;
|
|
|
|
RaplDeviceGetGraphRects(Context, labelRects, graphRects);
|
|
|
|
deferHandle = BeginDeferWindowPos(8);
|
|
|
|
deferHandle = DeferWindowPos(
|
|
deferHandle,
|
|
Context->PackageGraphLabelHandle,
|
|
NULL,
|
|
labelRects[0].left,
|
|
labelRects[0].top,
|
|
0,
|
|
0,
|
|
SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER
|
|
);
|
|
deferHandle = DeferWindowPos(
|
|
deferHandle,
|
|
Context->ProcessorGraphHandle,
|
|
NULL,
|
|
graphRects[0].left,
|
|
graphRects[0].top,
|
|
graphRects[0].right - graphRects[0].left,
|
|
graphRects[0].bottom - graphRects[0].top,
|
|
SWP_NOACTIVATE | SWP_NOZORDER
|
|
);
|
|
|
|
deferHandle = DeferWindowPos(
|
|
deferHandle,
|
|
Context->CoreGraphLabelHandle,
|
|
NULL,
|
|
labelRects[1].left,
|
|
labelRects[1].top,
|
|
0,
|
|
0,
|
|
SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER
|
|
);
|
|
deferHandle = DeferWindowPos(
|
|
deferHandle,
|
|
Context->CoreGraphHandle,
|
|
NULL,
|
|
graphRects[1].left,
|
|
graphRects[1].top,
|
|
graphRects[1].right - graphRects[1].left,
|
|
graphRects[1].bottom - graphRects[1].top,
|
|
SWP_NOACTIVATE | SWP_NOZORDER
|
|
);
|
|
|
|
deferHandle = DeferWindowPos(
|
|
deferHandle,
|
|
Context->DimmGraphLabelHandle,
|
|
NULL,
|
|
labelRects[2].left,
|
|
labelRects[2].top,
|
|
0,
|
|
0,
|
|
SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER
|
|
);
|
|
deferHandle = DeferWindowPos(
|
|
deferHandle,
|
|
Context->DimmGraphHandle,
|
|
NULL,
|
|
graphRects[2].left,
|
|
graphRects[2].top,
|
|
graphRects[2].right - graphRects[2].left,
|
|
graphRects[2].bottom - graphRects[2].top,
|
|
SWP_NOACTIVATE | SWP_NOZORDER
|
|
);
|
|
|
|
deferHandle = DeferWindowPos(
|
|
deferHandle,
|
|
Context->TotalGraphLabelHandle,
|
|
NULL,
|
|
labelRects[3].left,
|
|
labelRects[3].top,
|
|
0,
|
|
0,
|
|
SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER
|
|
);
|
|
deferHandle = DeferWindowPos(
|
|
deferHandle,
|
|
Context->TotalGraphHandle,
|
|
NULL,
|
|
graphRects[3].left,
|
|
graphRects[3].top,
|
|
graphRects[3].right - graphRects[3].left,
|
|
graphRects[3].bottom - graphRects[3].top,
|
|
SWP_NOACTIVATE | SWP_NOZORDER
|
|
);
|
|
|
|
EndDeferWindowPos(deferHandle);
|
|
}
|
|
|
|
/**
|
|
* Formats a graph Y-axis label for a single power series.
|
|
*
|
|
* \param DrawInfo Graph draw information.
|
|
* \param DataIndex Data point index.
|
|
* \param Value Normalized graph value.
|
|
* \param Parameter Scale factor used to denormalize the value.
|
|
*
|
|
* \return Formatted label string.
|
|
*/
|
|
_Function_class_(PH_GRAPH_LABEL_Y_FUNCTION)
|
|
PPH_STRING RaplGraphSingleLabelYFunction(
|
|
_In_ PPH_GRAPH_DRAW_INFO DrawInfo,
|
|
_In_ ULONG DataIndex,
|
|
_In_ FLOAT Value,
|
|
_In_ FLOAT Parameter
|
|
)
|
|
{
|
|
FLOAT value = Value * Parameter;
|
|
|
|
if (value != 0)
|
|
{
|
|
PH_FORMAT format[2];
|
|
|
|
PhInitFormatF(&format[0], value, 2);
|
|
PhInitFormatS(&format[1], L" W");
|
|
|
|
return PhFormat(format, RTL_NUMBER_OF(format), 0);
|
|
}
|
|
else
|
|
{
|
|
return PhReferenceEmptyString();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handles notifications for the package power graph.
|
|
*
|
|
* \param Context RAPL sysinfo context.
|
|
* \param Header Notification header.
|
|
*/
|
|
VOID RaplDeviceNotifyProcessorGraph(
|
|
_Inout_ PDV_RAPL_SYSINFO_CONTEXT Context,
|
|
_In_ NMHDR *Header
|
|
)
|
|
{
|
|
switch (Header->code)
|
|
{
|
|
case GCN_GETDRAWINFO:
|
|
{
|
|
PPH_GRAPH_GETDRAWINFO getDrawInfo = (PPH_GRAPH_GETDRAWINFO)Header;
|
|
PPH_GRAPH_DRAW_INFO drawInfo = getDrawInfo->DrawInfo;
|
|
|
|
drawInfo->Flags = PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_LABEL_MAX_Y;
|
|
Context->SysinfoSection->Parameters->ColorSetupFunction(drawInfo, PhGetIntegerSetting(SETTING_COLOR_CPU_KERNEL), 0, Context->SysinfoSection->Parameters->WindowDpi);
|
|
PhGraphStateGetDrawInfo(&Context->ProcessorGraphState, getDrawInfo, Context->DeviceEntry->PackageBuffer.Count);
|
|
|
|
if (!Context->ProcessorGraphState.Valid)
|
|
{
|
|
FLOAT max = 0;
|
|
|
|
PhCopyCircularBuffer_FLOAT(&Context->DeviceEntry->PackageBuffer, Context->ProcessorGraphState.Data1, drawInfo->LineDataCount);
|
|
|
|
for (ULONG i = 0; i < drawInfo->LineDataCount; i++)
|
|
{
|
|
FLOAT data = Context->ProcessorGraphState.Data1[i];
|
|
|
|
if (max < data)
|
|
max = data;
|
|
}
|
|
|
|
if (max != 0)
|
|
{
|
|
PhDivideSinglesBySingle(Context->ProcessorGraphState.Data1, max, drawInfo->LineDataCount);
|
|
}
|
|
|
|
drawInfo->LabelYFunction = RaplGraphSingleLabelYFunction;
|
|
drawInfo->LabelYFunctionParameter = max;
|
|
|
|
Context->ProcessorGraphState.Valid = TRUE;
|
|
}
|
|
}
|
|
break;
|
|
case GCN_GETTOOLTIPTEXT:
|
|
{
|
|
PPH_GRAPH_GETTOOLTIPTEXT getTooltipText = (PPH_GRAPH_GETTOOLTIPTEXT)Header;
|
|
|
|
if (getTooltipText->Index < getTooltipText->TotalCount)
|
|
{
|
|
if (Context->ProcessorGraphState.TooltipIndex != getTooltipText->Index)
|
|
{
|
|
FLOAT value;
|
|
PH_FORMAT format[3];
|
|
|
|
value = PhGetItemCircularBuffer_FLOAT(&Context->DeviceEntry->PackageBuffer, getTooltipText->Index);
|
|
|
|
// %.2f W\n%s
|
|
PhInitFormatF(&format[0], value, 2);
|
|
PhInitFormatS(&format[1], L" W\n");
|
|
PhInitFormatSR(&format[2], PH_AUTO_T(PH_STRING, PhGetStatisticsTimeString(NULL, getTooltipText->Index))->sr);
|
|
|
|
PhMoveReference(&Context->ProcessorGraphState.TooltipText, PhFormat(format, RTL_NUMBER_OF(format), 0));
|
|
}
|
|
|
|
getTooltipText->Text = PhGetStringRef(Context->ProcessorGraphState.TooltipText);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handles notifications for the core power graph.
|
|
*
|
|
* \param Context RAPL sysinfo context.
|
|
* \param Header Notification header.
|
|
*/
|
|
VOID RaplDeviceNotifyPackageGraph(
|
|
_Inout_ PDV_RAPL_SYSINFO_CONTEXT Context,
|
|
_In_ NMHDR *Header
|
|
)
|
|
{
|
|
switch (Header->code)
|
|
{
|
|
case GCN_GETDRAWINFO:
|
|
{
|
|
PPH_GRAPH_GETDRAWINFO getDrawInfo = (PPH_GRAPH_GETDRAWINFO)Header;
|
|
PPH_GRAPH_DRAW_INFO drawInfo = getDrawInfo->DrawInfo;
|
|
|
|
drawInfo->Flags = PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_LABEL_MAX_Y;
|
|
Context->SysinfoSection->Parameters->ColorSetupFunction(drawInfo, PhGetIntegerSetting(SETTING_COLOR_PHYSICAL), 0, Context->SysinfoSection->Parameters->WindowDpi);
|
|
PhGraphStateGetDrawInfo(&Context->CoreGraphState, getDrawInfo, Context->DeviceEntry->CoreBuffer.Count);
|
|
|
|
if (!Context->CoreGraphState.Valid)
|
|
{
|
|
FLOAT max = 0;
|
|
|
|
PhCopyCircularBuffer_FLOAT(&Context->DeviceEntry->CoreBuffer, Context->CoreGraphState.Data1, drawInfo->LineDataCount);
|
|
|
|
for (ULONG i = 0; i < drawInfo->LineDataCount; i++)
|
|
{
|
|
FLOAT data = Context->CoreGraphState.Data1[i];
|
|
|
|
if (max < data)
|
|
max = data;
|
|
}
|
|
|
|
if (max != 0)
|
|
{
|
|
PhDivideSinglesBySingle(Context->CoreGraphState.Data1, max, drawInfo->LineDataCount);
|
|
}
|
|
|
|
drawInfo->LabelYFunction = RaplGraphSingleLabelYFunction;
|
|
drawInfo->LabelYFunctionParameter = max;
|
|
}
|
|
}
|
|
break;
|
|
case GCN_GETTOOLTIPTEXT:
|
|
{
|
|
PPH_GRAPH_GETTOOLTIPTEXT getTooltipText = (PPH_GRAPH_GETTOOLTIPTEXT)Header;
|
|
|
|
if (getTooltipText->Index < getTooltipText->TotalCount)
|
|
{
|
|
if (Context->CoreGraphState.TooltipIndex != getTooltipText->Index)
|
|
{
|
|
FLOAT value;
|
|
PH_FORMAT format[3];
|
|
|
|
value = PhGetItemCircularBuffer_FLOAT(&Context->DeviceEntry->CoreBuffer, getTooltipText->Index);
|
|
|
|
// %.2f W\%s
|
|
PhInitFormatF(&format[0], value, 2);
|
|
PhInitFormatS(&format[1], L" W\n");
|
|
PhInitFormatSR(&format[2], PH_AUTO_T(PH_STRING, PhGetStatisticsTimeString(NULL, getTooltipText->Index))->sr);
|
|
|
|
PhMoveReference(&Context->CoreGraphState.TooltipText, PhFormat(format, RTL_NUMBER_OF(format), 0));
|
|
}
|
|
|
|
getTooltipText->Text = PhGetStringRef(Context->CoreGraphState.TooltipText);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handles notifications for the DRAM power graph.
|
|
*
|
|
* \param Context RAPL sysinfo context.
|
|
* \param Header Notification header.
|
|
*/
|
|
VOID RaplDeviceNotifyDimmGraph(
|
|
_Inout_ PDV_RAPL_SYSINFO_CONTEXT Context,
|
|
_In_ NMHDR *Header
|
|
)
|
|
{
|
|
switch (Header->code)
|
|
{
|
|
case GCN_GETDRAWINFO:
|
|
{
|
|
PPH_GRAPH_GETDRAWINFO getDrawInfo = (PPH_GRAPH_GETDRAWINFO)Header;
|
|
PPH_GRAPH_DRAW_INFO drawInfo = getDrawInfo->DrawInfo;
|
|
|
|
drawInfo->Flags = PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_LABEL_MAX_Y;
|
|
Context->SysinfoSection->Parameters->ColorSetupFunction(drawInfo, PhGetIntegerSetting(SETTING_COLOR_IO_WRITE), 0, Context->SysinfoSection->Parameters->WindowDpi);
|
|
PhGraphStateGetDrawInfo(&Context->DimmGraphState, getDrawInfo, Context->DeviceEntry->DimmBuffer.Count);
|
|
|
|
if (!Context->DimmGraphState.Valid)
|
|
{
|
|
FLOAT max = 0;
|
|
|
|
PhCopyCircularBuffer_FLOAT(&Context->DeviceEntry->DimmBuffer, Context->DimmGraphState.Data1, drawInfo->LineDataCount);
|
|
|
|
for (ULONG i = 0; i < drawInfo->LineDataCount; i++)
|
|
{
|
|
FLOAT data = Context->DimmGraphState.Data1[i];
|
|
|
|
if (max < data)
|
|
max = data;
|
|
}
|
|
|
|
if (max != 0)
|
|
{
|
|
PhDivideSinglesBySingle(Context->DimmGraphState.Data1, max, drawInfo->LineDataCount);
|
|
}
|
|
|
|
drawInfo->LabelYFunction = RaplGraphSingleLabelYFunction;
|
|
drawInfo->LabelYFunctionParameter = max;
|
|
|
|
Context->DimmGraphState.Valid = TRUE;
|
|
}
|
|
}
|
|
break;
|
|
case GCN_GETTOOLTIPTEXT:
|
|
{
|
|
PPH_GRAPH_GETTOOLTIPTEXT getTooltipText = (PPH_GRAPH_GETTOOLTIPTEXT)Header;
|
|
|
|
if (getTooltipText->Index < getTooltipText->TotalCount)
|
|
{
|
|
if (Context->DimmGraphState.TooltipIndex != getTooltipText->Index)
|
|
{
|
|
FLOAT value;
|
|
PH_FORMAT format[3];
|
|
|
|
value = PhGetItemCircularBuffer_FLOAT(&Context->DeviceEntry->DimmBuffer, getTooltipText->Index);
|
|
|
|
// %.2f W\%s
|
|
PhInitFormatF(&format[0], value, 2);
|
|
PhInitFormatS(&format[1], L" W\n");
|
|
PhInitFormatSR(&format[2], PH_AUTO_T(PH_STRING, PhGetStatisticsTimeString(NULL, getTooltipText->Index))->sr);
|
|
|
|
PhMoveReference(&Context->DimmGraphState.TooltipText, PhFormat(format, RTL_NUMBER_OF(format), 0));
|
|
}
|
|
|
|
getTooltipText->Text = PhGetStringRef(Context->DimmGraphState.TooltipText);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handles notifications for the total power graph.
|
|
*
|
|
* \param Context RAPL sysinfo context.
|
|
* \param Header Notification header.
|
|
*/
|
|
VOID RaplDeviceNotifyTotalGraph(
|
|
_Inout_ PDV_RAPL_SYSINFO_CONTEXT Context,
|
|
_In_ NMHDR* Header
|
|
)
|
|
{
|
|
switch (Header->code)
|
|
{
|
|
case GCN_GETDRAWINFO:
|
|
{
|
|
PPH_GRAPH_GETDRAWINFO getDrawInfo = (PPH_GRAPH_GETDRAWINFO)Header;
|
|
PPH_GRAPH_DRAW_INFO drawInfo = getDrawInfo->DrawInfo;
|
|
|
|
drawInfo->Flags = PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_LABEL_MAX_Y;
|
|
Context->SysinfoSection->Parameters->ColorSetupFunction(drawInfo, PhGetIntegerSetting(SETTING_COLOR_PRIVATE), 0, Context->SysinfoSection->Parameters->WindowDpi);
|
|
PhGraphStateGetDrawInfo(&Context->TotalGraphState, getDrawInfo, Context->DeviceEntry->TotalBuffer.Count);
|
|
|
|
if (!Context->TotalGraphState.Valid)
|
|
{
|
|
FLOAT max = 0;
|
|
|
|
PhCopyCircularBuffer_FLOAT(&Context->DeviceEntry->TotalBuffer, Context->TotalGraphState.Data1, drawInfo->LineDataCount);
|
|
|
|
for (ULONG i = 0; i < drawInfo->LineDataCount; i++)
|
|
{
|
|
FLOAT data = Context->TotalGraphState.Data1[i];
|
|
|
|
if (max < data)
|
|
max = data;
|
|
}
|
|
|
|
if (max != 0)
|
|
{
|
|
PhDivideSinglesBySingle(Context->TotalGraphState.Data1, max, drawInfo->LineDataCount);
|
|
}
|
|
|
|
drawInfo->LabelYFunction = RaplGraphSingleLabelYFunction;
|
|
drawInfo->LabelYFunctionParameter = max;
|
|
|
|
Context->TotalGraphState.Valid = TRUE;
|
|
}
|
|
}
|
|
break;
|
|
case GCN_GETTOOLTIPTEXT:
|
|
{
|
|
PPH_GRAPH_GETTOOLTIPTEXT getTooltipText = (PPH_GRAPH_GETTOOLTIPTEXT)Header;
|
|
|
|
if (getTooltipText->Index < getTooltipText->TotalCount)
|
|
{
|
|
if (Context->TotalGraphState.TooltipIndex != getTooltipText->Index)
|
|
{
|
|
FLOAT value;
|
|
PH_FORMAT format[3];
|
|
|
|
value = PhGetItemCircularBuffer_FLOAT(&Context->DeviceEntry->TotalBuffer, getTooltipText->Index);
|
|
|
|
// %.2f W\%s
|
|
PhInitFormatF(&format[0], value, 2);
|
|
PhInitFormatS(&format[1], L" W\n");
|
|
PhInitFormatSR(&format[2], PH_AUTO_T(PH_STRING, PhGetStatisticsTimeString(NULL, getTooltipText->Index))->sr);
|
|
|
|
PhMoveReference(&Context->TotalGraphState.TooltipText, PhFormat(format, RTL_NUMBER_OF(format), 0));
|
|
}
|
|
|
|
getTooltipText->Text = PhGetStringRef(Context->TotalGraphState.TooltipText);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Dispatches graph messages to the correct RAPL graph handler.
|
|
*
|
|
* \param WindowHandle Graph window handle.
|
|
* \param Message Graph callback message.
|
|
* \param Parameter1 Message parameter 1.
|
|
* \param Parameter2 Message parameter 2.
|
|
* \param Context RAPL sysinfo context.
|
|
*
|
|
* \return TRUE after processing the graph message.
|
|
*/
|
|
_Function_class_(PH_GRAPH_MESSAGE_CALLBACK)
|
|
BOOLEAN RaplDeviceGraphMessageCallback(
|
|
_In_ HWND WindowHandle,
|
|
_In_ ULONG Message,
|
|
_In_ PVOID Parameter1,
|
|
_In_ PVOID Parameter2,
|
|
_In_ PVOID Context
|
|
)
|
|
{
|
|
PDV_RAPL_SYSINFO_CONTEXT context = (PDV_RAPL_SYSINFO_CONTEXT)Context;
|
|
NMHDR *header = (NMHDR *)Parameter1;
|
|
|
|
if (WindowHandle == context->ProcessorGraphHandle)
|
|
{
|
|
RaplDeviceNotifyProcessorGraph(context, header);
|
|
}
|
|
else if (WindowHandle == context->CoreGraphHandle)
|
|
{
|
|
RaplDeviceNotifyPackageGraph(context, header);
|
|
}
|
|
else if (WindowHandle == context->DimmGraphHandle)
|
|
{
|
|
RaplDeviceNotifyDimmGraph(context, header);
|
|
}
|
|
else if (WindowHandle == context->TotalGraphHandle)
|
|
{
|
|
RaplDeviceNotifyTotalGraph(context, header);
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
/**
|
|
* Refreshes the RAPL device dialog contents for the current sample.
|
|
*
|
|
* \param Context RAPL sysinfo context.
|
|
*/
|
|
VOID RaplDeviceTickDialog(
|
|
_Inout_ PDV_RAPL_SYSINFO_CONTEXT Context
|
|
)
|
|
{
|
|
RaplDeviceUpdateGraphs(Context);
|
|
RaplDeviceUpdatePanel(Context);
|
|
}
|
|
|
|
/**
|
|
* Handles the main RAPL device dialog.
|
|
*
|
|
* \param WindowHandle Dialog window handle.
|
|
* \param WindowMessage Window message identifier.
|
|
* \param wParam Message-specific wParam value.
|
|
* \param lParam Message-specific lParam value.
|
|
*
|
|
* \return Dialog procedure result.
|
|
*/
|
|
INT_PTR CALLBACK RaplDeviceDialogProc(
|
|
_In_ HWND WindowHandle,
|
|
_In_ UINT WindowMessage,
|
|
_In_ WPARAM wParam,
|
|
_In_ LPARAM lParam
|
|
)
|
|
{
|
|
PDV_RAPL_SYSINFO_CONTEXT context = NULL;
|
|
|
|
if (WindowMessage == WM_INITDIALOG)
|
|
{
|
|
context = (PDV_RAPL_SYSINFO_CONTEXT)lParam;
|
|
|
|
PhSetWindowContext(WindowHandle, PH_WINDOW_CONTEXT_DEFAULT, context);
|
|
}
|
|
else
|
|
{
|
|
context = PhGetWindowContext(WindowHandle, PH_WINDOW_CONTEXT_DEFAULT);
|
|
}
|
|
|
|
if (context == NULL)
|
|
return FALSE;
|
|
|
|
switch (WindowMessage)
|
|
{
|
|
case WM_INITDIALOG:
|
|
{
|
|
PPH_LAYOUT_ITEM graphItem;
|
|
PPH_LAYOUT_ITEM panelItem;
|
|
|
|
context->WindowHandle = WindowHandle;
|
|
PhInitializeLayoutManager(&context->LayoutManager, WindowHandle);
|
|
PhAddLayoutItem(&context->LayoutManager, GetDlgItem(WindowHandle, IDC_DEVICENAME), NULL, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT | PH_LAYOUT_FORCE_INVALIDATE);
|
|
graphItem = PhAddLayoutItem(&context->LayoutManager, GetDlgItem(WindowHandle, IDC_GRAPH_LAYOUT), NULL, PH_ANCHOR_ALL);
|
|
panelItem = PhAddLayoutItem(&context->LayoutManager, GetDlgItem(WindowHandle, IDC_PANEL_LAYOUT), NULL, PH_ANCHOR_LEFT | PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
|
|
context->GraphMargin = graphItem->Margin;
|
|
context->GraphMarginScaled = context->GraphMargin;
|
|
PhGetMarginDpiValue(&context->GraphMarginScaled, context->SysinfoSection->Parameters->WindowDpi, TRUE);
|
|
|
|
RaplDeviceInitializeDialogDpi(context);
|
|
|
|
SetWindowFont(GetDlgItem(WindowHandle, IDC_TITLE), context->SysinfoSection->Parameters->LargeFont, FALSE);
|
|
SetWindowFont(GetDlgItem(WindowHandle, IDC_DEVICENAME), context->SysinfoSection->Parameters->MediumFont, FALSE);
|
|
PhSetDialogItemText(WindowHandle, IDC_DEVICENAME, PhGetStringOrDefault(context->DeviceEntry->DeviceName, L"Unknown"));
|
|
|
|
context->RaplDevicePanel = PhCreateDialog(PluginInstance->DllBase, MAKEINTRESOURCE(IDD_RAPLDEVICE_PANEL), WindowHandle, RaplDevicePanelDialogProc, context);
|
|
ShowWindow(context->RaplDevicePanel, SW_SHOW);
|
|
PhAddLayoutItemExLogical(&context->LayoutManager, context->RaplDevicePanel, NULL, PH_ANCHOR_LEFT | PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM, &panelItem->Margin);
|
|
|
|
RaplDeviceInitializeGraphStates(context);
|
|
RaplDeviceCreateGraphs(context);
|
|
RaplDeviceUpdateGraphs(context);
|
|
RaplDeviceUpdatePanel(context);
|
|
}
|
|
break;
|
|
case WM_DESTROY:
|
|
{
|
|
PhDeleteLayoutManager(&context->LayoutManager);
|
|
|
|
PhDeleteGraphState(&context->ProcessorGraphState);
|
|
PhDeleteGraphState(&context->CoreGraphState);
|
|
PhDeleteGraphState(&context->DimmGraphState);
|
|
PhDeleteGraphState(&context->TotalGraphState);
|
|
|
|
if (context->ProcessorGraphHandle)
|
|
DestroyWindow(context->ProcessorGraphHandle);
|
|
if (context->CoreGraphHandle)
|
|
DestroyWindow(context->CoreGraphHandle);
|
|
if (context->DimmGraphHandle)
|
|
DestroyWindow(context->DimmGraphHandle);
|
|
if (context->TotalGraphHandle)
|
|
DestroyWindow(context->TotalGraphHandle);
|
|
if (context->RaplDevicePanel)
|
|
DestroyWindow(context->RaplDevicePanel);
|
|
}
|
|
break;
|
|
case WM_NCDESTROY:
|
|
{
|
|
PhRemoveWindowContext(WindowHandle, PH_WINDOW_CONTEXT_DEFAULT);
|
|
}
|
|
break;
|
|
case WM_DPICHANGED_AFTERPARENT:
|
|
{
|
|
RaplDeviceInitializeDialogDpi(context);
|
|
|
|
context->GraphMarginScaled = context->GraphMargin;
|
|
PhGetMarginDpiValue(&context->GraphMarginScaled, context->SysinfoSection->Parameters->WindowDpi, TRUE);
|
|
|
|
if (context->SysinfoSection->Parameters->LargeFont)
|
|
{
|
|
SetWindowFont(GetDlgItem(WindowHandle, IDC_TITLE), context->SysinfoSection->Parameters->LargeFont, FALSE);
|
|
}
|
|
|
|
if (context->SysinfoSection->Parameters->MediumFont)
|
|
{
|
|
SetWindowFont(GetDlgItem(WindowHandle, IDC_DEVICENAME), context->SysinfoSection->Parameters->MediumFont, FALSE);
|
|
}
|
|
|
|
PhLayoutManagerUpdate(&context->LayoutManager, context->SysinfoSection->Parameters->WindowDpi);
|
|
PhLayoutManagerLayout(&context->LayoutManager);
|
|
RaplDeviceLayoutGraphs(context);
|
|
}
|
|
break;
|
|
case WM_SIZE:
|
|
{
|
|
PhLayoutManagerLayout(&context->LayoutManager);
|
|
RaplDeviceLayoutGraphs(context);
|
|
}
|
|
break;
|
|
case WM_CTLCOLORBTN:
|
|
return HANDLE_WM_CTLCOLORBTN(WindowHandle, wParam, lParam, PhWindowThemeControlColor);
|
|
case WM_CTLCOLORDLG:
|
|
return HANDLE_WM_CTLCOLORDLG(WindowHandle, wParam, lParam, PhWindowThemeControlColor);
|
|
case WM_CTLCOLORSTATIC:
|
|
return HANDLE_WM_CTLCOLORSTATIC(WindowHandle, wParam, lParam, PhWindowThemeControlColor);
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
/**
|
|
* Handles sysinfo section callbacks for a RAPL device section.
|
|
*
|
|
* \param Section Sysinfo section.
|
|
* \param Message Sysinfo callback message.
|
|
* \param Parameter1 Message parameter 1.
|
|
* \param Parameter2 Message parameter 2.
|
|
*
|
|
* \return TRUE if the message was handled.
|
|
*/
|
|
_Function_class_(PH_SYSINFO_SECTION_CALLBACK)
|
|
BOOLEAN RaplDeviceSectionCallback(
|
|
_In_ PPH_SYSINFO_SECTION Section,
|
|
_In_ PH_SYSINFO_SECTION_MESSAGE Message,
|
|
_In_ PVOID Parameter1,
|
|
_In_ PVOID Parameter2
|
|
)
|
|
{
|
|
PDV_RAPL_SYSINFO_CONTEXT context = (PDV_RAPL_SYSINFO_CONTEXT)Section->Context;
|
|
|
|
switch (Message)
|
|
{
|
|
case SysInfoCreate:
|
|
{
|
|
if (PhIsNullOrEmptyString(context->DeviceEntry->DeviceName))
|
|
{
|
|
PPH_STRING deviceName;
|
|
|
|
if (QueryRaplDeviceInterfaceInfo(PhGetString(context->DeviceEntry->Id.DevicePath), NULL, &deviceName))
|
|
{
|
|
PhMoveReference(&context->DeviceEntry->DeviceName, deviceName);
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
case SysInfoDestroy:
|
|
{
|
|
PhDereferenceObject(context->DeviceEntry);
|
|
PhFree(context);
|
|
}
|
|
return TRUE;
|
|
case SysInfoTick:
|
|
{
|
|
if (context->WindowHandle)
|
|
{
|
|
RaplDeviceTickDialog(context);
|
|
}
|
|
}
|
|
return TRUE;
|
|
case SysInfoViewChanging:
|
|
{
|
|
PH_SYSINFO_VIEW_TYPE view = (PH_SYSINFO_VIEW_TYPE)PtrToUlong(Parameter1);
|
|
PPH_SYSINFO_SECTION section = (PPH_SYSINFO_SECTION)Parameter2;
|
|
|
|
if (view == SysInfoSummaryView || section != Section)
|
|
return TRUE;
|
|
|
|
if (context->ProcessorGraphHandle)
|
|
{
|
|
context->ProcessorGraphState.Valid = FALSE;
|
|
context->ProcessorGraphState.TooltipIndex = ULONG_MAX;
|
|
Graph_Draw(context->ProcessorGraphHandle);
|
|
}
|
|
|
|
if (context->CoreGraphHandle)
|
|
{
|
|
context->CoreGraphState.Valid = FALSE;
|
|
context->CoreGraphState.TooltipIndex = ULONG_MAX;
|
|
Graph_Draw(context->CoreGraphHandle);
|
|
}
|
|
|
|
if (context->DimmGraphHandle)
|
|
{
|
|
context->DimmGraphState.Valid = FALSE;
|
|
context->DimmGraphState.TooltipIndex = ULONG_MAX;
|
|
Graph_Draw(context->DimmGraphHandle);
|
|
}
|
|
|
|
if (context->TotalGraphHandle)
|
|
{
|
|
context->TotalGraphState.Valid = FALSE;
|
|
context->TotalGraphState.TooltipIndex = ULONG_MAX;
|
|
Graph_Draw(context->TotalGraphHandle);
|
|
}
|
|
}
|
|
return TRUE;
|
|
case SysInfoCreateDialog:
|
|
{
|
|
PPH_SYSINFO_CREATE_DIALOG createDialog = (PPH_SYSINFO_CREATE_DIALOG)Parameter1;
|
|
|
|
createDialog->Instance = PluginInstance->DllBase;
|
|
createDialog->Template = MAKEINTRESOURCE(IDD_RAPLDEVICE_DIALOG);
|
|
createDialog->DialogProc = RaplDeviceDialogProc;
|
|
createDialog->Parameter = context;
|
|
}
|
|
return TRUE;
|
|
case SysInfoGraphGetDrawInfo:
|
|
{
|
|
PPH_GRAPH_DRAW_INFO drawInfo = (PPH_GRAPH_DRAW_INFO)Parameter1;
|
|
|
|
drawInfo->Flags = PH_GRAPH_USE_GRID_X | PH_GRAPH_USE_GRID_Y | PH_GRAPH_LABEL_MAX_Y;
|
|
Section->Parameters->ColorSetupFunction(drawInfo, PhGetIntegerSetting(SETTING_COLOR_PRIVATE), 0, context->SysinfoSection->Parameters->WindowDpi);
|
|
PhGetDrawInfoGraphBuffers(&Section->GraphState.Buffers, drawInfo, context->DeviceEntry->TotalBuffer.Count);
|
|
|
|
if (!Section->GraphState.Valid)
|
|
{
|
|
FLOAT max = 0;
|
|
|
|
PhCopyCircularBuffer_FLOAT(&context->DeviceEntry->TotalBuffer, Section->GraphState.Data1, drawInfo->LineDataCount);
|
|
|
|
for (ULONG i = 0; i < drawInfo->LineDataCount; i++)
|
|
{
|
|
FLOAT data = Section->GraphState.Data1[i];
|
|
|
|
if (max < data)
|
|
max = data;
|
|
}
|
|
|
|
if (max != 0)
|
|
{
|
|
PhDivideSinglesBySingle(Section->GraphState.Data1, max, drawInfo->LineDataCount);
|
|
}
|
|
|
|
drawInfo->LabelYFunction = RaplGraphSingleLabelYFunction;
|
|
drawInfo->LabelYFunctionParameter = max;
|
|
|
|
Section->GraphState.Valid = TRUE;
|
|
}
|
|
}
|
|
return TRUE;
|
|
case SysInfoGraphGetTooltipText:
|
|
{
|
|
PPH_SYSINFO_GRAPH_GET_TOOLTIP_TEXT getTooltipText = (PPH_SYSINFO_GRAPH_GET_TOOLTIP_TEXT)Parameter1;
|
|
FLOAT value;
|
|
PH_FORMAT format[3];
|
|
|
|
value = PhGetItemCircularBuffer_FLOAT(&context->DeviceEntry->TotalBuffer, getTooltipText->Index);
|
|
|
|
// %.2f W\%s
|
|
PhInitFormatF(&format[0], value, 2);
|
|
PhInitFormatS(&format[1], L" W\n");
|
|
PhInitFormatSR(&format[2], PH_AUTO_T(PH_STRING, PhGetStatisticsTimeString(NULL, getTooltipText->Index))->sr);
|
|
|
|
PhMoveReference(&Section->GraphState.TooltipText, PhFormat(format, RTL_NUMBER_OF(format), 0));
|
|
getTooltipText->Text = PhGetStringRef(Section->GraphState.TooltipText);
|
|
}
|
|
return TRUE;
|
|
case SysInfoGraphDrawPanel:
|
|
{
|
|
PPH_SYSINFO_DRAW_PANEL drawPanel = (PPH_SYSINFO_DRAW_PANEL)Parameter1;
|
|
PH_FORMAT format[2];
|
|
|
|
drawPanel->Title = PhCreateString(L"RAPL");
|
|
|
|
// %.2f W
|
|
PhInitFormatF(&format[0], context->DeviceEntry->CurrentTotalPower, 2);
|
|
PhInitFormatS(&format[1], L" W");
|
|
|
|
drawPanel->SubTitle = PhFormat(format, RTL_NUMBER_OF(format), 0);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
/**
|
|
* Registers a RAPL device as a sysinfo section.
|
|
*
|
|
* \param Pointers Plugin sysinfo callback table.
|
|
* \param DeviceEntry RAPL device entry.
|
|
*/
|
|
VOID RaplDeviceSysInfoInitializing(
|
|
_In_ PPH_PLUGIN_SYSINFO_POINTERS Pointers,
|
|
_In_ _Assume_refs_(1) PDV_RAPL_ENTRY DeviceEntry
|
|
)
|
|
{
|
|
static PH_STRINGREF text = PH_STRINGREF_INIT(L"RAPL");
|
|
PDV_RAPL_SYSINFO_CONTEXT context;
|
|
PH_SYSINFO_SECTION section;
|
|
|
|
context = PhAllocateZero(sizeof(DV_RAPL_SYSINFO_CONTEXT));
|
|
context->DeviceEntry = PhReferenceObject(DeviceEntry);
|
|
|
|
memset(§ion, 0, sizeof(PH_SYSINFO_SECTION));
|
|
section.Context = context;
|
|
section.Callback = RaplDeviceSectionCallback;
|
|
section.Name = text;
|
|
|
|
context->SysinfoSection = Pointers->CreateSection(§ion);
|
|
}
|