1 /*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 * Copyright (c) 2016 Intel Corporation
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8 #if K_HEAP_MEM_POOL_SIZE > 0
9 #include "kernel_shell.h"
10
11 extern struct k_heap _system_heap;
12
cmd_kernel_heap(const struct shell * sh,size_t argc,char ** argv)13 static int cmd_kernel_heap(const struct shell *sh, size_t argc, char **argv)
14 {
15 ARG_UNUSED(argc);
16 ARG_UNUSED(argv);
17
18 int err;
19 struct sys_memory_stats stats;
20
21 err = sys_heap_runtime_stats_get(&_system_heap.heap, &stats);
22 if (err) {
23 shell_error(sh, "Failed to read kernel system heap statistics (err %d)", err);
24 return -ENOEXEC;
25 }
26
27 shell_print(sh, "free: %zu", stats.free_bytes);
28 shell_print(sh, "allocated: %zu", stats.allocated_bytes);
29 shell_print(sh, "max. allocated: %zu", stats.max_allocated_bytes);
30
31 return 0;
32 }
33
34 KERNEL_CMD_ADD(heap, NULL, "System heap usage statistics.", cmd_kernel_heap);
35
36 #endif /* K_HEAP_MEM_POOL_SIZE > 0 */
37