Skip to content

Commit

Permalink
lib: heap: move heap stats to own file
Browse files Browse the repository at this point in the history
heap stats are split out from heap_validate.c into own file.

Signed-off-by: Anas Nashif <[email protected]>
  • Loading branch information
nashif committed Dec 13, 2023
1 parent d4c881d commit 246ec22
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
1 change: 1 addition & 0 deletions lib/heap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions lib/heap/heap_stats.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2019,2023 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/sys/sys_heap.h>
#include <zephyr/sys/util.h>
#include <zephyr/kernel.h>
#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;
}
29 changes: 0 additions & 29 deletions lib/heap/heap_validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 246ec22

Please sign in to comment.