Fixes #123, refresh delay on start

This commit is contained in:
Sean E. Russell 2020-05-01 12:41:18 -05:00
parent 4563131b2a
commit f2c63eb1b4
3 changed files with 7 additions and 8 deletions

View File

@ -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))
//}()

View File

@ -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)

View File

@ -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}
}