diff --git a/.gitignore b/.gitignore index 4f062d6..2d8fcb4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ /release +*.exe + +/.idea diff --git a/Makefile b/Makefile index 38609e4..5624965 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ clean: .PHONY: build build: clean - go build -o "${APP}" ${BUILDFLAGS} + go build ${BUILDFLAGS} .PHONY: install install: diff --git a/load.go b/load.go new file mode 100644 index 0000000..aff1209 --- /dev/null +++ b/load.go @@ -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) +} diff --git a/load_windows.go b/load_windows.go new file mode 100644 index 0000000..48ccdf4 --- /dev/null +++ b/load_windows.go @@ -0,0 +1,5 @@ +package main + +func printLoad(format Format, precision int) { + // todo: implement printLoad on windows +} diff --git a/statusline.go b/statusline.go index 350a076..f0728c3 100644 --- a/statusline.go +++ b/statusline.go @@ -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], "") - 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