Created
January 25, 2020 16:47
-
-
Save kraxarn/e840df0a66dbc8f6e1fe0cf735610286 to your computer and use it in GitHub Desktop.
gpuTemp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* | |
* gpuTemp | |
* Version 1.0 | |
* Licensed under WTFPL | |
* | |
* Pretty simple and bad way to display Nvidia GPU usage and temperature | |
* Only works with 2 GPUs | |
* Written in Go and Qt | |
*/ | |
import ( | |
"fmt" | |
"github.com/therecipe/qt/gui" | |
"github.com/therecipe/qt/widgets" | |
"log" | |
"os" | |
"os/exec" | |
"strconv" | |
"strings" | |
"time" | |
) | |
func update(status chan [2][2]int) { | |
for { | |
out, err := exec.Command( | |
"nvidia-smi", | |
"--format=csv", "--query-gpu=utilization.gpu,temperature.gpu").Output() | |
if err != nil { | |
log.Fatal(err) | |
} | |
result := [2][2]int{} | |
rows := strings.Split(string(out), "\n") | |
for i1, r := range rows[1:3] { | |
for i2, p := range strings.Split(r, ", ") { | |
if strings.HasSuffix(p, " %") { | |
p = p[:(len(p) - 2)] | |
} | |
result[i1][i2], _ = strconv.Atoi(p) | |
} | |
} | |
status <- result | |
time.Sleep(3000000000) | |
} | |
} | |
func main() { | |
app := widgets.NewQApplication(len(os.Args), os.Args) | |
window := widgets.NewQMainWindow(nil, 0) | |
window.SetWindowTitle("gpuTemp") | |
temps := []*widgets.QLabel{ | |
widgets.NewQLabel2("GPU 0:\t100 %\t30 C", nil, 0), | |
widgets.NewQLabel2("GPU 1:\t100 %\t30 C", nil, 0), | |
} | |
go func() { | |
ch := make(chan [2][2]int) | |
go update(ch) | |
for c := range ch { | |
for ti, t := range temps { | |
t.SetText(fmt.Sprintf("GPU %v:\t%2v %%\t%v C", ti, c[ti][0], c[ti][1])) | |
} | |
} | |
}() | |
vBox := widgets.NewQVBoxLayout() | |
for _, t := range temps { | |
t.SetFont(gui.NewQFont2("monospace", 18, -1, false)) | |
vBox.AddWidget(t, 0, 0) | |
} | |
wrapper := widgets.NewQWidget(nil, 0) | |
wrapper.SetLayout(vBox) | |
window.SetCentralWidget(wrapper) | |
window.Show() | |
app.Exec() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment