From 246ec224e2866721cc4ac6f807ac0768701c9c2d Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Fri, 24 Nov 2023 07:40:06 -0500 Subject: [PATCH] lib: heap: move heap stats to own file heap stats are split out from heap_validate.c into own file. Signed-off-by: Anas Nashif --- lib/heap/CMakeLists.txt | 1 + lib/heap/heap_stats.c | 34 ++++++++++++++++++++++++++++++++++ lib/heap/heap_validate.c | 29 ----------------------------- 3 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 lib/heap/heap_stats.c diff --git a/lib/heap/CMakeLists.txt b/lib/heap/CMakeLists.txt index 06508170b2..f3853fc5b7 100644 --- a/lib/heap/CMakeLists.txt +++ b/lib/heap/CMakeLists.txt @@ -4,6 +4,7 @@ zephyr_sources( heap.c ) +zephyr_sources_ifdef(CONFIG_SYS_HEAP_RUNTIME_STATS heap_stats.c) zephyr_sources_ifdef(CONFIG_SYS_HEAP_INFO heap_info.c) zephyr_sources_ifdef(CONFIG_SYS_HEAP_VALIDATE heap_validate.c) zephyr_sources_ifdef(CONFIG_SYS_HEAP_STRESS heap_stress.c) diff --git a/lib/heap/heap_stats.c b/lib/heap/heap_stats.c new file mode 100644 index 0000000000..e9c28b96d2 --- /dev/null +++ b/lib/heap/heap_stats.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019,2023 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include +#include "heap.h" + +int sys_heap_runtime_stats_get(struct sys_heap *heap, + struct sys_memory_stats *stats) +{ + if ((heap == NULL) || (stats == NULL)) { + return -EINVAL; + } + + stats->free_bytes = heap->heap->free_bytes; + stats->allocated_bytes = heap->heap->allocated_bytes; + stats->max_allocated_bytes = heap->heap->max_allocated_bytes; + + return 0; +} + +int sys_heap_runtime_stats_reset_max(struct sys_heap *heap) +{ + if (heap == NULL) { + return -EINVAL; + } + + heap->heap->max_allocated_bytes = heap->heap->allocated_bytes; + + return 0; +} diff --git a/lib/heap/heap_validate.c b/lib/heap/heap_validate.c index 3d52a0d15c..af63c8cdd8 100644 --- a/lib/heap/heap_validate.c +++ b/lib/heap/heap_validate.c @@ -184,32 +184,3 @@ bool sys_heap_validate(struct sys_heap *heap) } return true; } - -#ifdef CONFIG_SYS_HEAP_RUNTIME_STATS - -int sys_heap_runtime_stats_get(struct sys_heap *heap, - struct sys_memory_stats *stats) -{ - if ((heap == NULL) || (stats == NULL)) { - return -EINVAL; - } - - stats->free_bytes = heap->heap->free_bytes; - stats->allocated_bytes = heap->heap->allocated_bytes; - stats->max_allocated_bytes = heap->heap->max_allocated_bytes; - - return 0; -} - -int sys_heap_runtime_stats_reset_max(struct sys_heap *heap) -{ - if (heap == NULL) { - return -EINVAL; - } - - heap->heap->max_allocated_bytes = heap->heap->allocated_bytes; - - return 0; -} - -#endif