Gets the NVidia extension options working, including marshalling.
This commit is contained in:
parent
a44ced4bba
commit
efcb0e9d2a
|
@ -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 {
|
||||
|
|
15
config.go
15
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"
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -87,6 +87,8 @@ export="在指定端口上启用指标输出。"
|
|||
mbps="显示网速为 mbps。"
|
||||
test="执行测试并返回成功或失败码。"
|
||||
conffile="用于替代缺省参数的配置文件(必须是第一个参数)"
|
||||
nvidia="启用NVidia GPU指标"
|
||||
nvidiarefresh="刷新频率。接受了大多数时间单位。"
|
||||
list="""
|
||||
列出 <devices|layouts|colorschemes|paths|keys|langs>
|
||||
devices: 显示可用于过滤的设备名
|
||||
|
|
Loading…
Reference in New Issue
Block a user