summaryrefslogtreecommitdiffstats
path: root/devices
diff options
context:
space:
mode:
authorSean E. Russell <ser@ser1.net>2020-02-27 16:13:23 -0600
committerSean E. Russell <ser@ser1.net>2020-02-27 16:13:23 -0600
commit4fce1654c5c263797205997e7635c7d06c393a85 (patch)
tree06a0e382b9cfc292d978d45033f26aaaaa28fa12 /devices
parente38f6fc8c488ed9379efc32060be18f45b18329b (diff)
parenta5b039cd923270683a777c7e3851116076a663e9 (diff)
Merge branch 'v3.4.x' into nvidia
Diffstat (limited to 'devices')
-rw-r--r--devices/cpu_nvidia.go19
-rw-r--r--devices/devices.go21
2 files changed, 19 insertions, 21 deletions
diff --git a/devices/cpu_nvidia.go b/devices/cpu_nvidia.go
deleted file mode 100644
index ff4691c..0000000
--- a/devices/cpu_nvidia.go
+++ /dev/null
@@ -1,19 +0,0 @@
-package devices
-
-import (
- "github.com/NVIDIA/gpu-monitoring-tools/bindings/go/nvml"
- "time"
-)
-
-func init() {
- if nvml.Init() == nil {
- shutdownFuncs = append(shutdownFuncs, func() { nvml.Shutdown() })
- deviceCounts = append(deviceCounts, func(b bool) (int, error) {
- r, e := nvml.GetDeviceCount()
- return int(r), e
- })
- devicePercents = append(devicePercents, func(t time.Duration, b bool) ([]float64, error) {
- return nil, nil
- })
- }
-}
diff --git a/devices/devices.go b/devices/devices.go
index dabb900..91a8815 100644
--- a/devices/devices.go
+++ b/devices/devices.go
@@ -1,9 +1,26 @@
package devices
-var shutdownFuncs []func()
+import "log"
+var shutdownFuncs []func() error
+
+// RegisterShutdown stores a function to be called by gotop on exit, allowing
+// extensions to properly release resources. Extensions should register a
+// shutdown function IFF the extension is using resources that need to be
+// released. The returned error will be logged, but no other action will be
+// taken.
+func RegisterShutdown(f func() error) {
+ shutdownFuncs = append(shutdownFuncs, f)
+}
+
+// Shutdown will be called by the `main()` function if gotop is exited
+// cleanly. It will call all of the registered shutdown functions of devices,
+// logging all errors but otherwise not responding to them.
func Shutdown() {
for _, f := range shutdownFuncs {
- f()
+ err := f()
+ if err != nil {
+ log.Print(err)
+ }
}
}