Merge branch 'v4.0.2' into master
This commit is contained in:
commit
72cde05458
|
@ -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`.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
23
devices/cpu_linux.go
Normal file
23
devices/cpu_linux.go
Normal file
|
@ -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
|
||||
}
|
9
devices/cpu_other.go
Normal file
9
devices/cpu_other.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
// +build !linux
|
||||
|
||||
package devices
|
||||
|
||||
import "github.com/shirou/gopsutil/cpu"
|
||||
|
||||
func CpuCount() (int, error) {
|
||||
return cpu.Counts(false)
|
||||
}
|
|
@ -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))
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user