jaypipes / ghw

Go HardWare discovery/inspection library
Apache License 2.0
1.64k stars 180 forks source link

overhaul ghw-snapshot tool #382

Closed jaypipes closed 2 weeks ago

jaypipes commented 1 month ago

This is the first step in actually overhauling the ghw library's context package and moving to a more standard context.Context usage. In order to standardize the context usage, we needed to change the way that the ghw-snapshot functionality worked to manually construct a pkg/context.Context and call pkg/context.Context:Do() while reading the snapshot tarball.

In order to do that, I created a new ghw-snapshot read command that accepts a single argument to the snapshot tarball path to read:

➜  ghw git:(overhaul-snapshot) ✗ GHW_DISABLE_WARNINGS=1 go run cmd/ghw-snapshot/main.go read testdata/snapshots/linux-amd64-intel-xeon-L5640.tar.gz
block storage (8 disks, 723GB physical storage)
cpu (2 physical packages, 12 cores, 24 hardware threads)
gpu (0 graphics cards)
memory (66GB physical, 63GB usable)
net (0 NICs)
topology NUMA (2 nodes)
chassis type=unknown vendor=unknown version=unknown
bios vendor=unknown version=unknown
baseboard vendor=unknown version=unknown product=unknown
product family=unknown name=unknown vendor=unknown sku=unknown version=unknown
PCI (82 devices)

➜  ghw git:(overhaul-snapshot) ✗ GHW_DISABLE_WARNINGS=1 go run cmd/ghw-snapshot/main.go read testdata/snapshots/linux-amd64-amd-ryzen-1600.tar.gz
block storage (8 disks, 3TB physical storage)
cpu (1 physical package, 6 cores, 12 hardware threads)
gpu (1 graphics card)
memory (32GB physical, 32GB usable)
net (4 NICs)
topology NUMA (0 nodes)
chassis type=unknown vendor=unknown version=unknown
bios vendor=unknown version=unknown
baseboard vendor=unknown version=unknown product=unknown
product family=unknown name=unknown vendor=unknown sku=unknown version=unknown
PCI (43 devices)

A followup series of patches will make the aforementioned changes to pkg/context and remove the pkg/context.Context:Do() method and put that entirely in the cmd/ghw-snapshot/command/read.go file which is the only place we actually use it.

jaypipes commented 1 month ago

@ffromani what do you think of this one? :)