From f2c63eb1b4cd1df3f7e79a9cc2f23e04d028a69b Mon Sep 17 00:00:00 2001 From: "Sean E. Russell" Date: Fri, 1 May 2020 12:41:18 -0500 Subject: [PATCH] Fixes #123, refresh delay on start --- cmd/gotop/main.go | 4 ++-- devices/cpu.go | 6 +++--- devices/cpu_cpu.go | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cmd/gotop/main.go b/cmd/gotop/main.go index 23ed512..bd00b66 100644 --- a/cmd/gotop/main.go +++ b/cmd/gotop/main.go @@ -67,7 +67,7 @@ func parseArgs() error { opflag.BoolVarP(&conf.AverageLoad, "averagecpu", "a", conf.AverageLoad, "Show average CPU in the CPU widget.") fahrenheit := opflag.BoolP("fahrenheit", "f", conf.TempScale == 'F', "Show temperatures in fahrenheit.Show temperatures in fahrenheit.") opflag.BoolVarP(&conf.Statusbar, "statusbar", "s", conf.Statusbar, "Show a statusbar with the time.") - opflag.DurationVarP(&conf.UpdateInterval, "rate", "r", conf.UpdateInterval, "Number of times per second to update CPU and Mem widgets.") + opflag.DurationVarP(&conf.UpdateInterval, "rate", "r", conf.UpdateInterval, "Refresh frequency. Most time units accepted. `1m` = refresh every minute. `100ms` = refresh every 100ms.") opflag.StringVarP(&conf.Layout, "layout", "l", conf.Layout, `Name of layout spec file for the UI. Use "-" to pipe.`) opflag.StringVarP(&conf.NetInterface, "interface", "i", "all", "Select network interface. Several interfaces can be defined using comma separated values. Interfaces can also be ignored using `!`") opflag.StringVarP(&conf.ExportPort, "export", "x", conf.ExportPort, "Enable metrics for export on the specified port.") @@ -336,7 +336,7 @@ func eventLoop(c gotop.Config, grid *layout.MyGrid) { // TODO: state:merge #135 linux console font (cmatsuoka/console-font) func main() { - // For performance testing + // TODO: Make this an option, for performance testing //go func() { // log.Fatal(http.ListenAndServe(":7777", nil)) //}() diff --git a/devices/cpu.go b/devices/cpu.go index 436ccb1..b4a9799 100644 --- a/devices/cpu.go +++ b/devices/cpu.go @@ -5,7 +5,7 @@ import ( "time" ) -var cpuFuncs []func(map[string]int, time.Duration, bool) map[string]error +var cpuFuncs []func(map[string]int, bool) map[string]error // RegisterCPU adds a new CPU device to the CPU widget. labels returns the // names of the devices; they should be as short as possible, and the indexes @@ -16,7 +16,7 @@ var cpuFuncs []func(map[string]int, time.Duration, bool) map[string]error // // labels may be called once and the value cached. This means the number of // cores should not change dynamically. -func RegisterCPU(f func(map[string]int, time.Duration, bool) map[string]error) { +func RegisterCPU(f func(map[string]int, bool) map[string]error) { cpuFuncs = append(cpuFuncs, f) } @@ -24,7 +24,7 @@ func RegisterCPU(f func(map[string]int, time.Duration, bool) map[string]error) { // Returns one value per cpu, or a single value if percpu is set to false. func UpdateCPU(cpus map[string]int, interval time.Duration, logical bool) { for _, f := range cpuFuncs { - errs := f(cpus, interval, logical) + errs := f(cpus, logical) if errs != nil { for k, e := range errs { log.Printf("%s: %s", k, e) diff --git a/devices/cpu_cpu.go b/devices/cpu_cpu.go index 42eff2e..1ee50f7 100644 --- a/devices/cpu_cpu.go +++ b/devices/cpu_cpu.go @@ -2,13 +2,12 @@ package devices import ( "fmt" - "time" psCpu "github.com/shirou/gopsutil/cpu" ) func init() { - f := func(cpus map[string]int, iv time.Duration, l bool) map[string]error { + f := func(cpus map[string]int, l bool) map[string]error { cpuCount, err := psCpu.Counts(l) if err != nil { return nil @@ -17,7 +16,7 @@ func init() { if cpuCount > 10 { formatString = "CPU%02d" } - vals, err := psCpu.Percent(iv, l) + vals, err := psCpu.Percent(0, l) if err != nil { return map[string]error{"gopsutil": err} }