package metrics // A trimmed PCI ID database, embedded, so a GPU is named the same on every machine — // "Intel UHD Graphics 600" — whether or not that machine has pciutils. OpenWrt has neither // lspci nor pci.ids, and the router's GPU came up as "Intel GPU 3185" beside its twin's // "Intel UHD Graphics 600" until this. scripts/pci-ids-gpu.sh regenerates the file. import ( _ "embed" "strings" "sync" ) //go:embed pciids_gpu.txt var pciIDsGPU string var pciTable struct { once sync.Once vendors map[string]string // "8086" → "Intel Corporation" devices map[string]string // "8086:3185" → "GeminiLake [UHD Graphics 600]" } // pciName looks a vendor and device ID up (hex, lower case, no 0x): the vendor's name and // the device's; empty where unknown. func pciName(vendor, device string) (string, string) { pciTable.once.Do(func() { pciTable.vendors, pciTable.devices = map[string]string{}, map[string]string{} cur := "" for _, line := range strings.Split(pciIDsGPU, "\n") { switch { case line == "" || line[0] == '#': case line[0] == '\t': if cur == "" || len(line) < 7 || line[1] == '\t' { continue // a subsystem, or a device before any vendor } pciTable.devices[cur+":"+line[1:5]] = strings.TrimSpace(line[5:]) default: if len(line) >= 6 { cur = line[:4] pciTable.vendors[cur] = strings.TrimSpace(line[4:]) } } } }) vendor, device = strings.ToLower(vendor), strings.ToLower(device) return pciTable.vendors[vendor], pciTable.devices[vendor+":"+device] }