diff --git a/doc/releases/release-notes-4.2.rst b/doc/releases/release-notes-4.2.rst index bdebeee4c5485..8f3dec463e055 100644 --- a/doc/releases/release-notes-4.2.rst +++ b/doc/releases/release-notes-4.2.rst @@ -314,6 +314,12 @@ New APIs and options * :kconfig:option:`CONFIG_ZBUS_RUNTIME_OBSERVERS_NODE_POOL_SIZE` +Kernel +****** + +* :c:func:`k_thread_runtime_stats_is_enabled`. + + New Boards ********** diff --git a/include/zephyr/kernel.h b/include/zephyr/kernel.h index 614b2eab1b9b8..65c448c8b31f4 100644 --- a/include/zephyr/kernel.h +++ b/include/zephyr/kernel.h @@ -6576,6 +6576,16 @@ int k_thread_runtime_stats_enable(k_tid_t thread); */ int k_thread_runtime_stats_disable(k_tid_t thread); +/** + * @brief Check if runtime statistics gathering is enabled for a thread + * + * This routine checks whether the specified thread has enabled runtime statistics. + * + * @param thread ID of thread + * @return true if usage statistics are enabled for the given thread, otherwise false + */ +bool k_thread_runtime_stats_is_enabled(k_tid_t thread); + /** * @brief Enable gathering of system runtime statistics * diff --git a/kernel/usage.c b/kernel/usage.c index ad40e3ffd48a0..e5dcd364decf1 100644 --- a/kernel/usage.c +++ b/kernel/usage.c @@ -272,6 +272,11 @@ int k_thread_runtime_stats_disable(k_tid_t thread) return 0; } + +bool k_thread_runtime_stats_is_enabled(k_tid_t thread) +{ + return thread->base.usage.track_usage; +} #endif /* CONFIG_SCHED_THREAD_USAGE_ANALYSIS */ #ifdef CONFIG_SCHED_THREAD_USAGE_ALL diff --git a/tests/kernel/usage/thread_runtime_stats/src/test_thread_runtime_stats.c b/tests/kernel/usage/thread_runtime_stats/src/test_thread_runtime_stats.c index be5a1fc997449..db7ac0aaa7999 100644 --- a/tests/kernel/usage/thread_runtime_stats/src/test_thread_runtime_stats.c +++ b/tests/kernel/usage/thread_runtime_stats/src/test_thread_runtime_stats.c @@ -217,7 +217,9 @@ ZTEST(usage_api, test_thread_stats_enable_disable) k_thread_runtime_stats_get(_current, &stats1); k_thread_runtime_stats_get(tid, &helper_stats1); + zassert_true(k_thread_runtime_stats_is_enabled(tid)); k_thread_runtime_stats_disable(tid); + zassert_false(k_thread_runtime_stats_is_enabled(tid)); /* * Busy wait for the remaining tick before re-enabling the thread