2019-06-26 22:42:45 +08:00
|
|
|
/**
|
2019-06-27 18:58:58 +08:00
|
|
|
* @file debug/stack.h
|
2019-06-26 22:42:45 +08:00
|
|
|
* Stack usage analysis helpers
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZEPHYR_INCLUDE_DEBUG_STACK_H_
|
|
|
|
#define ZEPHYR_INCLUDE_DEBUG_STACK_H_
|
|
|
|
|
|
|
|
#include <logging/log.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2020-02-06 02:41:58 +08:00
|
|
|
static inline void log_stack_usage(const struct k_thread *thread)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_INIT_STACKS) && defined(CONFIG_THREAD_STACK_INFO)
|
|
|
|
size_t unused, size = thread->stack_info.size;
|
|
|
|
|
|
|
|
LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
|
|
|
|
|
|
|
|
if (k_thread_stack_space_get(thread, &unused) == 0) {
|
|
|
|
unsigned int pcnt = ((size - unused) * 100U) / size;
|
|
|
|
const char *tname;
|
|
|
|
|
|
|
|
tname = k_thread_name_get((k_tid_t)thread);
|
|
|
|
if (tname == NULL) {
|
|
|
|
tname = "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_INF("%p (%s):\tunused %zu\tusage %zu / %zu (%u %%)",
|
2020-02-11 14:54:16 +08:00
|
|
|
thread, log_strdup(tname), unused, size - unused, size,
|
2020-02-06 02:41:58 +08:00
|
|
|
pcnt);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2019-06-26 22:42:45 +08:00
|
|
|
#endif /* ZEPHYR_INCLUDE_DEBUG_STACK_H_ */
|