Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
stack.h
Go to the documentation of this file.
1
5
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/kernel.h>
17#include <zephyr/toolchain.h>
18#include <stdbool.h>
19
20static inline void log_stack_usage(const struct k_thread *thread)
21{
22#if defined(CONFIG_INIT_STACKS) && defined(CONFIG_THREAD_STACK_INFO)
23 size_t unused, size = thread->stack_info.size;
24
26 LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
28
29 if (k_thread_stack_space_get(thread, &unused) == 0) {
30 unsigned int pcnt = ((size - unused) * 100U) / size;
31 const char *tname;
32
33 tname = k_thread_name_get((k_tid_t)thread);
34 if (tname == NULL) {
35 tname = "unknown";
36 }
37
38 LOG_INF("%p (%s):\tunused %zu\tusage %zu / %zu (%u %%)",
39 thread, tname, unused, size - unused, size,
40 pcnt);
41 }
42#else
43 ARG_UNUSED(thread);
44#endif
45}
46#endif /* ZEPHYR_INCLUDE_DEBUG_STACK_H_ */
#define LOG_MODULE_DECLARE(...)
Macro for declaring a log module (not registering it).
Definition log.h:806
#define LOG_INF(...)
Writes an INFO level message to the log.
Definition log.h:83
const char * k_thread_name_get(k_tid_t thread)
Get thread name.
#define NULL
Definition iar_missing_defs.h:20
struct k_thread * k_tid_t
Definition thread.h:379
Public kernel APIs.
static void log_stack_usage(const struct k_thread *thread)
Definition stack.h:20
Thread Structure.
Definition thread.h:263
struct _thread_stack_info stack_info
Stack Info.
Definition thread.h:321
Macros to abstract toolchain specific capabilities.
#define TOOLCHAIN_DISABLE_WARNING(warning)
Disable the specified compiler warning for all compilers.
Definition toolchain.h:276
#define TOOLCHAIN_ENABLE_WARNING(warning)
Re-enable the specified compiler warning for all compilers.
Definition toolchain.h:286
#define TOOLCHAIN_WARNING_SHADOW
Toolchain-specific warning for shadow variables.
Definition toolchain.h:224