Skip to content

Commit

Permalink
display: prevent div-by-zero
Browse files Browse the repository at this point in the history
  • Loading branch information
robertswiecki committed Apr 10, 2018
1 parent 4fbedca commit b3d0245
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions display.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ static unsigned getCpuUse(long num_cpu, int64_t elapsed_millis) {
uint64_t allCycles = num_cpu * sysconf(_SC_CLK_TCK) * elapsed_millis / 1000;
prevIdleT = idleT;

if (allCycles == 0) {
return 0;
}

return (allCycles - idleCycles) * num_cpu * 100 / allCycles;
}

Expand Down

0 comments on commit b3d0245

Please sign in to comment.