Skip to content
Merged
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/services/debugging/thread-analyzer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ Configure this module using the following options.
:kconfig:option:`CONFIG_THREAD_RUNTIME_STATS`
Print thread runtime data such as utilization.
This options is automatically selected by :kconfig:option:`CONFIG_THREAD_ANALYZER`.
:kconfig:option:`CONFIG_THREAD_ANALYZER_LONG_FRAME_PER_INTERVAL`
Reset Longest Frame value statistics after printing.
When using :kconfig:option:`SCHED_THREAD_USAGE_ANALYSIS` to get average and longest
frame thread statistics, reset the Longest Frame value to zero after each time
printing the thread statistics. This enables observation of the longest frame
during the most recent interval rather than longest frame since startup.

API documentation
*****************
Expand Down
21 changes: 21 additions & 0 deletions include/zephyr/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,27 @@ typedef int (*_poller_cb_t)(struct k_poll_event *event, uint32_t state);
* @{
*/

/**
* @brief Resets thread longest frame usage data for specified thread
*
* This routine resets the longest frame value statistic
* after printing to zero, enabling observation of the
* longest frame from the most recent interval rather than
* the longest frame since startup.
*
* @param thread Pointer to the thread to reset counter.
*
* @note @kconfig{CONFIG_THREAD_ANALYZER_LONG_FRAME_PER_INTERVAL} must
* be set for this function to be effective.
*/
static inline void
k_thread_runtime_stats_longest_frame_reset(__maybe_unused struct k_thread *thread)
{
#ifdef CONFIG_SCHED_THREAD_USAGE_ANALYSIS
thread->base.usage.longest = 0ULL;
#endif
}

typedef void (*k_thread_user_cb_t)(const struct k_thread *thread,
void *user_data);

Expand Down
8 changes: 8 additions & 0 deletions subsys/debug/thread_analyzer/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,12 @@ endif # THREAD_ANALYZER_AUTO_THREAD_PRIORITY_OVERRIDE

endif # THREAD_ANALYZER_AUTO

config THREAD_ANALYZER_LONG_FRAME_PER_INTERVAL
bool "Prints the longest frame since the last thread analyzer interval"
depends on SCHED_THREAD_USAGE_ANALYSIS
help
Resets the thread longest frame field after printing so that the next print
will show the longest frame during that interval. This enables observation
of what long frames come after the initial startup of a thread.

endif # THREAD_ANALYZER
5 changes: 5 additions & 0 deletions subsys/debug/thread_analyzer/thread_analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ static void thread_analyze_cb(const struct k_thread *cthread, void *user_data)
ARG_UNUSED(ret);

cb(&info);

#if IS_ENABLED(CONFIG_THREAD_ANALYZER_LONG_FRAME_PER_INTERVAL)
k_thread_runtime_stats_longest_frame_reset(thread);
#endif

}

K_KERNEL_STACK_ARRAY_DECLARE(z_interrupt_stacks, CONFIG_MP_MAX_NUM_CPUS,
Expand Down