Process Hacker
etwmini.c
Go to the documentation of this file.
1 /*
2  * Process Hacker Extended Tools -
3  * ETW mini information section
4  *
5  * Copyright (C) 2015 wj32
6  *
7  * This file is part of Process Hacker.
8  *
9  * Process Hacker is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * Process Hacker is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "exttools.h"
24 #include "resource.h"
25 #include "etwmini.h"
26 
28  _In_ PPH_PLUGIN_MINIINFO_POINTERS Pointers
29  )
30 {
32 
33  memset(&section, 0, sizeof(PH_MINIINFO_LIST_SECTION));
35  Pointers->CreateListSection(L"Disk", 0, &section);
36 
37  memset(&section, 0, sizeof(PH_MINIINFO_LIST_SECTION));
39 
40  Pointers->CreateListSection(L"Network", 0, &section);
41 }
42 
44  _In_ struct _PH_MINIINFO_LIST_SECTION *ListSection,
46  _In_opt_ PVOID Parameter1,
47  _In_opt_ PVOID Parameter2
48  )
49 {
50  switch (Message)
51  {
52  case MiListSectionTick:
53  {
54  PH_FORMAT format[4];
55 
56  PhInitFormatS(&format[0], L"Disk R: ");
58  format[1].Type |= FormatUsePrecision;
59  format[1].Precision = 0;
60  PhInitFormatS(&format[2], L" W: ");
62  format[3].Type |= FormatUsePrecision;
63  format[3].Precision = 0;
64  ListSection->Section->Parameters->SetSectionText(ListSection->Section,
65  PhAutoDereferenceObject(PhFormat(format, 4, 50)));
66  }
67  break;
69  {
70  PPH_MINIINFO_LIST_SECTION_SORT_LIST sortList = Parameter1;
71 
72  qsort(sortList->List->Items, sortList->List->Count,
74  }
75  return TRUE;
77  {
78  PPH_MINIINFO_LIST_SECTION_ASSIGN_SORT_DATA assignSortData = Parameter1;
79  PPH_LIST processes = assignSortData->ProcessGroup->Processes;
80  ULONG64 diskReadDelta = 0;
81  ULONG64 diskWriteDelta = 0;
82  ULONG i;
83 
84  for (i = 0; i < processes->Count; i++)
85  {
86  PPH_PROCESS_ITEM processItem = processes->Items[i];
87  PET_PROCESS_BLOCK block = EtGetProcessBlock(processItem);
88  diskReadDelta += block->DiskReadRawDelta.Delta;
89  diskWriteDelta += block->DiskWriteRawDelta.Delta;
90  }
91 
92  assignSortData->SortData->UserData[0] = diskReadDelta;
93  assignSortData->SortData->UserData[1] = diskWriteDelta;
94  }
95  return TRUE;
97  {
98  PPH_MINIINFO_LIST_SECTION_SORT_LIST sortList = Parameter1;
99 
100  qsort(sortList->List->Items, sortList->List->Count,
102  }
103  return TRUE;
105  {
106  PPH_MINIINFO_LIST_SECTION_GET_USAGE_TEXT getUsageText = Parameter1;
107  PPH_LIST processes = getUsageText->ProcessGroup->Processes;
108  ULONG64 diskReadDelta = getUsageText->SortData->UserData[0];
109  ULONG64 diskWriteDelta = getUsageText->SortData->UserData[1];
110  PH_FORMAT format[1];
111 
112  PhInitFormatSize(&format[0], diskReadDelta + diskWriteDelta);
113  PhMoveReference(&getUsageText->Line1, PhFormat(format, 1, 16));
114  }
115  return TRUE;
116  }
117 
118  return FALSE;
119 }
120 
122  _In_ const void *elem1,
123  _In_ const void *elem2
124  )
125 {
126  int result;
127  PPH_PROCESS_NODE node1 = *(PPH_PROCESS_NODE *)elem1;
128  PPH_PROCESS_NODE node2 = *(PPH_PROCESS_NODE *)elem2;
131  ULONG64 total1 = block1->DiskReadRawDelta.Delta + block1->DiskWriteRawDelta.Delta;
132  ULONG64 total2 = block2->DiskReadRawDelta.Delta + block2->DiskWriteRawDelta.Delta;
133 
134  result = uint64cmp(total2, total1);
135 
136  if (result == 0)
137  result = uint64cmp(block2->DiskReadRaw + block2->DiskWriteRaw, block1->DiskReadRaw + block1->DiskWriteRaw);
138  if (result == 0)
139  result = singlecmp(node2->ProcessItem->CpuUsage, node1->ProcessItem->CpuUsage);
140 
141  return result;
142 }
143 
145  _In_ const void *elem1,
146  _In_ const void *elem2
147  )
148 {
151 
152  return uint64cmp(data2->UserData[0] + data2->UserData[1], data1->UserData[0] + data1->UserData[1]);
153 }
154 
156  _In_ struct _PH_MINIINFO_LIST_SECTION *ListSection,
158  _In_opt_ PVOID Parameter1,
159  _In_opt_ PVOID Parameter2
160  )
161 {
162  switch (Message)
163  {
164  case MiListSectionTick:
165  {
166  PH_FORMAT format[4];
167 
168  PhInitFormatS(&format[0], L"Network R: ");
170  format[1].Type |= FormatUsePrecision;
171  format[1].Precision = 0;
172  PhInitFormatS(&format[2], L" S: ");
174  format[3].Type |= FormatUsePrecision;
175  format[3].Precision = 0;
176  ListSection->Section->Parameters->SetSectionText(ListSection->Section,
177  PhAutoDereferenceObject(PhFormat(format, 4, 50)));
178  }
179  break;
181  {
182  PPH_MINIINFO_LIST_SECTION_SORT_LIST sortList = Parameter1;
183 
184  qsort(sortList->List->Items, sortList->List->Count,
186  }
187  return TRUE;
189  {
190  PPH_MINIINFO_LIST_SECTION_ASSIGN_SORT_DATA assignSortData = Parameter1;
191  PPH_LIST processes = assignSortData->ProcessGroup->Processes;
192  ULONG64 networkReceiveDelta = 0;
193  ULONG64 networkSendDelta = 0;
194  ULONG i;
195 
196  for (i = 0; i < processes->Count; i++)
197  {
198  PPH_PROCESS_ITEM processItem = processes->Items[i];
199  PET_PROCESS_BLOCK block = EtGetProcessBlock(processItem);
200  networkReceiveDelta += block->NetworkReceiveRawDelta.Delta;
201  networkSendDelta += block->NetworkSendRawDelta.Delta;
202  }
203 
204  assignSortData->SortData->UserData[0] = networkReceiveDelta;
205  assignSortData->SortData->UserData[1] = networkSendDelta;
206  }
207  return TRUE;
209  {
210  PPH_MINIINFO_LIST_SECTION_SORT_LIST sortList = Parameter1;
211 
212  qsort(sortList->List->Items, sortList->List->Count,
214  }
215  return TRUE;
217  {
218  PPH_MINIINFO_LIST_SECTION_GET_USAGE_TEXT getUsageText = Parameter1;
219  PPH_LIST processes = getUsageText->ProcessGroup->Processes;
220  ULONG64 networkReceiveDelta = getUsageText->SortData->UserData[0];
221  ULONG64 networkSendDelta = getUsageText->SortData->UserData[1];
222  PH_FORMAT format[1];
223 
224  PhInitFormatSize(&format[0], networkReceiveDelta + networkSendDelta);
225  PhMoveReference(&getUsageText->Line1, PhFormat(format, 1, 16));
226  }
227  return TRUE;
228  }
229 
230  return FALSE;
231 }
232 
234  _In_ const void *elem1,
235  _In_ const void *elem2
236  )
237 {
238  int result;
239  PPH_PROCESS_NODE node1 = *(PPH_PROCESS_NODE *)elem1;
240  PPH_PROCESS_NODE node2 = *(PPH_PROCESS_NODE *)elem2;
243  ULONG64 total1 = block1->NetworkReceiveRawDelta.Delta + block1->NetworkSendRawDelta.Delta;
244  ULONG64 total2 = block2->NetworkReceiveRawDelta.Delta + block2->NetworkSendRawDelta.Delta;
245 
246  result = uint64cmp(total2, total1);
247 
248  if (result == 0)
249  result = uint64cmp(block2->NetworkReceiveRaw + block2->NetworkSendRaw, block1->NetworkReceiveRaw + block1->NetworkSendRaw);
250  if (result == 0)
251  result = singlecmp(node2->ProcessItem->CpuUsage, node1->ProcessItem->CpuUsage);
252 
253  return result;
254 }
255 
257  _In_ const void *elem1,
258  _In_ const void *elem2
259  )
260 {
263 
264  return uint64cmp(data2->UserData[0] + data2->UserData[1], data1->UserData[0] + data1->UserData[1]);
265 }