Process Hacker
gpumini.c
Go to the documentation of this file.
1 /*
2  * Process Hacker Extended Tools -
3  * GPU 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 "gpumini.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"GPU", 0, &section);
36 }
37 
39  _In_ struct _PH_MINIINFO_LIST_SECTION *ListSection,
41  _In_opt_ PVOID Parameter1,
42  _In_opt_ PVOID Parameter2
43  )
44 {
45  switch (Message)
46  {
47  case MiListSectionTick:
48  {
49  ListSection->Section->Parameters->SetSectionText(ListSection->Section,
50  PhaFormatString(L"GPU %.2f%%", EtGpuNodeUsage * 100));
51  }
52  break;
54  {
55  PPH_MINIINFO_LIST_SECTION_SORT_LIST sortList = Parameter1;
56 
57  qsort(sortList->List->Items, sortList->List->Count,
59  }
60  return TRUE;
62  {
63  PPH_MINIINFO_LIST_SECTION_ASSIGN_SORT_DATA assignSortData = Parameter1;
64  PPH_LIST processes = assignSortData->ProcessGroup->Processes;
65  FLOAT gpuUsage = 0;
66  ULONG i;
67 
68  for (i = 0; i < processes->Count; i++)
69  {
70  PPH_PROCESS_ITEM processItem = processes->Items[i];
71  PET_PROCESS_BLOCK block = EtGetProcessBlock(processItem);
72  gpuUsage += block->GpuNodeUsage;
73  }
74 
75  *(PFLOAT)assignSortData->SortData->UserData = gpuUsage;
76  }
77  return TRUE;
79  {
80  PPH_MINIINFO_LIST_SECTION_SORT_LIST sortList = Parameter1;
81 
82  qsort(sortList->List->Items, sortList->List->Count,
84  }
85  return TRUE;
87  {
88  PPH_MINIINFO_LIST_SECTION_GET_USAGE_TEXT getUsageText = Parameter1;
89  PPH_LIST processes = getUsageText->ProcessGroup->Processes;
90  FLOAT gpuUsage = *(PFLOAT)getUsageText->SortData->UserData;
91 
92  PhMoveReference(&getUsageText->Line1, PhFormatString(L"%.2f%%", gpuUsage * 100));
93  }
94  return TRUE;
95  }
96 
97  return FALSE;
98 }
99 
101  _In_ const void *elem1,
102  _In_ const void *elem2
103  )
104 {
105  int result;
106  PPH_PROCESS_NODE node1 = *(PPH_PROCESS_NODE *)elem1;
107  PPH_PROCESS_NODE node2 = *(PPH_PROCESS_NODE *)elem2;
110 
111  result = singlecmp(block2->GpuNodeUsage, block1->GpuNodeUsage);
112 
113  if (result == 0)
114  result = uint64cmp(block2->GpuRunningTimeDelta.Value, block1->GpuRunningTimeDelta.Value);
115  if (result == 0)
116  result = singlecmp(node2->ProcessItem->CpuUsage, node1->ProcessItem->CpuUsage);
117 
118  return result;
119 }
120 
122  _In_ const void *elem1,
123  _In_ const void *elem2
124  )
125 {
128 
129  return singlecmp(*(PFLOAT)data2->UserData, *(PFLOAT)data1->UserData);
130 }