Skip to content

Instantly share code, notes, and snippets.

@PetteriAimonen
Last active February 1, 2024 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PetteriAimonen/cf9d2ef431b8abee3d8b96f11961c8ab to your computer and use it in GitHub Desktop.
Save PetteriAimonen/cf9d2ef431b8abee3d8b96f11961c8ab to your computer and use it in GitHub Desktop.
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