Skip to content

Commit

Permalink
kernel: Add k_thread_runtime_stats_is_enabled function
Browse files Browse the repository at this point in the history
Add 'k_thread_runtime_stats_is_enabled' to 'usage.c', which's
used to check whether runtime statistics collection is
enabled for a thread.

Signed-off-by: James Roy <[email protected]>
  • Loading branch information
rruuaanng committed Oct 25, 2024
1 parent 2f23313 commit fc52903
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/zephyr/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6224,6 +6224,17 @@ 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
*

Check failure on line 6229 in include/zephyr/kernel.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

include/zephyr/kernel.h:6229 trailing whitespace
* This function checks the status of runtime statistics gathering for the
* specified thread and returns the current usage_lock status.
*

Check failure on line 6232 in include/zephyr/kernel.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

include/zephyr/kernel.h:6232 trailing whitespace
* @param thread ID of thread

Check notice on line 6233 in include/zephyr/kernel.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/kernel.h:6233 - * + * * This function checks the status of runtime statistics gathering for the * specified thread and returns the current usage_lock status. - * + *
* @return -EINVAL if invalid thread ID, otherwise return usage_lock status
*/
int k_thread_runtime_stats_is_enabled(k_tid_t thread);

/**
* @brief Enable gathering of system runtime statistics
*
Expand Down
16 changes: 16 additions & 0 deletions kernel/usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,22 @@ int k_thread_runtime_stats_disable(k_tid_t thread)

return 0;
}

int k_thread_runtime_stats_is_enabled(k_tid_t thread)
{
int status;
k_spinlock_key_t key;

CHECKIF(thread == NULL) {
return -EINVAL;
}

key = k_spin_lock(&usage_lock);
status = thread->base.usage.track_usage;
k_spin_unlock(&usage_lock, key);

return status;
}
#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 @@ -225,6 +225,7 @@ ZTEST(usage_api, test_thread_stats_enable_disable)
k_sleep(K_TICKS(2));

k_thread_runtime_stats_enable(tid);
zassert_true(k_thread_runtime_stats_is_enabled(tid));
k_thread_runtime_stats_get(_current, &stats2);
k_thread_runtime_stats_get(tid, &helper_stats2);

Expand Down

0 comments on commit fc52903

Please sign in to comment.