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.
Problem
The
compute_cpu_usage
function relied on redundant operations and inefficient handling of cached system times. This could lead to unnecessary updates to system times, resulting in reduced efficiency and increased overhead.Solution
I updated the function to use cached values unless the time elapsed since the previous values were cached exceeds MINIMUM_CPU_UPDATE_INTERVAL, ensuring system times are only refreshed when necessary.
GetSystemTimes
, andfiletime_to_u64
.Now, after each call to
compute_cpu_usage
if the last time these values were retrieved ( a call toGetSystemTimes
took place ) is less than MINIMUM_CPU_UPDATE_INTERVAL ( system values haven't updated ) the function will use the values used previously. Otherwise,GetSystemTimes
will be called, values will be retrieved, and an Instant::now() value will be saved in cpu_calc_values to determine the timeGetSystemTimes
was last called.Tests
cargo test
.Other
cargo fmt
andcargo clippy
were ran successfully.