score: Return heap stats via _Heap_Get_information

Print out heap statistics via the MALLOC and WKSPACE shell commands.
This commit is contained in:
Sebastian Huber
2014-11-27 13:25:22 +01:00
parent 01557b0c6e
commit 2c3c657625
8 changed files with 76 additions and 24 deletions

View File

@@ -98,6 +98,12 @@ static int open_files(void)
return (int) rtems_libio_number_iops - free_count;
}
static void get_heap_info(Heap_Control *heap, Heap_Information_block *info)
{
_Heap_Get_information(heap, info);
memset(&info->Stats, 0, sizeof(info->Stats));
}
void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot)
{
uint32_t *active = &snapshot->rtems_api.active_barriers;
@@ -107,13 +113,8 @@ void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot)
_Thread_Kill_zombies();
#ifdef HEAP_PROTECTION
_Heap_Protection_free_all_delayed_blocks(RTEMS_Malloc_Heap);
_Heap_Protection_free_all_delayed_blocks(&_Workspace_Area);
#endif
_Heap_Get_information(RTEMS_Malloc_Heap, &snapshot->heap_info);
_Heap_Get_information(&_Workspace_Area, &snapshot->workspace_info);
get_heap_info(RTEMS_Malloc_Heap, &snapshot->heap_info);
get_heap_info(&_Workspace_Area, &snapshot->workspace_info);
for (i = 0; i < RTEMS_ARRAY_SIZE(objects_info_table); ++i) {
active [i] = _Objects_Active_count(objects_info_table[i]);

View File

@@ -32,10 +32,13 @@ int rtems_shell_execute_cmd(const char *cmd, int argc, char *argv[]);
extern void rtems_shell_register_monitor_commands(void);
extern void rtems_shell_print_heap_info(
const char *c,
Heap_Information *h
const char *c,
const Heap_Information *h
);
extern void rtems_shell_print_heap_stats(
const Heap_Statistics *s
);
extern void rtems_shell_print_unified_work_area_message(void);

View File

@@ -37,6 +37,7 @@ static int rtems_shell_main_malloc_info(
malloc_info( &info );
rtems_shell_print_heap_info( "free", &info.Free );
rtems_shell_print_heap_info( "used", &info.Used );
rtems_shell_print_heap_stats( &info.Stats );
}
return 0;

View File

@@ -24,7 +24,7 @@
void rtems_shell_print_unified_work_area_message(void)
{
printf( "\nC Program Heap and RTEMS Workspace are %s.\n",
printf( "C Program Heap and RTEMS Workspace are %s.\n",
rtems_configuration_get_unified_work_area() ? "the same" : "separate"
);
}
@@ -41,6 +41,7 @@ static int rtems_shell_main_wkspace_info(
_Protected_heap_Get_information( &_Workspace_Area, &info );
rtems_shell_print_heap_info( "free", &info.Free );
rtems_shell_print_heap_info( "used", &info.Used );
rtems_shell_print_heap_stats( &info.Stats );
return 0;
}

View File

@@ -14,22 +14,47 @@
#endif
#include <inttypes.h>
#include <stdio.h>
#include <rtems.h>
#include <rtems/shell.h>
#include "internal.h"
void rtems_shell_print_heap_info(
const char *c,
Heap_Information *h
const char *c,
const Heap_Information *h
)
{
printf(
"Number of %s blocks: %" PRId32 "\n"
"Largest %s block: %" PRId32 "\n"
"Total bytes %s: %" PRId32 "\n",
"Number of %s blocks: %12" PRId32 "\n"
"Largest %s block: %12" PRId32 "\n"
"Total bytes %s: %12" PRId32 "\n",
c, h->number,
c, h->largest,
c, h->total
);
}
void rtems_shell_print_heap_stats(
const Heap_Statistics *s
)
{
printf(
"Instance number: %12" PRIu32 "\n"
"Size of the allocatable area in bytes: %12" PRIuPTR "\n"
"Minimum free size ever in bytes: %12" PRIuPTR "\n"
"Maximum number of free blocks ever: %12" PRIu32 "\n"
"Maximum number of blocks searched ever: %12" PRIu32 "\n"
"Total number of successful allocations: %12" PRIu32 "\n"
"Total number of searches ever: %12" PRIu32 "\n"
"Total number of successful calls to free: %12" PRIu32 "\n"
"Total number of successful resizes: %12" PRIu32 "\n",
s->instance,
s->size,
s->min_free_size,
s->max_free_blocks,
s->max_search,
s->allocs,
s->searches,
s->frees,
s->resizes
);
}

View File

@@ -313,7 +313,7 @@ typedef struct {
uint32_t searches;
/**
* @brief Total number of suceessful calls to free.
* @brief Total number of successful calls to free.
*/
uint32_t frees;
@@ -366,6 +366,7 @@ typedef struct {
typedef struct {
Heap_Information Free;
Heap_Information Used;
Heap_Statistics Stats;
} Heap_Information_block;
/**

View File

@@ -50,4 +50,5 @@ void _Heap_Get_information(
memset( the_info, 0, sizeof(*the_info) );
_Heap_Protection_free_all_delayed_blocks( the_heap );
_Heap_Iterate( the_heap, _Heap_Get_information_visitor, the_info );
the_info->Stats = the_heap->stats;
}

View File

@@ -546,6 +546,15 @@ to the command. This includes the following information:
@item Number of used blocks
@item Largest used block
@item Total bytes used
@item Instance number
@item Size of the allocatable area in bytes
@item Minimum free size ever in bytes
@item Maximum number of free blocks ever
@item Maximum number of blocks searched ever
@item Total number of successful allocations
@item Total number of searches ever
@item Total number of successful calls to free
@item Total number of successful resizes
@end itemize
When the subcommand @code{walk} is specified, then a heap walk will be
@@ -565,12 +574,22 @@ The following is an example of how to use the @code{malloc} command.
@example
SHLL [/] $ malloc
Number of free blocks: 3
Largest free block: 3626672
Total bytes free: 3627768
Number of used blocks: 130
Largest used block: 1048
Total bytes used: 10136
C Program Heap and RTEMS Workspace are the same.
Number of free blocks: 14
Largest free block: 266157192
Total bytes free: 266164928
Number of used blocks: 167
Largest used block: 16424
Total bytes used: 90888
Instance number: 0
Size of the allocatable area in bytes: 266255816
Minimum free size ever in bytes: 266156136
Maximum number of free blocks ever: 15
Maximum number of blocks searched ever: 15
Total number of successful allocations: 186
Total number of searches ever: 186
Total number of successful calls to free: 19
Total number of successful resizes: 0
SHLL [/] $ malloc walk
malloc walk
PASS[0]: page size 8, min block size 48