From 72775dbd1c6f4b94eca143bd8c0db77779aa7514 Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Wed, 8 May 2019 11:32:29 +0200 Subject: [PATCH] Ensure we collect counters continously also align output correctly --- goprocstat.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/goprocstat.go b/goprocstat.go index c66abf7..94c7986 100644 --- a/goprocstat.go +++ b/goprocstat.go @@ -15,18 +15,18 @@ func main() { flag.Parse() p, _ := process.NewProcess(int32(*flagPID)) - v, err := p.Times() name, _ := p.Name() cnt := 0 for { + v, err := p.Times() if *flagNUM >= 0 && cnt >= *flagNUM { os.Exit(0) } if err == nil { cpuUsage, _ := p.CPUPercent() - fmt.Printf("%d %s cpu: %3.2f%% user: %-3.2f system: %0.2f iowait: %0.2f irq: %0.2f softirq: %0.2f\n", + fmt.Printf("%d %s cpu: %5.2f%% user: %5.2f system: %5.2f iowait: %5.2f irq: %5.2f softirq: %5.2f\n", time.Now().Unix(), name, cpuUsage, v.User, v.System, v.Iowait, v.Irq, v.Softirq) } else { fmt.Println(err)