Skip to content

Commit 639b981

Browse files
committed
feat: add devName and devType to DRM GPU stats
1 parent 9b0219b commit 639b981

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

sysfs/class_drm_amdgpu.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"path/filepath"
2323
"regexp"
24+
"strings"
2425
"syscall"
2526

2627
"github.com/prometheus/procfs/internal/util"
@@ -47,6 +48,21 @@ type ClassDRMCardAMDGPUStats struct {
4748
MemoryVRAMVendor string // The VRAM vendor name.
4849
PowerDPMForcePerformanceLevel string // The current power performance level.
4950
UniqueID string // The unique ID of the GPU that will persist from machine to machine.
51+
DevName string // The device name.
52+
DevType string // The device type.
53+
}
54+
55+
// readDev reads the device name and type from the "device" symlink in the given directory.
56+
func readDevInfo(dir string) (string, string, error) {
57+
devicePath, devErr := filepath.EvalSymlinks(filepath.Join(dir, "device"))
58+
if devErr == nil {
59+
devPathPrefix, devName := filepath.Split(devicePath)
60+
_, devType := filepath.Split(strings.TrimRight(devPathPrefix, "/"))
61+
62+
return devName, devType, nil
63+
}
64+
65+
return "", "", devErr
5066
}
5167

5268
// ClassDRMCardAMDGPUStats returns DRM card metrics for all amdgpu cards.
@@ -117,6 +133,10 @@ func parseClassDRMAMDGPUCard(card string) (ClassDRMCardAMDGPUStats, error) {
117133
if v, err := readDRMCardField(card, "unique_id"); err == nil {
118134
stats.UniqueID = v
119135
}
136+
if n, t, err := readDevInfo(card); err == nil {
137+
stats.DevName = n
138+
stats.DevType = t
139+
}
120140

121141
return stats, nil
122142
}

sysfs/class_drm_amdgpu_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ func TestClassDRMCardAMDGPUStats(t *testing.T) {
4646
MemoryVRAMVendor: "samsung",
4747
PowerDPMForcePerformanceLevel: "manual",
4848
UniqueID: "0123456789abcdef",
49+
DevName: "device",
50+
DevType: "card0",
4951
},
5052
{
5153
Name: "card1",

0 commit comments

Comments
 (0)