-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
94 lines (79 loc) · 2.77 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include "./config/phconfig.h"
#include "./utils/getWindowsVersion.h"
#include "./src/gpuMonitor.h"
#include "./utils/Handles.h"
#include "./utils/common.h"
#pragma comment(lib, "cfgmgr32.lib")
static char* TAG = "main.cpp:\t";
void loop(GpuMonitor &monitor)
{
while (true)
{
LOGI << "\n\n";
std::vector<FLOAT_ULONG64> dataList = monitor.collect();
Sleep(1000);
LOGI << "\n===============================================================\n";
//LOGI << TAG << "GPU_TARGET_PROCESS_UTILIZATION: " << dataList[GPU_TARGET_PROCESS_UTILIZATION].float_ << "\n";
//LOGI << TAG << "GPU_SYSTEM_UTILIZATION: " << dataList[GPU_SYSTEM_UTILIZATION].float_ << "\n";
//LOGI << TAG << "GPU_TARGET_PROCESS_DEDICATED_USAGE: " << dataList[GPU_TARGET_PROCESS_DEDICATED_USAGE].ulong64_ / 1024 / 1024 << "MB \n";
LOGI << TAG << "GPU_DEDICATED_LIMIT: " << dataList[GPU_DEDICATED_LIMIT].ulong64_ / 1024 / 1024 << "MB \n";
//LOGI << TAG << "GPU_TARGET_PROCESS_SHARED_USAGE: " << dataList[GPU_TARGET_PROCESS_SHARED_USAGE].ulong64_ / 1024 / 1024 << "MB \n";
LOGI << TAG << "GPU_SHARED_LIMIT: " << dataList[GPU_SHARED_LIMIT].ulong64_ / 1024 / 1024 << "MB \n";
LOGI << TAG << "GPU_SYSTEM_DEDICATED_USAGE: " << dataList[GPU_SYSTEM_DEDICATED_USAGE].ulong64_ / 1024 / 1024 << "MB \n";
LOGI << TAG << "GPU_SYSTEM_SHARED_USAGE: " << dataList[GPU_SYSTEM_SHARED_USAGE].ulong64_ / 1024 / 1024 << "MB \n";
LOGI << "===============================================================\n";
}
}
int main(int argc, char *argv[])
{
DWORD pid = 0;
if (argc < 2)
{
LOGE << TAG << "Get Gpu memory of system merely.\n";
}
else
{
pid = std::stoul(argv[1]);
LOGI << TAG << "Monitor " << pid << "\n";
}
if (!loadDll())
{
LOGE << TAG << "loadDll Error.\n";
return 1;
}
if (!loadFunc())
{
LOGE << TAG << "loadFunc Error.\n";
return 1;
}
//ULONG WindowsVersion = 0;
//WindowsVersion = getWindowsVersion();
//printf("Vesion: %ul.\n", WindowsVersion);
if (pid == 0)
{
GpuMonitor monitor;
if (!monitor.start())
{
LOGE << TAG << "monitor.start failed.\n";
return -1;
}
LOGI << TAG << "start collect.\n";
loop(monitor);
}
else
{
GpuMonitor monitor(pid);
if (!monitor.start())
{
LOGE << TAG << "monitor.start failed.\n";
return -1;
}
LOGI << TAG << "start collect.\n";
loop(monitor);
}
LOGI << TAG << "process exit sucessfully.\n";
return 0;
}