-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvstat.vala
150 lines (125 loc) · 3.62 KB
/
nvstat.vala
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using NVCtrl;
using X;
void main() {
int temp = 0, u_mem = 0, t_mem = 0, u_freq = 0, freq = 0, v_info = 0;
int gpu;
int vmem;
int vendor;
int dev_id;
char *name = "";
char *used = "";
Display nvidia_display = new Display();
int screen = nvidia_display.get_default_screen ();
stdout.printf ("DEFAULT_SCREEN: %d\n", screen);
var res = XNVCTRLQueryAttribute(
nvidia_display,
0,
0,
NV_CTRL_GPU_CORE_TEMPERATURE,
&temp
);
if(!res) {
stdout.printf("Could not query NV_CTRL_GPU_CORE_TEMPERATURE attribute!\n");
return;
}
var res1 = XNVCTRLQueryAttribute(
nvidia_display,
0,
0,
NV_CTRL_GPU_CURRENT_CLOCK_FREQS,
&freq
);
if(!res1) {
stdout.printf("Could not query NV_CTRL_GPU_CURRENT_CLOCK_FREQS attribute!\n");
return ;
}
gpu = freq>>16;
vmem = freq&0xFFFF;
var res2 = XNVCTRLQueryAttribute(
nvidia_display,
0,
0,
NV_CTRL_TOTAL_GPU_MEMORY,
&t_mem
);
if(!res2) {
stdout.printf("Could not query NV_CTRL_TOTAL_GPU_MEMORY attribute!\n");
return ;
}
t_mem = t_mem / 1024;
var res3 = XNVCTRLQueryTargetStringAttribute(
nvidia_display,
NV_CTRL_TARGET_TYPE_GPU,
0,
0,
NV_CTRL_STRING_GPU_UTILIZATION,
&used
);
var str_used = (string)used;
stdout.printf("USED_GRAPHICS: %s%\n", str_used.split_set("=,")[1]);
stdout.printf("USED_MEMORY: %s%\n", str_used.split_set("=,")[3]);
if(!res3) {
stdout.printf("Could not query NV_CTRL_STRING_GPU_UTILIZATION attribute!\n");
return ;
}
var res4 = XNVCTRLQueryTargetAttribute(
nvidia_display,
NV_CTRL_TARGET_TYPE_GPU,
0,
0,
NV_CTRL_USED_DEDICATED_GPU_MEMORY,
&u_mem
);
if(!res4) {
stdout.printf("Could not query NV_CTRL_USED_DEDICATED_GPU_MEMORY attribute!\n");
return ;
}
var res5 = XNVCTRLQueryTargetAttribute(
nvidia_display,
NV_CTRL_TARGET_TYPE_GPU,
0,
0,
NV_CTRL_GPU_CURRENT_PROCESSOR_CLOCK_FREQS,
&u_freq
);
if(!res5) {
stdout.printf("Could not query NV_CTRL_GPU_CURRENT_PROCESSOR_CLOCK_FREQS attribute!\n");
return ;
}
var res6 = XNVCTRLQueryTargetStringAttribute(
nvidia_display,
NV_CTRL_TARGET_TYPE_GPU,
0,
0,
NV_CTRL_STRING_PRODUCT_NAME,
&name
);
if(!res6) {
stdout.printf("Could not query NV_CTRL_STRING_PRODUCT_NAME attribute!\n");
return ;
}
var res7 = XNVCTRLQueryTargetAttribute(
nvidia_display,
NV_CTRL_TARGET_TYPE_GPU,
0,
0,
NV_CTRL_PCI_ID,
&v_info
);
if(!res7) {
stdout.printf("Could not query NV_CTRL_PCI_ID attribute!\n");
return ;
}
vendor = v_info>>16;
dev_id = v_info&0xFFFF;
stdout.printf("GPU_CORE_TEMPERATURE: %d°C\n", temp);
stdout.printf("GPU_CLOCK_FREQS: %d MHz\n", (int)gpu);
stdout.printf("MEM_CLOCK_FREQS: %d MHz\n", (int)vmem);
stdout.printf("TOTAL_GPU_MEMORY: %d Gb\n", t_mem);
stdout.printf("USED_GPU_MEMORY: %d Mb\n", u_mem);
stdout.printf("CURRENT_PROCESSOR_CLOCK_FREQS: %d \n", u_freq);
stdout.printf("GPU_UTILIZATION: %s\n", (string)used);
stdout.printf("PRODUCT_NAME: %s\n", (string)name);
stdout.printf("VENDOR_ID: %d\n", vendor);
stdout.printf("DEVICE_ID: %d\n", dev_id);
}