27 #define MSG_UPDATE (WM_APP + 1)
29 static RECT NormalGraphTextMargin = { 5, 5, 5, 5 };
30 static RECT NormalGraphTextPadding = { 3, 3, 3, 3 };
32 typedef struct _ET_DISKNET_CONTEXT
45 HWND NetworkGraphHandle;
48 ULONG64 CurrentDiskRead;
49 ULONG64 CurrentDiskWrite;
50 ULONG64 CurrentNetworkSend;
51 ULONG64 CurrentNetworkReceive;
56 PH_CIRCULAR_BUFFER_ULONG64 DiskReadHistory;
57 PH_CIRCULAR_BUFFER_ULONG64 DiskWriteHistory;
58 PH_CIRCULAR_BUFFER_ULONG64 NetworkSendHistory;
59 PH_CIRCULAR_BUFFER_ULONG64 NetworkReceiveHistory;
62 static INT_PTR CALLBACK EtwDiskNetworkPanelDialogProc(
72 static VOID EtwDiskNetworkCreateGraphs(
76 Context->DiskGraphHandle = CreateWindow(
79 WS_VISIBLE | WS_CHILD | WS_BORDER,
84 Context->WindowHandle,
91 Context->NetworkGraphHandle = CreateWindow(
94 WS_VISIBLE | WS_CHILD | WS_BORDER,
99 Context->WindowHandle,
107 static VOID EtwDiskNetworkCreatePanel(
113 Context->PanelHandle = CreateDialogParam(
116 Context->WindowHandle,
117 EtwDiskNetworkPanelDialogProc,
122 Context->PanelHandle,
125 SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOSIZE | SWP_NOZORDER
128 ShowWindow(Context->PanelHandle, SW_SHOW);
134 MapDialogRect(Context->WindowHandle, &margin);
137 &Context->LayoutManager,
138 Context->PanelHandle,
144 SendMessage(Context->WindowHandle, WM_SIZE, 0, 0);
147 static VOID EtwDiskNetworkLayoutGraphs(
154 RECT margin = { 13, 13, 13, 13 };
155 RECT innerMargin = { 10, 20, 10, 10 };
162 Context->DiskGraphState.Valid =
FALSE;
163 Context->NetworkGraphState.Valid =
FALSE;
165 GetClientRect(Context->WindowHandle, &clientRect);
168 GetWindowRect(Context->PanelHandle, &panelRect);
169 MapWindowPoints(NULL, Context->WindowHandle, (PPOINT)&panelRect, 2);
170 clientRect.bottom = panelRect.top + 10;
172 graphWidth = clientRect.right - margin.left - margin.right;
173 graphHeight = (clientRect.bottom - margin.top - margin.bottom - between * 2) / 2;
175 deferHandle = BeginDeferWindowPos(4);
177 deferHandle = DeferWindowPos(deferHandle, Context->DiskGroupBox, NULL, margin.left, margin.top, graphWidth, graphHeight, SWP_NOACTIVATE | SWP_NOZORDER);
178 deferHandle = DeferWindowPos(
180 Context->DiskGraphHandle,
182 margin.left + innerMargin.left,
183 margin.top + innerMargin.top,
184 graphWidth - innerMargin.left - innerMargin.right,
185 graphHeight - innerMargin.top - innerMargin.bottom,
186 SWP_NOACTIVATE | SWP_NOZORDER
189 deferHandle = DeferWindowPos(deferHandle, Context->NetworkGroupBox, NULL, margin.left, margin.top + graphHeight + between, graphWidth, graphHeight, SWP_NOACTIVATE | SWP_NOZORDER);
190 deferHandle = DeferWindowPos(
192 Context->NetworkGraphHandle,
194 margin.left + innerMargin.left,
195 margin.top + graphHeight + between + innerMargin.top,
196 graphWidth - innerMargin.left - innerMargin.right,
197 graphHeight - innerMargin.top - innerMargin.bottom,
198 SWP_NOACTIVATE | SWP_NOZORDER
201 EndDeferWindowPos(deferHandle);
204 static VOID EtwDiskNetworkUpdateGraphs(
208 Context->DiskGraphState.Valid =
FALSE;
209 Context->DiskGraphState.TooltipIndex = -1;
213 InvalidateRect(Context->DiskGraphHandle, NULL,
FALSE);
215 Context->NetworkGraphState.Valid =
FALSE;
216 Context->NetworkGraphState.TooltipIndex = -1;
220 InvalidateRect(Context->NetworkGraphHandle, NULL,
FALSE);
223 static VOID EtwDiskNetworkUpdatePanel(
244 static VOID EtwDiskNetworkUpdateInfo(
255 PhAddItemCircularBuffer_ULONG64(&Context->DiskReadHistory, Context->CurrentDiskRead);
256 PhAddItemCircularBuffer_ULONG64(&Context->DiskWriteHistory, Context->CurrentDiskWrite);
257 PhAddItemCircularBuffer_ULONG64(&Context->NetworkSendHistory, Context->CurrentNetworkSend);
258 PhAddItemCircularBuffer_ULONG64(&Context->NetworkReceiveHistory, Context->CurrentNetworkReceive);
261 static VOID NTAPI EtwDiskNetworkUpdateHandler(
262 _In_opt_ PVOID Parameter,
263 _In_opt_ PVOID Context
268 if (!context->Enabled)
271 if (context->WindowHandle)
273 PostMessage(context->WindowHandle,
MSG_UPDATE, 0, 0);
277 static INT_PTR CALLBACK EtwDiskNetworkPageDlgProc(
284 LPPROPSHEETPAGE propSheetPage;
291 context = propPageContext->
Context;
309 context->WindowHandle = hwndDlg;
311 context->Enabled =
TRUE;
314 propPageContext->
Context = context;
321 PhInitializeCircularBuffer_ULONG64(&context->DiskReadHistory, sampleCount);
322 PhInitializeCircularBuffer_ULONG64(&context->DiskWriteHistory, sampleCount);
323 PhInitializeCircularBuffer_ULONG64(&context->NetworkSendHistory, sampleCount);
324 PhInitializeCircularBuffer_ULONG64(&context->NetworkReceiveHistory, sampleCount);
326 EtwDiskNetworkCreateGraphs(context);
327 EtwDiskNetworkCreatePanel(context);
328 EtwDiskNetworkUpdateInfo(context);
329 EtwDiskNetworkUpdatePanel(context);
332 &PhProcessesUpdatedEvent,
333 EtwDiskNetworkUpdateHandler,
335 &context->ProcessesUpdatedRegistration
346 PhDeleteCircularBuffer_ULONG64(&context->DiskReadHistory);
347 PhDeleteCircularBuffer_ULONG64(&context->DiskWriteHistory);
348 PhDeleteCircularBuffer_ULONG64(&context->NetworkSendHistory);
349 PhDeleteCircularBuffer_ULONG64(&context->NetworkReceiveHistory);
351 if (context->DiskGraphHandle)
352 DestroyWindow(context->DiskGraphHandle);
353 if (context->NetworkGraphHandle)
354 DestroyWindow(context->NetworkGraphHandle);
355 if (context->PanelHandle)
356 DestroyWindow(context->PanelHandle);
372 LPNMHDR header = (LPNMHDR)lParam;
374 switch (header->code)
377 context->Enabled =
TRUE;
380 context->Enabled =
FALSE;
387 if (header->hwndFrom == context->DiskGraphHandle)
413 if (!context->DiskGraphState.Valid)
422 context->DiskGraphState.Data1[i] = data1 = (FLOAT)PhGetItemCircularBuffer_ULONG64(&context->DiskReadHistory, i);
423 context->DiskGraphState.Data2[i] = data2 = (FLOAT)PhGetItemCircularBuffer_ULONG64(&context->DiskWriteHistory, i);
425 if (max < data1 + data2)
435 context->DiskGraphState.Data1,
442 context->DiskGraphState.Data2,
447 context->DiskGraphState.Valid =
TRUE;
450 else if (header->hwndFrom == context->NetworkGraphHandle)
476 if (!context->NetworkGraphState.Valid)
485 context->NetworkGraphState.Data1[i] = data1 = (FLOAT)PhGetItemCircularBuffer_ULONG64(&context->NetworkReceiveHistory, i);
486 context->NetworkGraphState.Data2[i] = data2 = (FLOAT)PhGetItemCircularBuffer_ULONG64(&context->NetworkSendHistory, i);
488 if (max < data1 + data2)
498 context->NetworkGraphState.Data1,
505 context->NetworkGraphState.Data2,
510 context->NetworkGraphState.Valid =
TRUE;
521 if (header->hwndFrom == context->DiskGraphHandle)
523 if (context->DiskGraphState.TooltipIndex != getTooltipText->
Index)
525 ULONG64 diskRead = PhGetItemCircularBuffer_ULONG64(
526 &context->DiskReadHistory,
527 getTooltipText->
Index
530 ULONG64 diskWrite = PhGetItemCircularBuffer_ULONG64(
531 &context->DiskWriteHistory,
532 getTooltipText->
Index
543 getTooltipText->
Text = context->DiskGraphState.TooltipText->sr;
545 else if (header->hwndFrom == context->NetworkGraphHandle)
547 if (context->NetworkGraphState.TooltipIndex != getTooltipText->
Index)
549 ULONG64 networkSend = PhGetItemCircularBuffer_ULONG64(
550 &context->NetworkSendHistory,
551 getTooltipText->
Index
554 ULONG64 networkReceive = PhGetItemCircularBuffer_ULONG64(
555 &context->NetworkReceiveHistory,
556 getTooltipText->
Index
567 getTooltipText->
Text = context->NetworkGraphState.TooltipText->sr;
577 EtwDiskNetworkUpdateInfo(context);
578 EtwDiskNetworkUpdateGraphs(context);
579 EtwDiskNetworkUpdatePanel(context);
584 EtwDiskNetworkLayoutGraphs(context);