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 <anas.nashif@intel.com>
This commit is contained in:
parent
d4c881da04
commit
246ec224e2
|
@ -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)
|
||||
|
|
34
lib/heap/heap_stats.c
Normal file
34
lib/heap/heap_stats.c
Normal file
|
@ -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;
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue