-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpu_vram.go
56 lines (48 loc) · 1.21 KB
/
gpu_vram.go
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
package main
import (
"fmt"
"os"
"strconv"
"strings"
"time"
)
func main() {
for {
time.Sleep(1 * time.Second)
file_content, err := os.ReadFile("/sys/class/drm/card1/device/mem_info_vram_total")
if err != nil {
continue
}
memory_total, err := strconv.Atoi(strings.Fields(string(file_content))[0])
if err != nil {
continue
}
file_content, err = os.ReadFile("/sys/class/drm/card1/device/mem_info_vram_used")
if err != nil {
continue
}
memory_used, err := strconv.Atoi(strings.Fields(string(file_content))[0])
if err != nil {
continue
}
file_content, err = os.ReadFile("/sys/class/drm/card1/device/mem_info_gtt_total")
if err != nil {
continue
}
gtt_total, err := strconv.Atoi(strings.Fields(string(file_content))[0])
if err != nil {
continue
}
file_content, err = os.ReadFile("/sys/class/drm/card1/device/mem_info_gtt_used")
if err != nil {
continue
}
gtt_used, err := strconv.Atoi(strings.Fields(string(file_content))[0])
if err != nil {
continue
}
memory_percent := (float32(memory_used) / float32(memory_total)) * 100
gtt_percent := (float32(gtt_used) / float32(gtt_total)) * 100
fmt.Printf("%.0f%% +%.0f%%\n", memory_percent, gtt_percent)
}
}