Added rate; closes #5
This commit is contained in:
parent
479491298e
commit
02219b6889
15
gotop.go
15
gotop.go
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
|
@ -28,7 +29,8 @@ var (
|
|||
|
||||
colorscheme = colorschemes.Default
|
||||
|
||||
minimal = false
|
||||
minimal = false
|
||||
interval = time.Second
|
||||
|
||||
cpu *w.CPU
|
||||
mem *w.Mem
|
||||
|
@ -48,6 +50,7 @@ Options:
|
|||
-c, --color <name> Set a colorscheme.
|
||||
-h, --help Show this screen.
|
||||
-m, --minimal Only show CPU, Mem and Process widgets.
|
||||
-r, --rate=RATE Number of times per second to update CPU and Mem widgets [default: 1].
|
||||
-v, --version Show version.
|
||||
|
||||
Colorschemes:
|
||||
|
@ -63,6 +66,10 @@ Colorschemes:
|
|||
}
|
||||
|
||||
minimal, _ = args["--minimal"].(bool)
|
||||
|
||||
rateStr, _ := args["--rate"].(string)
|
||||
rate, _ := strconv.Atoi(rateStr)
|
||||
interval = time.Second / time.Duration(rate)
|
||||
}
|
||||
|
||||
func handleColorscheme(cs string) {
|
||||
|
@ -156,8 +163,8 @@ func main() {
|
|||
// need to do this before initializing widgets so that they can inherit the colors
|
||||
termuiColors()
|
||||
|
||||
cpu = w.NewCPU()
|
||||
mem = w.NewMem()
|
||||
cpu = w.NewCPU(interval)
|
||||
mem = w.NewMem(interval)
|
||||
proc = w.NewProc(procLoaded, keyPressed)
|
||||
if !minimal {
|
||||
net = w.NewNet()
|
||||
|
@ -194,7 +201,7 @@ func main() {
|
|||
// all rendering done here
|
||||
go func() {
|
||||
ui.Render(ui.Body)
|
||||
drawTick := time.NewTicker(time.Second)
|
||||
drawTick := time.NewTicker(interval)
|
||||
for {
|
||||
select {
|
||||
case <-helpToggled:
|
||||
|
|
|
@ -14,12 +14,12 @@ type CPU struct {
|
|||
interval time.Duration
|
||||
}
|
||||
|
||||
func NewCPU() *CPU {
|
||||
func NewCPU(interval time.Duration) *CPU {
|
||||
count, _ := psCPU.Counts(false)
|
||||
c := &CPU{
|
||||
LineGraph: ui.NewLineGraph(),
|
||||
count: count,
|
||||
interval: time.Second,
|
||||
interval: interval,
|
||||
}
|
||||
c.Label = "CPU Usage"
|
||||
for i := 0; i < c.count; i++ {
|
||||
|
@ -41,7 +41,7 @@ func NewCPU() *CPU {
|
|||
func (c *CPU) update() {
|
||||
// psutil calculates the CPU usage over a 1 second interval, therefore it blocks for 1 second
|
||||
// `true` makes it so psutil doesn't group CPU usage percentages
|
||||
percent, _ := psCPU.Percent(time.Second, true)
|
||||
percent, _ := psCPU.Percent(c.interval, true)
|
||||
for i := 0; i < c.count; i++ {
|
||||
key := "CPU" + strconv.Itoa(i+1)
|
||||
c.Data[key] = append(c.Data[key], percent[i])
|
||||
|
|
|
@ -12,10 +12,10 @@ type Mem struct {
|
|||
interval time.Duration
|
||||
}
|
||||
|
||||
func NewMem() *Mem {
|
||||
func NewMem(interval time.Duration) *Mem {
|
||||
m := &Mem{
|
||||
LineGraph: ui.NewLineGraph(),
|
||||
interval: time.Second,
|
||||
interval: interval,
|
||||
}
|
||||
m.Label = "Memory Usage"
|
||||
m.Data["Main"] = []float64{0}
|
||||
|
|
Loading…
Reference in New Issue
Block a user