Zephyr API 3.6.99
Loading...
Searching...
No Matches
stack.h
Go to the documentation of this file.
1
6/*
7 * Copyright (c) 2015 Intel Corporation
8 *
9 * SPDX-License-Identifier: Apache-2.0
10 */
11
12#ifndef ZEPHYR_INCLUDE_DEBUG_STACK_H_
13#define ZEPHYR_INCLUDE_DEBUG_STACK_H_
14
15#include <zephyr/logging/log.h>
16#include <zephyr/toolchain.h>
17#include <stdbool.h>
18
19static inline void log_stack_usage(const struct k_thread *thread)
20{
21#if defined(CONFIG_INIT_STACKS) && defined(CONFIG_THREAD_STACK_INFO)
22 size_t unused, size = thread->stack_info.size;
23
25 LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
27
28 if (k_thread_stack_space_get(thread, &unused) == 0) {
29 unsigned int pcnt = ((size - unused) * 100U) / size;
30 const char *tname;
31
32 tname = k_thread_name_get((k_tid_t)thread);
33 if (tname == NULL) {
34 tname = "unknown";
35 }
36
37 LOG_INF("%p (%s):\tunused %zu\tusage %zu / %zu (%u %%)",
38 thread, tname, unused, size - unused, size,
39 pcnt);
40 }
41#else
42 ARG_UNUSED(thread);
43#endif
44}
45#endif /* ZEPHYR_INCLUDE_DEBUG_STACK_H_ */
#define LOG_MODULE_DECLARE(...)
Macro for declaring a log module (not registering it).
Definition log.h:424
#define LOG_INF(...)
Writes an INFO level message to the log.
Definition log.h:65
const char * k_thread_name_get(k_tid_t thread)
Get thread name.
static void log_stack_usage(const struct k_thread *thread)
Definition stack.h:19
Thread Structure.
Definition thread.h:259
struct _thread_stack_info stack_info
Stack Info.
Definition thread.h:317
Macros to abstract toolchain specific capabilities.
#define TOOLCHAIN_IGNORE_WSHADOW_END
End of block to ignore -Wshadow.
Definition toolchain.h:145
#define TOOLCHAIN_IGNORE_WSHADOW_BEGIN
Begin of block to ignore -Wshadow.
Definition toolchain.h:134