zephyr/include/debug/thread_analyzer.h
Anas Nashif 802d214582 debug: analyzer: add support for thread runtime stats
Add thread runtime statistics to the thread analyser.

With CONFIG_THREAD_RUNTIME_STATS enabled:

Booting from ROM..*** Booting Zephyr OS build zephyr-v2.4.0-2330-g77be0e93e65b  ***
thread_a: Hello World from cpu 0 on qemu_x86!
Thread analyze:
 thread_b            : STACK: unused 740 usage 284 / 1024 (27 %); CPU: 0 %
 thread_analyzer     : STACK: unused 8 usage 504 / 512 (98 %); CPU: 0 %
 thread_a            : STACK: unused 648 usage 376 / 1024 (36 %); CPU: 98 %
 idle 00             : STACK: unused 204 usage 116 / 320 (36 %); CPU: 0 %
thread_b: Hello World from cpu 0 on qemu_x86!
thread_a: Hello World from cpu 0 on qemu_x86!
thread_b: Hello World from cpu 0 on qemu_x86!
thread_a: Hello World from cpu 0 on qemu_x86!
thread_b: Hello World from cpu 0 on qemu_x86!
thread_a: Hello World from cpu 0 on qemu_x86!
thread_b: Hello World from cpu 0 on qemu_x86!
thread_a: Hello World from cpu 0 on qemu_x86!
Thread analyze:
 thread_b            : STACK: unused 648 usage 376 / 1024 (36 %); CPU: 7 %
 thread_analyzer     : STACK: unused 8 usage 504 / 512 (98 %); CPU: 0 %
 thread_a            : STACK: unused 648 usage 376 / 1024 (36 %); CPU: 9 %
 idle 00             : STACK: unused 204 usage 116 / 320 (36 %); CPU: 82 %
thread_b: Hello World from cpu 0 on qemu_x86!

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-12-14 13:00:47 -05:00

69 lines
1.5 KiB
C

/*
* Copyright (c) 2019 - 2020 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __STACK_SIZE_ANALYZER_H
#define __STACK_SIZE_ANALYZER_H
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @defgroup thread_analyzer Thread analyzer
* @brief Module for analyzing threads
*
* This module implements functions and the configuration that simplifies
* thread analysis.
* @{
*/
struct thread_analyzer_info {
/** The name of the thread or stringified address of the thread handle
* if name is not set.
*/
const char *name;
/** The total size of the stack*/
size_t stack_size;
/** Stack size in used */
size_t stack_used;
#ifdef CONFIG_THREAD_RUNTIME_STATS
unsigned int utilization;
#endif
};
/** @brief Thread analyzer stack size callback function
*
* Callback function with thread analysis information.
*
* @param info Thread analysis information.
*/
typedef void (*thread_analyzer_cb)(struct thread_analyzer_info *info);
/** @brief Run the thread analyzer and provide information to the callback
*
* This function analyzes the current state for all threads and calls
* a given callback on every thread found.
*
* @param cb The callback function handler
*/
void thread_analyzer_run(thread_analyzer_cb cb);
/** @brief Run the thread analyzer and print stack size statistics.
*
* This function runs the thread analyzer and prints the output in standard
* form.
*/
void thread_analyzer_print(void);
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* __STACK_SIZE_ANALYZER_H */