Gets the NVidia extension options working, including marshalling.

This commit is contained in:
Sean E. Russell 2021-03-04 16:23:04 -06:00
parent a44ced4bba
commit efcb0e9d2a
9 changed files with 31 additions and 7 deletions

View File

@ -77,6 +77,7 @@ func parseArgs() error {
opflag.BoolVarP(&conf.Mbps, "mbps", "", conf.Mbps, tr.Value("args.mbps")) opflag.BoolVarP(&conf.Mbps, "mbps", "", conf.Mbps, tr.Value("args.mbps"))
opflag.BoolVar(&conf.Test, "test", conf.Test, tr.Value("args.test")) opflag.BoolVar(&conf.Test, "test", conf.Test, tr.Value("args.test"))
opflag.StringP("", "C", "", tr.Value("args.conffile")) 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")) list := opflag.String("list", "", tr.Value("args.list"))
wc := opflag.Bool("write-config", false, tr.Value("args.write")) wc := opflag.Bool("write-config", false, tr.Value("args.write"))
opflag.SortFlags = false opflag.SortFlags = false
@ -139,6 +140,9 @@ func parseArgs() error {
} }
os.Exit(0) os.Exit(0)
} }
if conf.Nvidia {
conf.ExtensionVars["nvidia"] = "true"
}
if *wc { if *wc {
path, err := conf.Write() path, err := conf.Write()
if err != nil { if err != nil {

View File

@ -16,10 +16,10 @@ import (
"strings" "strings"
"time" "time"
"github.com/xxxserxxx/lingo"
"github.com/shibukawa/configdir" "github.com/shibukawa/configdir"
"github.com/xxxserxxx/gotop/v4/colorschemes" "github.com/xxxserxxx/gotop/v4/colorschemes"
"github.com/xxxserxxx/gotop/v4/widgets" "github.com/xxxserxxx/gotop/v4/widgets"
"github.com/xxxserxxx/lingo"
) )
// CONFFILE is the name of the default config file // CONFFILE is the name of the default config file
@ -45,6 +45,8 @@ type Config struct {
ExtensionVars map[string]string ExtensionVars map[string]string
ConfigFile string ConfigFile string
Tr lingo.Translations Tr lingo.Translations
Nvidia bool
NvidiaRefresh time.Duration
} }
func NewConfig() Config { func NewConfig() Config {
@ -179,6 +181,12 @@ func load(in io.Reader, conf *Config) error {
conf.Mbps = true conf.Mbps = true
case temperatures: case temperatures:
conf.Temps = strings.Split(kv[1], ",") 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.Fprint(buff, "#")
} }
fmt.Fprintf(buff, "%s=%s\n", temperatures, strings.Join(c.Temps, ",")) 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() return buff.Bytes()
} }
@ -270,4 +282,5 @@ const (
export = "metricsexportport" export = "metricsexportport"
mbps = "mbps" mbps = "mbps"
temperatures = "temperatures" temperatures = "temperatures"
nvidia = "nvidia"
) )

View File

@ -9,8 +9,6 @@ import (
"strconv" "strconv"
"sync" "sync"
"time" "time"
"github.com/xxxserxxx/opflag"
) )
// Set up variables and register this plug-in with the main code. // 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 // tool periodically and puts the results into hashes; the update functions
// then just sync data from those hashes into the return data. // then just sync data from those hashes into the return data.
func init() { func init() {
opflag.BoolVarP(&nvidia, "nvidia", "", false, "Enable NVidia GPU support")
RegisterStartup(startNVidia) 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 // `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. // sets how frequently the nvidia tool is called to refresh the date.
func startNVidia(vars map[string]string) error { func startNVidia(vars map[string]string) error {
if !nvidia { if vars["nvidia"] != "true" {
return nil return nil
} }
_, err := exec.Command("nvidia-smi", "-L").Output() _, err := exec.Command("nvidia-smi", "-L").Output()
@ -180,5 +177,3 @@ func update() {
} }
} }
} }
var nvidia bool

View File

@ -87,6 +87,8 @@ export="Aktivieren Sie Metriken für den Export auf dem angegebenen Port."
mbps="Netzwerkrate als MBit / s anzeigen." mbps="Netzwerkrate als MBit / s anzeigen."
test="Führt Tests aus und beendet das Programm mit Erfolgs- / Fehlercode." 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)" 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="""
List <devices|layouts|colorschemes|paths|keys|langs> List <devices|layouts|colorschemes|paths|keys|langs>
devices: Druckt Gerätenamen für filterbare Widgets aus devices: Druckt Gerätenamen für filterbare Widgets aus

View File

@ -87,6 +87,8 @@ export="Enable metrics for export on the specified port."
mbps="Show network rate as mbps." mbps="Show network rate as mbps."
test="Runs tests and exits with success/failure code." test="Runs tests and exits with success/failure code."
conffile="Config file to use instead of default (MUST BE FIRST ARGUMENT)" 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. # TRANSLATORS: Please don't translate the **labels** ("devices", "layouts") as they don't change in the code.
list=""" list="""
List <devices|layouts|colorschemes|paths|keys|langs> List <devices|layouts|colorschemes|paths|keys|langs>

View File

@ -87,6 +87,8 @@ export="Ebligu metrikojn por eksportado en la specifita haveno."
mbps="Montri reta takson kiel mbps." mbps="Montri reta takson kiel mbps."
test="Ekzekutas testojn kaj forirojn kun sukceso / fiaska kodo." test="Ekzekutas testojn kaj forirojn kun sukceso / fiaska kodo."
conffile="Agordi dosiero por uzi anstataŭ defaŭlte (DEVAS ESTI UNUA ARGUMENTO)" 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 # TRANSLATORS: Please don't translate the list entries
list=""" list="""
List <devices|layouts|colorschemes|paths|keys|langs> List <devices|layouts|colorschemes|paths|keys|langs>

View File

@ -87,6 +87,8 @@ export="Activer l'export des mesures sur le port indiqué."
mbps="Montrer le débit réseau en mbps." mbps="Montrer le débit réseau en mbps."
test="Lancer les tests et sortir avec le code de succès ou d'échec." 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)" 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. # TRANSLATORS: Please don't translate the **labels** ("devices", "layouts") as they don't change in the code.
list=""" list="""
Énumérer <devices|layouts|colorschemes|paths|keys|langs> Énumérer <devices|layouts|colorschemes|paths|keys|langs>

View File

@ -86,6 +86,8 @@ export=".trop deificeps eht no tropxe rof scirtem elbanE"
mbps=".spbm sa etar krowten wohS" mbps=".spbm sa etar krowten wohS"
test=".edoc eruliaf/sseccus htiw stixe dna stset snuR" test=".edoc eruliaf/sseccus htiw stixe dna stset snuR"
conffile=")TNEMUGRA TSRIF EB TSUM( tluafed fo daetsni esu ot elif gifnoC" 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=""" list="""
>snart|syek|shtap|semehcsroloc|stuoyal|secived< tsiL >snart|syek|shtap|semehcsroloc|stuoyal|secived< tsiL
stegdiw elbaretlif rof seman ecived tuo stnirP :secived stegdiw elbaretlif rof seman ecived tuo stnirP :secived

View File

@ -87,6 +87,8 @@ export="在指定端口上启用指标输出。"
mbps="显示网速为 mbps。" mbps="显示网速为 mbps。"
test="执行测试并返回成功或失败码。" test="执行测试并返回成功或失败码。"
conffile="用于替代缺省参数的配置文件(必须是第一个参数)" conffile="用于替代缺省参数的配置文件(必须是第一个参数)"
nvidia="启用NVidia GPU指标"
nvidiarefresh="刷新频率。接受了大多数时间单位。"
list=""" list="""
<devices|layouts|colorschemes|paths|keys|langs> <devices|layouts|colorschemes|paths|keys|langs>
devices: devices: