Skip to content

kernel: Add k_thread_runtime_stats_is_enabled function #80450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/releases/release-notes-4.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
**********

Expand Down
10 changes: 10 additions & 0 deletions include/zephyr/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this just depends on the thread struct, that header appears in the include paths already. You can make this inline without worry and save a few code bytes for users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should stick to the existing API style? It looks like there are no static inline functions in kernel.h.


/**
* @brief Enable gathering of system runtime statistics
*
Expand Down
5 changes: 5 additions & 0 deletions kernel/usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down