Fix CPU usage error with 32bit awk and long uptimes #11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Greetings,
I have encountered the problem, that my cpu usage in the motd would show values like 103% or -97%.
After some searching i found the issue.
The version of awk on my rpi is
Note the maximum-integer of 2 billion
Output of my /proc/stat is
Note the idle time of 4 billion at position $5 (uptime is 132 days)
this causes problems when calculating the sum of all the cputimes:
and consequently awk prints an imprecise float number instead of an integer which screws up the following calculations
Forcing it to print integers doesn't work, it then hits the max value of awk
The solution was to change the math around a bit (result is of course the same), so that awk never "prints" an integer that is bigger than 2 billion
This will of course fail once the cpu "busy" time sum is bigger than 2 billion but considering that on my (admittedly very inactive) raspberry pi that sum is currently around 11 million (after 132 days of uptime) that should not happen very soon.