Last active
February 1, 2024 13:00
-
-
Save PetteriAimonen/cf9d2ef431b8abee3d8b96f11961c8ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint32_t prev_time = get_us_ticks(); | |
uint32_t busy_time = 0; | |
uint32_t total_time = 0; | |
while(1) | |
{ | |
uint32_t time_now = get_us_ticks(); | |
uint32_t delta = time_now - prev_time; | |
prev_time = time_now; | |
if (delta > 1) | |
{ | |
busy_time += delta; | |
} | |
total_time += delta; | |
if (total_time > 100000) | |
{ | |
cpu_load = 100 * busy_time / total_time; | |
busy_time = total_time = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment