diff --git a/cmd/gotop/main.go b/cmd/gotop/main.go index 3a335356..94f03a8e 100644 --- a/cmd/gotop/main.go +++ b/cmd/gotop/main.go @@ -77,6 +77,7 @@ func parseArgs() error { opflag.BoolVarP(&conf.Mbps, "mbps", "", conf.Mbps, tr.Value("args.mbps")) opflag.BoolVar(&conf.Test, "test", conf.Test, tr.Value("args.test")) opflag.StringP("", "C", "", tr.Value("args.conffile")) + opflag.BoolVarP(&conf.Nvidia, "nvidia", "", conf.Nvidia, "Enable NVidia GPU support") list := opflag.String("list", "", tr.Value("args.list")) wc := opflag.Bool("write-config", false, tr.Value("args.write")) opflag.SortFlags = false @@ -139,6 +140,9 @@ func parseArgs() error { } os.Exit(0) } + if conf.Nvidia { + conf.ExtensionVars["nvidia"] = "true" + } if *wc { path, err := conf.Write() if err != nil { diff --git a/config.go b/config.go index b483f65b..30c76dbc 100644 --- a/config.go +++ b/config.go @@ -16,10 +16,10 @@ import ( "strings" "time" - "github.com/xxxserxxx/lingo" "github.com/shibukawa/configdir" "github.com/xxxserxxx/gotop/v4/colorschemes" "github.com/xxxserxxx/gotop/v4/widgets" + "github.com/xxxserxxx/lingo" ) // CONFFILE is the name of the default config file @@ -45,6 +45,8 @@ type Config struct { ExtensionVars map[string]string ConfigFile string Tr lingo.Translations + Nvidia bool + NvidiaRefresh time.Duration } func NewConfig() Config { @@ -179,6 +181,12 @@ func load(in io.Reader, conf *Config) error { conf.Mbps = true case temperatures: conf.Temps = strings.Split(kv[1], ",") + case nvidia: + nv, err := strconv.ParseBool(kv[1]) + if err != nil { + return fmt.Errorf(conf.Tr.Value("config.err.line", ln, err.Error())) + } + conf.Nvidia = nv } } @@ -252,6 +260,10 @@ func marshal(c *Config) []byte { fmt.Fprint(buff, "#") } fmt.Fprintf(buff, "%s=%s\n", temperatures, strings.Join(c.Temps, ",")) + fmt.Fprintln(buff, "# Enable NVidia GPU metrics.") + fmt.Fprintf(buff, "%s=%t\n", nvidia, c.Nvidia) + fmt.Fprintln(buff, "# To configure the NVidia refresh rate, set a duration:") + fmt.Fprintln(buff, "#nvidiarefresh=30s") return buff.Bytes() } @@ -270,4 +282,5 @@ const ( export = "metricsexportport" mbps = "mbps" temperatures = "temperatures" + nvidia = "nvidia" ) diff --git a/devices/nvidia.go b/devices/nvidia.go index 0e50dba6..8f4b21e1 100644 --- a/devices/nvidia.go +++ b/devices/nvidia.go @@ -9,8 +9,6 @@ import ( "strconv" "sync" "time" - - "github.com/xxxserxxx/opflag" ) // Set up variables and register this plug-in with the main code. @@ -27,7 +25,6 @@ import ( // tool periodically and puts the results into hashes; the update functions // then just sync data from those hashes into the return data. func init() { - opflag.BoolVarP(&nvidia, "nvidia", "", false, "Enable NVidia GPU support") RegisterStartup(startNVidia) } @@ -73,7 +70,7 @@ func updateNvidiaUsage(cpus map[string]int, _ bool) map[string]error { // `nvidia-refresh` arg, which is expected to be a time.Duration value and // sets how frequently the nvidia tool is called to refresh the date. func startNVidia(vars map[string]string) error { - if !nvidia { + if vars["nvidia"] != "true" { return nil } _, err := exec.Command("nvidia-smi", "-L").Output() @@ -180,5 +177,3 @@ func update() { } } } - -var nvidia bool diff --git a/translations/dicts/de_DE.toml b/translations/dicts/de_DE.toml index 1e52d2d7..4c1fc4e7 100644 --- a/translations/dicts/de_DE.toml +++ b/translations/dicts/de_DE.toml @@ -87,6 +87,8 @@ export="Aktivieren Sie Metriken für den Export auf dem angegebenen Port." mbps="Netzwerkrate als MBit / s anzeigen." test="Führt Tests aus und beendet das Programm mit Erfolgs- / Fehlercode." conffile="Konfigurationsdatei, die anstelle der Standardeinstellung verwendet werden soll (MUSS DAS ERSTE ARGUMENT SEIN)" +nvidia="Aktivieren Sie die NVidia-GPU-Metriken" +nvidiarefresh="Frequenz aktualisieren. Die meisten Zeiteinheiten werden akzeptiert." list=""" List devices: Druckt Gerätenamen für filterbare Widgets aus diff --git a/translations/dicts/en_US.toml b/translations/dicts/en_US.toml index cb0f8ed3..476556b6 100644 --- a/translations/dicts/en_US.toml +++ b/translations/dicts/en_US.toml @@ -87,6 +87,8 @@ export="Enable metrics for export on the specified port." mbps="Show network rate as mbps." test="Runs tests and exits with success/failure code." conffile="Config file to use instead of default (MUST BE FIRST ARGUMENT)" +nvidia="Enable NVidia GPU metrics" +nvidiarefresh="Refresh frequency. Most time units accepted." # TRANSLATORS: Please don't translate the **labels** ("devices", "layouts") as they don't change in the code. list=""" List diff --git a/translations/dicts/eo.toml b/translations/dicts/eo.toml index 5bfbb690..dfde1f58 100644 --- a/translations/dicts/eo.toml +++ b/translations/dicts/eo.toml @@ -87,6 +87,8 @@ export="Ebligu metrikojn por eksportado en la specifita haveno." mbps="Montri reta takson kiel mbps." test="Ekzekutas testojn kaj forirojn kun sukceso / fiaska kodo." conffile="Agordi dosiero por uzi anstataŭ defaŭlte (DEVAS ESTI UNUA ARGUMENTO)" +nvidia="Ebligu NVidia GPU-metrikojn" +nvidiarefresh="Refreŝigi oftecon. Plej multaj tempunuoj akceptis." # TRANSLATORS: Please don't translate the list entries list=""" List diff --git a/translations/dicts/fr.toml b/translations/dicts/fr.toml index e6a3f873..35d724a0 100644 --- a/translations/dicts/fr.toml +++ b/translations/dicts/fr.toml @@ -87,6 +87,8 @@ export="Activer l'export des mesures sur le port indiqué." mbps="Montrer le débit réseau en mbps." test="Lancer les tests et sortir avec le code de succès ou d'échec." conffile="Fichier de configuration à utiliser au lieu du fichier par défaut (DOIT ÊTRE PASSÉ EN PREMIER)" +nvidia="Activer les métriques GPU NVidia" +nvidiarefresh="Rafraîchir la fréquence. La plupart des unités de temps sont acceptées." # TRANSLATORS: Please don't translate the **labels** ("devices", "layouts") as they don't change in the code. list=""" Énumérer diff --git a/translations/dicts/tt_TT.toml b/translations/dicts/tt_TT.toml index 05e7dc2e..f83cb8f8 100644 --- a/translations/dicts/tt_TT.toml +++ b/translations/dicts/tt_TT.toml @@ -86,6 +86,8 @@ export=".trop deificeps eht no tropxe rof scirtem elbanE" mbps=".spbm sa etar krowten wohS" test=".edoc eruliaf/sseccus htiw stixe dna stset snuR" conffile=")TNEMUGRA TSRIF EB TSUM( tluafed fo daetsni esu ot elif gifnoC" +nvidia="scirtem UPG aidiVN elbanE" +nvidiarefresh=".detpecca stinu emit tsoM .ycneuqerf hserfeR" list=""" >snart|syek|shtap|semehcsroloc|stuoyal|secived< tsiL stegdiw elbaretlif rof seman ecived tuo stnirP :secived diff --git a/translations/dicts/zh_CN.toml b/translations/dicts/zh_CN.toml index e42499f0..d9de2733 100644 --- a/translations/dicts/zh_CN.toml +++ b/translations/dicts/zh_CN.toml @@ -87,6 +87,8 @@ export="在指定端口上启用指标输出。" mbps="显示网速为 mbps。" test="执行测试并返回成功或失败码。" conffile="用于替代缺省参数的配置文件(必须是第一个参数)" +nvidia="启用NVidia GPU指标" +nvidiarefresh="刷新频率。接受了大多数时间单位。" list=""" 列出 devices: 显示可用于过滤的设备名