Stormfetch will now list all GPUs if multiple of them are connected

This commit is contained in:
CapCreeperGR 2024-06-09 14:39:24 +03:00
parent 7b8c017ed0
commit efdbe94193
4 changed files with 21 additions and 8 deletions

View File

@ -33,4 +33,6 @@ run: build/stormfetch
build/stormfetch
clean:
rm -r build/
rm -r build/
.PHONY: build

View File

@ -6,7 +6,10 @@ echo -e "${C3}Kernel: ${C4}$(uname -s) $(uname -r)"
echo -e "${C3}Packages: ${C4}$(get_packages)"
echo -e "${C3}Shell: ${C4}${USER_SHELL}"
if [ ! -z "$CPU_MODEL" ]; then echo -e "${C3}CPU: ${C4}${CPU_MODEL} (${CPU_THREADS} threads)"; fi
if [ ! -z "$GPU_MODEL" ]; then echo -e "${C3}GPU: ${C4}${GPU_MODEL}"; fi
for i in $(seq ${CONNECTED_GPUS}); do
gpu="GPU$i"
echo -e "${C3}GPU: ${C4}${!gpu}"
done
if [ ! -z "$MEM_TOTAL" ] && [ ! -z "$MEM_USED" ]; then echo -e "${C3}Memory: ${C4}${MEM_USED} MiB / ${MEM_TOTAL} MiB"; fi
for i in $(seq ${MOUNTED_PARTITIONS}); do
device="PARTITION${i}_DEVICE"

11
main.go
View File

@ -141,8 +141,15 @@ func SetupFetchEnv() []string {
env["MONITOR"+strconv.Itoa(i+1)] = monitor
}
}
if getGPUName() != "" {
env["GPU_MODEL"] = getGPUName()
gpus := getGPUNames()
if len(gpus) != 0 {
env["CONNECTED_GPUS"] = strconv.Itoa(len(gpus))
for i, gpu := range gpus {
if gpu == "" {
continue
}
env["GPU"+strconv.Itoa(i+1)] = gpu
}
}
var ret = make([]string, len(env))

View File

@ -119,7 +119,8 @@ func getCPUThreads() int {
return int(cpu.TotalThreads)
}
func getGPUName() string {
func getGPUNames() []string {
var ret []string
null, _ := os.Open(os.DevNull)
serr := os.Stderr
os.Stderr = null
@ -127,14 +128,14 @@ func getGPUName() string {
defer null.Close()
os.Stderr = serr
if err != nil {
return ""
return nil
}
for _, graphics := range gpu.GraphicsCards {
if graphics.DeviceInfo != nil {
return graphics.DeviceInfo.Product.Name
ret = append(ret, graphics.DeviceInfo.Product.Name)
}
}
return ""
return ret
}
type Memory struct {