Moved printLoad() into load.go and created load_windows.go to omit it on Windows; removed usage()
This commit is contained in:
parent
d28ad1741d
commit
2a5f3fadee
5 changed files with 36 additions and 21 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,4 @@
|
|||
/release
|
||||
*.exe
|
||||
|
||||
/.idea
|
||||
|
|
2
Makefile
2
Makefile
|
@ -13,7 +13,7 @@ clean:
|
|||
|
||||
.PHONY: build
|
||||
build: clean
|
||||
go build -o "${APP}" ${BUILDFLAGS}
|
||||
go build ${BUILDFLAGS}
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
|
|
27
load.go
Normal file
27
load.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
//+build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/shirou/gopsutil/v3/load"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func printLoad(format Format, precision int) {
|
||||
l, err := load.Avg()
|
||||
if err != nil {
|
||||
panic(err) // fixme
|
||||
}
|
||||
|
||||
cpus, err := cpu.Counts(true)
|
||||
if err != nil {
|
||||
// todo: log error
|
||||
cpus = runtime.NumCPU()
|
||||
}
|
||||
if l.Load1 > float64(cpus) {
|
||||
fmt.Print(format.Warning)
|
||||
}
|
||||
fmt.Printf("[%.[1]*[2]f %.[1]*[3]f %.[1]*[4]f]",
|
||||
precision, l.Load1, l.Load5, l.Load15)
|
||||
}
|
5
load_windows.go
Normal file
5
load_windows.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package main
|
||||
|
||||
func printLoad(format Format, precision int) {
|
||||
// todo: implement printLoad on windows
|
||||
}
|
|
@ -4,10 +4,8 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/shirou/gopsutil/v3/load"
|
||||
"github.com/shirou/gopsutil/v3/mem"
|
||||
)
|
||||
|
||||
|
@ -34,24 +32,6 @@ func HBin(a uint64, precision int) string {
|
|||
return fmt.Sprintf("%.*f%s", precision, f, suffix)
|
||||
}
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintln(os.Stderr, "Usage:", os.Args[0], "<window_width>")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
func printLoad(format Format, precision int) {
|
||||
l, err := load.Avg()
|
||||
if err != nil {
|
||||
panic(err) // fixme
|
||||
}
|
||||
|
||||
if l.Load1 > float64(runtime.NumCPU()) {
|
||||
fmt.Print(format.Warning)
|
||||
}
|
||||
fmt.Printf("[%.[1]*[2]f %.[1]*[3]f %.[1]*[4]f]",
|
||||
precision, l.Load1, l.Load5, l.Load15)
|
||||
}
|
||||
|
||||
func printMem(format Format, absolute, percent bool) {
|
||||
if !(absolute || percent) {
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue