Skip to content

Commit

Permalink
Gets the NVidia extension options working, including marshalling.
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxserxxx committed Mar 4, 2021
1 parent a44ced4 commit efcb0e9
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 7 deletions.
4 changes: 4 additions & 0 deletions cmd/gotop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 14 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,6 +45,8 @@ type Config struct {
ExtensionVars map[string]string
ConfigFile string
Tr lingo.Translations
Nvidia bool
NvidiaRefresh time.Duration
}

func NewConfig() Config {
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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()
}

Expand All @@ -270,4 +282,5 @@ const (
export = "metricsexportport"
mbps = "mbps"
temperatures = "temperatures"
nvidia = "nvidia"
)
7 changes: 1 addition & 6 deletions devices/nvidia.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"strconv"
"sync"
"time"

"github.com/xxxserxxx/opflag"
)

// Set up variables and register this plug-in with the main code.
Expand All @@ -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)
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -180,5 +177,3 @@ func update() {
}
}
}

var nvidia bool
2 changes: 2 additions & 0 deletions translations/dicts/de_DE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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|layouts|colorschemes|paths|keys|langs>
devices: Druckt Gerätenamen für filterbare Widgets aus
Expand Down
2 changes: 2 additions & 0 deletions translations/dicts/en_US.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <devices|layouts|colorschemes|paths|keys|langs>
Expand Down
2 changes: 2 additions & 0 deletions translations/dicts/eo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <devices|layouts|colorschemes|paths|keys|langs>
Expand Down
2 changes: 2 additions & 0 deletions translations/dicts/fr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <devices|layouts|colorschemes|paths|keys|langs>
Expand Down
2 changes: 2 additions & 0 deletions translations/dicts/tt_TT.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions translations/dicts/zh_CN.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export="在指定端口上启用指标输出。"
mbps="显示网速为 mbps。"
test="执行测试并返回成功或失败码。"
conffile="用于替代缺省参数的配置文件(必须是第一个参数)"
nvidia="启用NVidia GPU指标"
nvidiarefresh="刷新频率。接受了大多数时间单位。"
list="""
列出 <devices|layouts|colorschemes|paths|keys|langs>
devices: 显示可用于过滤的设备名
Expand Down

0 comments on commit efcb0e9

Please sign in to comment.