VOID NvGpuUpdate( VOID ) { static ULONG runCount = 0; // MUST keep in sync with runCount in process provider if (runCount != 0) { NvGpuUpdateValues(); PhAddItemCircularBuffer_FLOAT(&GpuUtilizationHistory, GpuCurrentGpuUsage); PhAddItemCircularBuffer_ULONG(&GpuMemoryHistory, GpuCurrentMemUsage); PhAddItemCircularBuffer_FLOAT(&GpuBoardHistory, GpuCurrentCoreUsage); PhAddItemCircularBuffer_FLOAT(&GpuBusHistory, GpuCurrentBusUsage); } runCount++; }
static BOOLEAN NvGpuSectionCallback( _In_ PPH_SYSINFO_SECTION Section, _In_ PH_SYSINFO_SECTION_MESSAGE Message, _In_opt_ PVOID Parameter1, _In_opt_ PVOID Parameter2 ) { PPH_NVGPU_SYSINFO_CONTEXT context = (PPH_NVGPU_SYSINFO_CONTEXT)Section->Context; switch (Message) { case SysInfoCreate: { ULONG sampleCount; sampleCount = PhGetIntegerSetting(L"SampleCount"); PhInitializeCircularBuffer_FLOAT(&context->GpuUtilizationHistory, sampleCount); PhInitializeCircularBuffer_ULONG(&context->GpuMemoryHistory, sampleCount); PhInitializeCircularBuffer_FLOAT(&context->GpuBoardHistory, sampleCount); PhInitializeCircularBuffer_FLOAT(&context->GpuBusHistory, sampleCount); } return TRUE; case SysInfoDestroy: { if (context->GpuName) PhDereferenceObject(context->GpuName); PhDeleteCircularBuffer_FLOAT(&context->GpuUtilizationHistory); PhDeleteCircularBuffer_ULONG(&context->GpuMemoryHistory); PhDeleteCircularBuffer_FLOAT(&context->GpuBoardHistory); PhDeleteCircularBuffer_FLOAT(&context->GpuBusHistory); PhFree(context); } return TRUE; case SysInfoTick: { NvGpuUpdateValues(); PhAddItemCircularBuffer_FLOAT(&context->GpuUtilizationHistory, GpuCurrentGpuUsage); PhAddItemCircularBuffer_ULONG(&context->GpuMemoryHistory, GpuCurrentMemUsage); PhAddItemCircularBuffer_FLOAT(&context->GpuBoardHistory, GpuCurrentCoreUsage); PhAddItemCircularBuffer_FLOAT(&context->GpuBusHistory, GpuCurrentBusUsage); } return TRUE; case SysInfoCreateDialog: { PPH_SYSINFO_CREATE_DIALOG createDialog = (PPH_SYSINFO_CREATE_DIALOG)Parameter1; createDialog->Instance = PluginInstance->DllBase; createDialog->Template = MAKEINTRESOURCE(IDD_GPU_DIALOG); createDialog->DialogProc = NvGpuDialogProc; 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; Section->Parameters->ColorSetupFunction(drawInfo, PhGetIntegerSetting(L"ColorCpuKernel"), 0); PhGetDrawInfoGraphBuffers(&Section->GraphState.Buffers, drawInfo, context->GpuUtilizationHistory.Count); if (!Section->GraphState.Valid) { PhCopyCircularBuffer_FLOAT(&context->GpuUtilizationHistory, Section->GraphState.Data1, drawInfo->LineDataCount); Section->GraphState.Valid = TRUE; } } return TRUE; case SysInfoGraphGetTooltipText: { FLOAT gpuUsageValue; PPH_SYSINFO_GRAPH_GET_TOOLTIP_TEXT getTooltipText = (PPH_SYSINFO_GRAPH_GET_TOOLTIP_TEXT)Parameter1; gpuUsageValue = PhGetItemCircularBuffer_FLOAT(&context->GpuUtilizationHistory, getTooltipText->Index); PhMoveReference(&Section->GraphState.TooltipText, PhFormatString( L"%.0f%%\n%s", gpuUsageValue * 100, ((PPH_STRING)PhAutoDereferenceObject(PhGetStatisticsTimeString(NULL, getTooltipText->Index)))->Buffer )); getTooltipText->Text = Section->GraphState.TooltipText->sr; } return TRUE; case SysInfoGraphDrawPanel: { PPH_SYSINFO_DRAW_PANEL drawPanel = (PPH_SYSINFO_DRAW_PANEL)Parameter1; drawPanel->Title = PhCreateString(Section->Name.Buffer); drawPanel->SubTitle = PhFormatString( L"%.0f%%", GpuCurrentGpuUsage * 100 ); } return TRUE; } return FALSE; }
static INT_PTR CALLBACK NvGpuDialogProc( _In_ HWND hwndDlg, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { PPH_NVGPU_SYSINFO_CONTEXT context = NULL; if (uMsg == WM_INITDIALOG) { context = (PPH_NVGPU_SYSINFO_CONTEXT)lParam; SetProp(hwndDlg, L"Context", (HANDLE)context); } else { context = (PPH_NVGPU_SYSINFO_CONTEXT)GetProp(hwndDlg, L"Context"); if (uMsg == WM_NCDESTROY) { PhDeleteLayoutManager(&context->LayoutManager); PhDeleteGraphState(&context->GpuGraphState); PhDeleteGraphState(&context->MemGraphState); PhDeleteGraphState(&context->SharedGraphState); PhDeleteGraphState(&context->BusGraphState); if (context->GpuGraphHandle) DestroyWindow(context->GpuGraphHandle); if (context->MemGraphHandle) DestroyWindow(context->MemGraphHandle); if (context->SharedGraphHandle) DestroyWindow(context->SharedGraphHandle); if (context->BusGraphHandle) DestroyWindow(context->BusGraphHandle); if (context->GpuPanel) DestroyWindow(context->GpuPanel); PhUnregisterCallback(&PhProcessesUpdatedEvent, &context->ProcessesUpdatedRegistration); RemoveProp(hwndDlg, L"Context"); } } if (context == NULL) return FALSE; switch (uMsg) { case WM_INITDIALOG: { PPH_LAYOUT_ITEM graphItem; PPH_LAYOUT_ITEM panelItem; context->WindowHandle = hwndDlg; context->GpuLabelHandle = GetDlgItem(hwndDlg, IDC_GPU_L); context->MemLabelHandle = GetDlgItem(hwndDlg, IDC_MEMORY_L); context->SharedLabelHandle = GetDlgItem(hwndDlg, IDC_SHARED_L); context->BusLabelHandle = GetDlgItem(hwndDlg, IDC_BUS_L); PhInitializeGraphState(&context->GpuGraphState); PhInitializeGraphState(&context->MemGraphState); PhInitializeGraphState(&context->SharedGraphState); PhInitializeGraphState(&context->BusGraphState); PhInitializeLayoutManager(&context->LayoutManager, hwndDlg); PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_GPUNAME), NULL, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT | PH_LAYOUT_FORCE_INVALIDATE); graphItem = PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_GRAPH_LAYOUT), NULL, PH_ANCHOR_ALL); context->GpuGraphMargin = graphItem->Margin; panelItem = PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_PANEL_LAYOUT), NULL, PH_ANCHOR_LEFT | PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM); SendMessage(GetDlgItem(hwndDlg, IDC_TITLE), WM_SETFONT, (WPARAM)context->Section->Parameters->LargeFont, FALSE); SendMessage(GetDlgItem(hwndDlg, IDC_GPUNAME), WM_SETFONT, (WPARAM)context->Section->Parameters->MediumFont, FALSE); SetDlgItemText(hwndDlg, IDC_GPUNAME, context->GpuName->Buffer); context->GpuPanel = CreateDialogParam(PluginInstance->DllBase, MAKEINTRESOURCE(IDD_GPU_PANEL), hwndDlg, NvGpuPanelDialogProc, (LPARAM)context); ShowWindow(context->GpuPanel, SW_SHOW); PhAddLayoutItemEx(&context->LayoutManager, context->GpuPanel, NULL, PH_ANCHOR_LEFT | PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM, panelItem->Margin); NvGpuCreateGraphs(context); NvGpuUpdateValues(); NvGpuUpdateGraphs(context); NvGpuUpdatePanel(context); PhRegisterCallback( &PhProcessesUpdatedEvent, ProcessesUpdatedHandler, context, &context->ProcessesUpdatedRegistration ); } break; case WM_SIZE: NvGpuLayoutGraphs(context); break; case WM_NOTIFY: { NMHDR* header = (NMHDR*)lParam; if (header->hwndFrom == context->GpuGraphHandle) { NvGpuNotifyUsageGraph(context, header); } else if (header->hwndFrom == context->MemGraphHandle) { NvGpuNotifyMemoryGraph(context, header); } else if (header->hwndFrom == context->SharedGraphHandle) { NvGpuNotifySharedGraph(context, header); } else if (header->hwndFrom == context->BusGraphHandle) { NvGpuNotifyBusGraph(context, header); } } break; case MSG_UPDATE: { NvGpuUpdateGraphs(context); NvGpuUpdatePanel(context); } break; } return FALSE; }