summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2018-03-27 14:00:32 -0700
committerCaleb Bassi <calebjbassi@gmail.com>2018-03-27 14:00:32 -0700
commit86c5c7155acfb695926081eedd16e365687032d1 (patch)
treef94ba3771cc1d32eafa8b2a78055e96a3c0a6e9e
parentbfd6382f6b1723d63de80acef83194b04c3aea8d (diff)
Average cpu usage when more than 8 cores
-rw-r--r--gotop.go8
-rw-r--r--widgets/cpu.go28
2 files changed, 24 insertions, 12 deletions
diff --git a/gotop.go b/gotop.go
index 6f67906..4369465 100644
--- a/gotop.go
+++ b/gotop.go
@@ -167,8 +167,12 @@ func widgetColors() {
mem.LineColor["Swap"] = ui.Color(colorscheme.SwapMem)
LineColor := make(map[string]ui.Color)
- for i := 0; i < len(cpu.Data); i++ {
- LineColor[fmt.Sprintf("CPU%d", i+1)] = ui.Color(colorscheme.CPULines[i])
+ if cpu.Count <= 8 {
+ for i := 0; i < len(cpu.Data); i++ {
+ LineColor[fmt.Sprintf("CPU%d", i+1)] = ui.Color(colorscheme.CPULines[i])
+ }
+ } else {
+ LineColor["Average"] = ui.Color(colorscheme.CPULines[0])
}
cpu.LineColor = LineColor
diff --git a/widgets/cpu.go b/widgets/cpu.go
index 6065279..9d57eba 100644
--- a/widgets/cpu.go
+++ b/widgets/cpu.go
@@ -10,7 +10,7 @@ import (
type CPU struct {
*ui.LineGraph
- count int // number of CPUs
+ Count int // number of CPUs
interval time.Duration
}
@@ -18,14 +18,18 @@ func NewCPU(interval time.Duration, zoom int) *CPU {
count, _ := psCPU.Counts(false)
c := &CPU{
LineGraph: ui.NewLineGraph(),
- count: count,
+ Count: count,
interval: interval,
}
c.Label = "CPU Usage"
c.Zoom = zoom
- for i := 0; i < c.count; i++ {
- key := "CPU" + strconv.Itoa(i+1)
- c.Data[key] = []float64{0}
+ if c.Count <= 8 {
+ for i := 0; i < c.Count; i++ {
+ key := "CPU" + strconv.Itoa(i+1)
+ c.Data[key] = []float64{0}
+ }
+ } else {
+ c.Data["Average"] = []float64{0}
}
go c.update()
@@ -41,10 +45,14 @@ func NewCPU(interval time.Duration, zoom int) *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(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])
+ if c.Count <= 8 {
+ 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])
+ }
+ } else {
+ percent, _ := psCPU.Percent(c.interval, false)
+ c.Data["Average"] = append(c.Data["Average"], percent[0])
}
}