1 /* 2 * Copyright (c) 2019 - 2020 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __STACK_SIZE_ANALYZER_H 8 #define __STACK_SIZE_ANALYZER_H 9 10 #include <stddef.h> 11 #include <zephyr/kernel/thread.h> 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 /** @defgroup thread_analyzer Thread analyzer 18 * @ingroup os_services 19 * @brief Module for analyzing threads 20 * 21 * This module implements functions and the configuration that simplifies 22 * thread analysis. 23 * @{ 24 */ 25 26 struct thread_analyzer_info { 27 /** The name of the thread or stringified address of the thread handle 28 * if name is not set. 29 */ 30 const char *name; 31 /** The total size of the stack*/ 32 size_t stack_size; 33 /** Stack size in used */ 34 size_t stack_used; 35 36 #ifdef CONFIG_THREAD_RUNTIME_STATS 37 unsigned int utilization; 38 #ifdef CONFIG_SCHED_THREAD_USAGE 39 k_thread_runtime_stats_t usage; 40 #endif 41 #endif 42 }; 43 44 /** @brief Thread analyzer stack size callback function 45 * 46 * Callback function with thread analysis information. 47 * 48 * @param info Thread analysis information. 49 */ 50 typedef void (*thread_analyzer_cb)(struct thread_analyzer_info *info); 51 52 /** @brief Run the thread analyzer and provide information to the callback 53 * 54 * This function analyzes the current state for all threads and calls 55 * a given callback on every thread found. 56 * 57 * @param cb The callback function handler 58 */ 59 void thread_analyzer_run(thread_analyzer_cb cb); 60 61 /** @brief Run the thread analyzer and print stack size statistics. 62 * 63 * This function runs the thread analyzer and prints the output in standard 64 * form. 65 */ 66 void thread_analyzer_print(void); 67 68 /** @} */ 69 70 #ifdef __cplusplus 71 } 72 #endif 73 74 #endif /* __STACK_SIZE_ANALYZER_H */ 75