Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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 <logging/log.h>
16#include <stdbool.h>
17
18static inline void log_stack_usage(const struct k_thread *thread)
19{
20#if defined(CONFIG_INIT_STACKS) && defined(CONFIG_THREAD_STACK_INFO)
21 size_t unused, size = thread->stack_info.size;
22
23 LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
24
25 if (k_thread_stack_space_get(thread, &unused) == 0) {
26 unsigned int pcnt = ((size - unused) * 100U) / size;
27 const char *tname;
28
30 if (tname == NULL) {
31 tname = "unknown";
32 }
33
34 LOG_INF("%p (%s):\tunused %zu\tusage %zu / %zu (%u %%)",
35 thread, log_strdup(tname), unused, size - unused, size,
36 pcnt);
37 }
38#endif
39}
40#endif /* ZEPHYR_INCLUDE_DEBUG_STACK_H_ */
static struct k_thread thread[2]
Definition: atomic.c:22
static char * log_strdup(const char *str)
Definition: log.h:290
#define LOG_MODULE_DECLARE(...)
Macro for declaring a log module (not registering it).
Definition: log.h:410
#define LOG_INF(...)
Writes an INFO level message to the log.
Definition: log.h:61
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:18
Definition: thread.h:201
struct _thread_stack_info stack_info
Definition: thread.h:256