The library provides methods to parse the contents of a pci.ids
file
and export methods to query the parsed data. It has been created
as a stripped down, but more performant alternative to jaypipes/pcidb.
Because of this minimalistic approach only functions for parsing and
querying are provided, without any extra features (see Limitations).
The following features are not included:
- No caching
- No fetching of
pci.ids
via network - No search for
pci.ids
files locally
go get github.com/hertg/go-pciids
// you have to create a bufio.scanner yourself
filepath := "/usr/share/hwdata/pci.ids"
file, _ := os.Open(filepath)
scanner := bufio.NewScanner(file)
// pass the scanner to the NewDB method
db, err := pciids.NewDB(scanner)
Names and labels of vendors, devices, and classes can be easily
retrieved by using the Find...Label
methods available inside the
pciids
package.
db.FindClassLabel(0x03) // 'Display controller'
db.FindSubclassLabel(0x03, 0x00) // 'VGA compatible controller'
db.FindVendorLabel(0x1002) // 'Advanced Micro Devices, Inc. [AMD/ATI]'
db.FindDeviceLabel(0x1002, 0x73bf) // 'Navi 21 [Radeon RX 6800/6800 XT / 6900 XT]'
db.FindSubsystemLabel(0x148c, 0x2408) // 'Red Devil AMD Radeon RX 6900 XT'
The DB
can also be traversed manually,
see a quick overview of the DB structure.
DB
├─ vendors
│ ├─ devices
│ │ └─ subsystems
│ └─ subsystems
├─ devices
│ └─ subsystems
├─ subsystems
└─ classes
└─ subclasses
└─ progifs
It parses the vendor, device, and class IDs directly to unsigned integers. This prevents unnecessary string allocations and significantly improves performance.
It has been found that this library parses at 2-3 times the speed while using roughly half the amount memory in comparison to jaypipes/pcidb.
goos: linux
goarch: amd64
pkg: github.com/hertg/go-pciids/pkg/pciids
cpu: AMD Ryzen 9 5950X 16-Core Processor
BenchmarkGoPCIIDS-32 100 16775134 ns/op 6400548 B/op 116541 allocs/op
BenchmarkPCIDB-32 37 29394779 ns/op 11972032 B/op 184512 allocs/op
PASS
ok github.com/hertg/go-pciids/pkg/pciids 2.813s