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