CPU usage statistics
-
I would like to see the following statistics of my CPU usage:
last: min, avg, max
current: min, avg, max
It is required to update the "current" set of values on regular basis.*** Updating current statistics can be implemented as follows (assuming we have calculated current CPU usage):
total, count = total + usage, count + 1
min = usage if usage < min
max = usage if usage > max
avg = total / countThe "last" set of values is just a snapshot of current statistics. It is not necessary to implement automatic snapshots but would be great. It is required to have an ability to take snapshots manually (probably by pressing a button).
*** Sample implementation of automatic snapshots:
if count == NUMBER_OF_SAMPLES_IN_SNAPSHOT
then handle_snapshot_request()function handle_snapshot_request() {
last = current
reset(current)
total, count = 0, 0
}
-
You can just make this yourself? Store CPU usage in array and perform the min, max, avg functions on them?
-
Well, I can gather statistics myself, but I cannot see it real-time (do not suggest me to use console.log(), please) and reset without changing the code.
-
(do not suggest me to use console.log(), please)
I am gonna suggest that. Why not? And a reset isn't that hard either, just a memory item with a boolean called reset and if its set remove the statistics?