kernel: Fix gathering of runtime thread stats
The function k_thread_runtime_stats_all_get() now populates the
current_cycles field in the thread runtime stats structure.
Resets the number of cycles in the CPU's current usage window once
the idle thread is scheduled.
Fixes the average_cycles calcuation.
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
diff --git a/kernel/usage.c b/kernel/usage.c
index c29c0f8..3fb031c 100644
--- a/kernel/usage.c
+++ b/kernel/usage.c
@@ -39,16 +39,19 @@
return;
}
-#ifdef CONFIG_SCHED_THREAD_USAGE_ANALYSIS
- cpu->usage.current += cycles;
-
- if (cpu->usage.longest < cpu->usage.current) {
- cpu->usage.longest = cpu->usage.current;
- }
-#endif
-
if (cpu->current != cpu->idle_thread) {
cpu->usage.total += cycles;
+
+#ifdef CONFIG_SCHED_THREAD_USAGE_ANALYSIS
+ cpu->usage.current += cycles;
+
+ if (cpu->usage.longest < cpu->usage.current) {
+ cpu->usage.longest = cpu->usage.current;
+ }
+ } else {
+ cpu->usage.current = 0;
+ cpu->usage.num_windows++;
+#endif
}
}
#else