zephyr/subsys/shell/modules/kernel_service/heap.c
Yong Cong Sin 83212147b2 shell: kernel_service: reorg the commands
Split the `kernel_service.c` into multiple subcommand files,
each file would register with the main `kernel` cmd based on
the dependencies in Kconfig/CMakeLists.txt.

This greatly reduces the number of precompiler directives.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-09-17 20:12:33 -04:00

37 lines
896 B
C

/*
* Copyright (c) 2018 Nordic Semiconductor ASA
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#if K_HEAP_MEM_POOL_SIZE > 0
#include <zephyr/sys/sys_heap.h>
extern struct sys_heap _system_heap;
static int cmd_kernel_heap(const struct shell *sh, size_t argc, char **argv)
{
ARG_UNUSED(argc);
ARG_UNUSED(argv);
int err;
struct sys_memory_stats stats;
err = sys_heap_runtime_stats_get(&_system_heap, &stats);
if (err) {
shell_error(sh, "Failed to read kernel system heap statistics (err %d)", err);
return -ENOEXEC;
}
shell_print(sh, "free: %zu", stats.free_bytes);
shell_print(sh, "allocated: %zu", stats.allocated_bytes);
shell_print(sh, "max. allocated: %zu", stats.max_allocated_bytes);
return 0;
}
KERNEL_CMD_ADD(heap, NULL, "System heap usage statistics.", cmd_kernel_heap);
#endif /* K_HEAP_MEM_POOL_SIZE > 0 */