Skip to content

Commit 9f82804

Browse files
committed
Only report CPU percentage per period if period is > 0
The change in #154 lead to the CPU usage being reported for a 0s duration: cpu usage (0s): NaN% Fix this by only reporting CPU usage per period if the user specified a positive duration.
1 parent c14dce9 commit 9f82804

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

main.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@ func processInfo(pid int, period time.Duration) {
156156
if v, err := p.CPUPercent(); err == nil {
157157
fmt.Printf("cpu usage:\t%.3f%%\n", v)
158158
}
159-
if v, err := cpuPercentWithinTime(p, period); err == nil {
160-
fmt.Printf("cpu usage (%v):\t%.3f%%\n", period, v)
159+
if period > 0 {
160+
if v, err := cpuPercentWithinTime(p, period); err == nil {
161+
fmt.Printf("cpu usage (%v):\t%.3f%%\n", period, v)
162+
}
161163
}
162164
if v, err := p.Username(); err == nil {
163165
fmt.Printf("username:\t%v\n", v)

0 commit comments

Comments
 (0)