summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean E. Russell <ser@ser1.net>2020-08-25 08:25:39 -0500
committerSean E. Russell <ser@ser1.net>2020-08-25 08:25:39 -0500
commit72cde0545887f98e58423c1495327276daa202b5 (patch)
tree21bbad30c0434bbba95b71cd0c95e5b80fc7d873
parentc25e58e79c704b9e2b34e27ea342d12fa26b00b3 (diff)
parentfa9357d1ed084529e75fe7e04457c45d30843601 (diff)
Merge branch 'v4.0.2' into master
-rw-r--r--README.md6
-rw-r--r--devices/cpu_cpu.go2
-rw-r--r--devices/cpu_linux.go23
-rw-r--r--devices/cpu_other.go9
-rw-r--r--devices/temp_linux.go1
-rw-r--r--widgets/batterygauge.go4
-rw-r--r--widgets/proc.go5
-rw-r--r--widgets/proc_linux.go1
8 files changed, 46 insertions, 5 deletions
diff --git a/README.md b/README.md
index b8be2df..6956921 100644
--- a/README.md
+++ b/README.md
@@ -62,7 +62,11 @@ gotop should build with most versions of Go. If you have a version other than 1
git clone https://github.com/xxxserxxx/gotop.git
cd gotop
sed -i '/^go/d' go.mod # Do this if you have go != 1.14
-go build -o gotop ./cmd/gotop
+VERS="$(git tag -l --sort=-v:refname | sed 's/v\([^-].*\)/\1/g' | head -1 | tr -d '-' ).$(git describe --long --tags | sed 's/\([^-].*\)-\([0-9]*\)-\(g.*\)/r\2.\3/g' | tr -d '-')"
+DAT=$(date +%Y%m%dT%H%M%S)
+go build -o gotop \
+ -ldflags "-X main.Version=v${VERS} -X main.BuildDate=${DAT}" \
+ ./cmd/gotop
```
Move `gotop` to somewhere in your `$PATH`.
diff --git a/devices/cpu_cpu.go b/devices/cpu_cpu.go
index 1ee50f7..9847572 100644
--- a/devices/cpu_cpu.go
+++ b/devices/cpu_cpu.go
@@ -8,7 +8,7 @@ import (
func init() {
f := func(cpus map[string]int, l bool) map[string]error {
- cpuCount, err := psCpu.Counts(l)
+ cpuCount, err := CpuCount()
if err != nil {
return nil
}
diff --git a/devices/cpu_linux.go b/devices/cpu_linux.go
new file mode 100644
index 0000000..4e836d5
--- /dev/null
+++ b/devices/cpu_linux.go
@@ -0,0 +1,23 @@
+// +build linux
+
+package devices
+
+import "github.com/shirou/gopsutil/cpu"
+
+func CpuCount() (int, error) {
+ cpuCount, err := cpu.Counts(false)
+ if err != nil {
+ return 0, err
+ }
+ if cpuCount == 0 {
+ is, err := cpu.Info()
+ if err != nil {
+ return 0, err
+ }
+ if is[0].Cores > 0 {
+ return len(is) / 2, nil
+ }
+ return len(is), nil
+ }
+ return cpuCount, nil
+}
diff --git a/devices/cpu_other.go b/devices/cpu_other.go
new file mode 100644
index 0000000..95d183f
--- /dev/null
+++ b/devices/cpu_other.go
@@ -0,0 +1,9 @@
+// +build !linux
+
+package devices
+
+import "github.com/shirou/gopsutil/cpu"
+
+func CpuCount() (int, error) {
+ return cpu.Counts(false)
+}
diff --git a/devices/temp_linux.go b/devices/temp_linux.go
index 6967232..0bd480f 100644
--- a/devices/temp_linux.go
+++ b/devices/temp_linux.go
@@ -15,6 +15,7 @@ func devs() []string {
}
sensors, err := host.SensorsTemperatures()
if err != nil {
+ // FIXME report the error
return []string{}
}
rv := make([]string, 0, len(sensors))
diff --git a/widgets/batterygauge.go b/widgets/batterygauge.go
index 135f223..02a8866 100644
--- a/widgets/batterygauge.go
+++ b/widgets/batterygauge.go
@@ -51,6 +51,10 @@ func (b *BatteryGauge) update() {
}
return
}
+ if len(bats) < 1 {
+ b.Label = fmt.Sprintf("N/A")
+ return
+ }
mx := 0.0
cu := 0.0
charging := "%d%% ⚡%s"
diff --git a/widgets/proc.go b/widgets/proc.go
index f47f646..218ba63 100644
--- a/widgets/proc.go
+++ b/widgets/proc.go
@@ -9,9 +9,8 @@ import (
"strings"
"time"
- psCPU "github.com/shirou/gopsutil/cpu"
-
tui "github.com/gizak/termui/v3"
+ "github.com/xxxserxxx/gotop/v4/devices"
ui "github.com/xxxserxxx/gotop/v4/termui"
"github.com/xxxserxxx/gotop/v4/utils"
)
@@ -49,7 +48,7 @@ type ProcWidget struct {
}
func NewProcWidget() *ProcWidget {
- cpuCount, err := psCPU.Counts(false)
+ cpuCount, err := devices.CpuCount()
if err != nil {
log.Printf("failed to get CPU count from gopsutil: %v", err)
}
diff --git a/widgets/proc_linux.go b/widgets/proc_linux.go
index 164319d..8fb53a0 100644
--- a/widgets/proc_linux.go
+++ b/widgets/proc_linux.go
@@ -19,6 +19,7 @@ func getProcs() ([]Proc, error) {
procs := []Proc{}
for _, line := range linesOfProcStrings {
+ log.Printf("line is '%s', pid is '%s', cpu is '%s', mem is '%s'", line, strings.TrimSpace(line[0:10]), strings.TrimSpace(line[63:68]), strings.TrimSpace(line[69:74]))
pid, err := strconv.Atoi(strings.TrimSpace(line[0:10]))
if err != nil {
log.Printf("failed to convert PID to int: %v. line: %v", err, line)