forked from Imagelibrary/rtems
libcsupport: Delete malloc statistics
Use the heap handler statistics instead. Add heap walk option to MALLOC shell command. close #1367
This commit is contained in:
@@ -98,10 +98,9 @@ MALLOC_C_FILES = src/malloc_initialize.c src/calloc.c src/malloc.c \
|
||||
src/realloc.c src/_calloc_r.c src/_malloc_r.c \
|
||||
src/free.c src/_free_r.c \
|
||||
src/_realloc_r.c src/mallocfreespace.c \
|
||||
src/mallocgetheapptr.c src/mallocsetheapptr.c \
|
||||
src/mallocinfo.c src/malloc_walk.c src/malloc_get_statistics.c \
|
||||
src/malloc_report_statistics.c src/malloc_report_statistics_plugin.c \
|
||||
src/malloc_statistics_helpers.c src/posix_memalign.c \
|
||||
src/mallocgetheapptr.c src/mallocsetheapptr.c \
|
||||
src/mallocinfo.c src/malloc_walk.c \
|
||||
src/posix_memalign.c \
|
||||
src/rtems_memalign.c src/malloc_deferred.c \
|
||||
src/malloc_dirtier.c src/malloc_p.h src/rtems_malloc.c \
|
||||
src/rtems_heap_extend_via_sbrk.c \
|
||||
|
||||
@@ -48,34 +48,6 @@ void RTEMS_Malloc_Initialize(
|
||||
Heap_Initialization_or_extend_handler extend
|
||||
);
|
||||
|
||||
/*
|
||||
* Malloc Statistics Structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t space_available; /* current size of malloc area */
|
||||
uint32_t malloc_calls; /* # calls to malloc */
|
||||
uint32_t memalign_calls; /* # calls to memalign */
|
||||
uint32_t free_calls;
|
||||
uint32_t realloc_calls;
|
||||
uint32_t calloc_calls;
|
||||
uint32_t max_depth; /* most ever malloc'd at 1 time */
|
||||
uintmax_t lifetime_allocated;
|
||||
uintmax_t lifetime_freed;
|
||||
} rtems_malloc_statistics_t;
|
||||
|
||||
/*
|
||||
* Malloc statistics plugin
|
||||
*/
|
||||
typedef struct {
|
||||
void (*initialize)(void);
|
||||
void (*at_malloc)(void *);
|
||||
void (*at_free)(void *);
|
||||
} rtems_malloc_statistics_functions_t;
|
||||
|
||||
extern rtems_malloc_statistics_functions_t
|
||||
rtems_malloc_statistics_helpers_table;
|
||||
extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers;
|
||||
|
||||
extern ptrdiff_t RTEMS_Malloc_Sbrk_amount;
|
||||
|
||||
static inline void rtems_heap_set_sbrk_amount( ptrdiff_t sbrk_amount )
|
||||
@@ -121,41 +93,6 @@ void rtems_malloc_dirty_memory(
|
||||
size_t size
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Print Malloc Statistic Usage Report
|
||||
*
|
||||
* This method fills in the called provided malloc statistics area.
|
||||
*
|
||||
* @return This method returns 0 if successful and -1 on error.
|
||||
*/
|
||||
int malloc_get_statistics(
|
||||
rtems_malloc_statistics_t *stats
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Print Malloc Statistic Usage Report
|
||||
*
|
||||
* This method prints a malloc statistics report.
|
||||
*
|
||||
* @note It uses printk to print the report.
|
||||
*/
|
||||
void malloc_report_statistics(void);
|
||||
|
||||
/**
|
||||
* @brief Print Malloc Statistic Usage Report
|
||||
*
|
||||
* This method prints a malloc statistics report.
|
||||
*
|
||||
* @param[in] context is the context to pass to the print handler
|
||||
* @param[in] print is the print handler
|
||||
*
|
||||
* @note It uses the CALLER's routine to print the report.
|
||||
*/
|
||||
void malloc_report_statistics_with_plugin(
|
||||
void *context,
|
||||
rtems_printk_plugin_t print
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief RTEMS Variation on Aligned Memory Allocation
|
||||
*
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#endif
|
||||
|
||||
#if defined(RTEMS_NEWLIB) && !defined(HAVE_CALLOC)
|
||||
#include "malloc_p.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -31,15 +30,11 @@ void *calloc(
|
||||
char *cptr;
|
||||
size_t length;
|
||||
|
||||
MSBUMP(calloc_calls, 1);
|
||||
|
||||
length = nelem * elsize;
|
||||
cptr = malloc( length );
|
||||
if ( cptr )
|
||||
memset( cptr, '\0', length );
|
||||
|
||||
MSBUMP(malloc_calls, (uint32_t) -1); /* subtract off the malloc */
|
||||
|
||||
return cptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
|
||||
#include <rtems/score/sysstate.h>
|
||||
|
||||
#include "malloc_p.h"
|
||||
|
||||
void free(
|
||||
void *ptr
|
||||
)
|
||||
{
|
||||
MSBUMP(free_calls, 1);
|
||||
|
||||
if ( !ptr )
|
||||
return;
|
||||
|
||||
@@ -41,12 +41,6 @@ void free(
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* If configured, update the statistics
|
||||
*/
|
||||
if ( rtems_malloc_statistics_helpers )
|
||||
(*rtems_malloc_statistics_helpers->at_free)(ptr);
|
||||
|
||||
if ( !_Protected_heap_Free( RTEMS_Malloc_Heap, ptr ) ) {
|
||||
printk( "Program heap: free of bad pointer %p -- range %p - %p \n",
|
||||
ptr,
|
||||
|
||||
@@ -30,8 +30,6 @@ void *malloc(
|
||||
{
|
||||
void *return_this;
|
||||
|
||||
MSBUMP(malloc_calls, 1);
|
||||
|
||||
/*
|
||||
* If some free's have been deferred, then do them now.
|
||||
*/
|
||||
@@ -71,12 +69,6 @@ void *malloc(
|
||||
if ( rtems_malloc_dirty_helper )
|
||||
(*rtems_malloc_dirty_helper)( return_this, size );
|
||||
|
||||
/*
|
||||
* If configured, update the statistics
|
||||
*/
|
||||
if ( rtems_malloc_statistics_helpers )
|
||||
(*rtems_malloc_statistics_helpers->at_malloc)(return_this);
|
||||
|
||||
return return_this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @brief Print Malloc Statistic Usage Report
|
||||
* @ingroup MallocSupport
|
||||
*/
|
||||
|
||||
/*
|
||||
* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef RTEMS_NEWLIB
|
||||
#include "malloc_p.h"
|
||||
|
||||
int malloc_get_statistics(
|
||||
rtems_malloc_statistics_t *stats
|
||||
)
|
||||
{
|
||||
if ( !stats )
|
||||
return -1;
|
||||
_RTEMS_Lock_allocator();
|
||||
*stats = rtems_malloc_statistics;
|
||||
_RTEMS_Unlock_allocator();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -22,8 +22,6 @@
|
||||
#include "malloc_p.h"
|
||||
|
||||
#ifdef RTEMS_NEWLIB
|
||||
rtems_malloc_statistics_t rtems_malloc_statistics;
|
||||
|
||||
void RTEMS_Malloc_Initialize(
|
||||
const Heap_Area *areas,
|
||||
size_t area_count,
|
||||
@@ -59,15 +57,6 @@ void RTEMS_Malloc_Initialize(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If configured, initialize the statistics support
|
||||
*/
|
||||
if ( rtems_malloc_statistics_helpers != NULL ) {
|
||||
(*rtems_malloc_statistics_helpers->initialize)();
|
||||
}
|
||||
|
||||
MSBUMP( space_available, _Protected_heap_Get_size( heap ) );
|
||||
}
|
||||
#else
|
||||
void RTEMS_Malloc_Initialize(
|
||||
|
||||
@@ -21,13 +21,6 @@
|
||||
#include <stdint.h>
|
||||
#include <rtems/chain.h>
|
||||
|
||||
/*
|
||||
* Malloc Statistics Structure
|
||||
*/
|
||||
extern rtems_malloc_statistics_t rtems_malloc_statistics;
|
||||
|
||||
#define MSBUMP(_f,_n) rtems_malloc_statistics._f += (_n)
|
||||
|
||||
/*
|
||||
* Process deferred free operations
|
||||
*/
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @brief Print Malloc Statistic Usage Report
|
||||
* @ingroup MallocSupport
|
||||
*/
|
||||
|
||||
/*
|
||||
* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef RTEMS_NEWLIB
|
||||
#include "malloc_p.h"
|
||||
|
||||
void malloc_report_statistics(void)
|
||||
{
|
||||
malloc_report_statistics_with_plugin( NULL, printk_plugin );
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* malloc_report_statistics with plugin Implementation
|
||||
*
|
||||
* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef RTEMS_NEWLIB
|
||||
#include "malloc_p.h"
|
||||
#include "inttypes.h"
|
||||
|
||||
void malloc_report_statistics_with_plugin(
|
||||
void *context,
|
||||
rtems_printk_plugin_t print
|
||||
)
|
||||
{
|
||||
rtems_malloc_statistics_t *s = &rtems_malloc_statistics;
|
||||
uint32_t space_available = s->space_available;
|
||||
uint32_t allocated = (uint32_t) (s->lifetime_allocated - s->lifetime_freed);
|
||||
uint32_t max_depth = s->max_depth;
|
||||
/* avoid float! */
|
||||
uint32_t allocated_per_cent = (allocated * 100) / space_available;
|
||||
uint32_t max_depth_per_cent = (max_depth * 100) / space_available;
|
||||
|
||||
(*print)(
|
||||
context,
|
||||
"Malloc statistics\n"
|
||||
" avail:%"PRIu32"k allocated:%"PRIu32"k (%"PRIu32"%%) "
|
||||
"max:%"PRIu32"k (%"PRIu32"%%)"
|
||||
" lifetime:%"PRIuMAX"k freed:%"PRIuMAX"k\n",
|
||||
space_available / 1024,
|
||||
allocated / 1024,
|
||||
allocated_per_cent,
|
||||
max_depth / 1024,
|
||||
max_depth_per_cent,
|
||||
s->lifetime_allocated / 1024,
|
||||
s->lifetime_freed / 1024
|
||||
);
|
||||
(*print)(
|
||||
context,
|
||||
" Call counts: malloc:%"PRIu32" memalign:%"PRIu32" free:%"PRIu32
|
||||
" realloc:%"PRIu32" calloc:%"PRIu32"\n",
|
||||
s->malloc_calls,
|
||||
s->memalign_calls,
|
||||
s->free_calls,
|
||||
s->realloc_calls,
|
||||
s->calloc_calls
|
||||
);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @brief Malloc Statistics Support
|
||||
* @ingroup MallocSupport
|
||||
*/
|
||||
|
||||
/*
|
||||
* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef RTEMS_NEWLIB
|
||||
#include "malloc_p.h"
|
||||
|
||||
#include <sys/reent.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void rtems_malloc_statistics_initialize( void )
|
||||
{
|
||||
/*
|
||||
* Zero all the statistics
|
||||
*/
|
||||
(void) memset(&rtems_malloc_statistics, 0, sizeof(rtems_malloc_statistics));
|
||||
}
|
||||
|
||||
static void rtems_malloc_statistics_at_malloc(
|
||||
void *pointer
|
||||
)
|
||||
{
|
||||
uintptr_t actual_size = 0;
|
||||
uint32_t current_depth;
|
||||
rtems_malloc_statistics_t *s = &rtems_malloc_statistics;
|
||||
|
||||
if ( !pointer )
|
||||
return;
|
||||
|
||||
_Protected_heap_Get_block_size(RTEMS_Malloc_Heap, pointer, &actual_size);
|
||||
|
||||
MSBUMP(lifetime_allocated, actual_size);
|
||||
|
||||
current_depth = (uint32_t) (s->lifetime_allocated - s->lifetime_freed);
|
||||
if (current_depth > s->max_depth)
|
||||
s->max_depth = current_depth;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the pointer is not in the heap, then we won't be able to get its
|
||||
* size and thus we skip updating the statistics.
|
||||
*/
|
||||
static void rtems_malloc_statistics_at_free(
|
||||
void *pointer
|
||||
)
|
||||
{
|
||||
uintptr_t size;
|
||||
|
||||
if (_Protected_heap_Get_block_size(RTEMS_Malloc_Heap, pointer, &size) ) {
|
||||
MSBUMP(lifetime_freed, size);
|
||||
}
|
||||
}
|
||||
|
||||
rtems_malloc_statistics_functions_t rtems_malloc_statistics_helpers_table = {
|
||||
rtems_malloc_statistics_initialize,
|
||||
rtems_malloc_statistics_at_malloc,
|
||||
rtems_malloc_statistics_at_free,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @brief Update call statistics
|
||||
* @ingroup libcsupport
|
||||
*/
|
||||
|
||||
@@ -30,11 +29,6 @@ int posix_memalign(
|
||||
size_t size
|
||||
)
|
||||
{
|
||||
/*
|
||||
* Update call statistics
|
||||
*/
|
||||
MSBUMP(memalign_calls, 1);
|
||||
|
||||
if (((alignment - 1) & alignment) != 0 || (alignment < sizeof(void *)))
|
||||
return EINVAL;
|
||||
|
||||
|
||||
@@ -35,8 +35,6 @@ void *realloc(
|
||||
uintptr_t old_size;
|
||||
char *new_area;
|
||||
|
||||
MSBUMP(realloc_calls, 1);
|
||||
|
||||
/*
|
||||
* Do not attempt to allocate memory if in a critical section or ISR.
|
||||
*/
|
||||
@@ -77,8 +75,6 @@ void *realloc(
|
||||
|
||||
new_area = malloc( size );
|
||||
|
||||
MSBUMP(malloc_calls, (uint32_t) -1); /* subtract off the malloc */
|
||||
|
||||
if ( !new_area ) {
|
||||
return (void *) 0;
|
||||
}
|
||||
|
||||
@@ -52,8 +52,6 @@ void *rtems_heap_extend_via_sbrk(
|
||||
bool ok = _Protected_heap_Extend( heap, area_begin, sbrk_size );
|
||||
|
||||
if ( ok ) {
|
||||
MSBUMP( space_available, sbrk_size );
|
||||
|
||||
return_this = _Protected_heap_Allocate( heap, alloc_size );
|
||||
} else {
|
||||
sbrk( -sbrk_size );
|
||||
|
||||
@@ -62,12 +62,6 @@ int rtems_memalign(
|
||||
if ( !return_this )
|
||||
return ENOMEM;
|
||||
|
||||
/*
|
||||
* If configured, update the more involved statistics
|
||||
*/
|
||||
if ( rtems_malloc_statistics_helpers )
|
||||
(*rtems_malloc_statistics_helpers->at_malloc)(pointer);
|
||||
|
||||
*pointer = return_this;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/malloc.h>
|
||||
#include <rtems/libcsupport.h>
|
||||
#include <rtems/shell.h>
|
||||
#include <rtems/shellconfig.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
@@ -28,31 +28,23 @@ static int rtems_shell_main_malloc_info(
|
||||
char *argv[]
|
||||
)
|
||||
{
|
||||
if ( argc == 2 ) {
|
||||
if ( argc == 2 && strcmp( argv[ 1 ], "walk" ) == 0 ) {
|
||||
malloc_walk( 0, true );
|
||||
} else {
|
||||
region_information_block info;
|
||||
|
||||
rtems_shell_print_unified_work_area_message();
|
||||
|
||||
if ( !strcmp( argv[1], "info" ) ) {
|
||||
region_information_block info;
|
||||
|
||||
malloc_info( &info );
|
||||
rtems_shell_print_heap_info( "free", &info.Free );
|
||||
rtems_shell_print_heap_info( "used", &info.Used );
|
||||
return 0;
|
||||
} else if ( !strcmp( argv[1], "stats" ) ) {
|
||||
malloc_report_statistics_with_plugin(
|
||||
stdout,
|
||||
(rtems_printk_plugin_t) fprintf
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
malloc_info( &info );
|
||||
rtems_shell_print_heap_info( "free", &info.Free );
|
||||
rtems_shell_print_heap_info( "used", &info.Used );
|
||||
}
|
||||
fprintf( stderr, "%s: [info|stats]\n", argv[0] );
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
rtems_shell_cmd_t rtems_shell_MALLOC_INFO_Command = {
|
||||
"malloc", /* name */
|
||||
"[info|stats]", /* usage */
|
||||
"malloc [walk]", /* usage */
|
||||
"mem", /* topic */
|
||||
rtems_shell_main_malloc_info, /* command */
|
||||
NULL, /* alias */
|
||||
|
||||
@@ -1113,19 +1113,6 @@ const rtems_libio_helper rtems_fs_init_helper =
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIGURE_INIT
|
||||
/**
|
||||
* This configures the malloc family statistics to be available.
|
||||
* By default only function call counts are kept.
|
||||
*/
|
||||
rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers =
|
||||
#ifndef CONFIGURE_MALLOC_STATISTICS
|
||||
NULL;
|
||||
#else
|
||||
&rtems_malloc_statistics_helpers_table;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIGURE_INIT
|
||||
/**
|
||||
* This configures the sbrk() support for the malloc family.
|
||||
|
||||
@@ -530,18 +530,14 @@ extern rtems_shell_cmd_t rtems_shell_MMOVE_Command;
|
||||
@subheading SYNOPSYS:
|
||||
|
||||
@example
|
||||
malloc [info|stats]
|
||||
malloc [walk]
|
||||
@end example
|
||||
|
||||
@subheading DESCRIPTION:
|
||||
|
||||
This command prints either information or statistics about the
|
||||
C Program Heap used by the @code{malloc} family of calls based upon
|
||||
the value of the first argument passed to the command.
|
||||
|
||||
When the subcommand @code{info} is specified, information on the
|
||||
current state of the C Program Heap is reported. This includes the following
|
||||
information:
|
||||
This command prints information about the current state of the C Program Heap
|
||||
used by the @code{malloc()} family of calls if no or invalid options are passed
|
||||
to the command. This includes the following information:
|
||||
|
||||
@itemize @bullet
|
||||
@item Number of free blocks
|
||||
@@ -552,23 +548,8 @@ information:
|
||||
@item Total bytes used
|
||||
@end itemize
|
||||
|
||||
When the subcommand @code{stats} is specified, statistics on the
|
||||
the C Program Heap are reported. Malloc Family Statistics must
|
||||
be enabled for all of the values to be updated. The statistics
|
||||
available includes the following information:
|
||||
|
||||
@itemize @bullet
|
||||
@item
|
||||
@item Currently available memory (in kilobytes)
|
||||
@item Currently allocated memory (in kilobytes)
|
||||
@item Maximum amount of memory ever allocated (in kilobytes)
|
||||
@item Lifetime tally of allocated memory (in kilobytes)
|
||||
@item Lifetime tally of freed memory (in kilobytes)
|
||||
@item Number of calls to @code{malloc}
|
||||
@item Number of calls to @code{free}
|
||||
@item Number of calls to @code{realloc}
|
||||
@item Number of calls to @code{calloc}
|
||||
@end itemize
|
||||
When the subcommand @code{walk} is specified, then a heap walk will be
|
||||
performed and information about each block is printed out.
|
||||
|
||||
@subheading EXIT STATUS:
|
||||
|
||||
@@ -576,47 +557,41 @@ This command returns 0 on success and non-zero if an error is encountered.
|
||||
|
||||
@subheading NOTES:
|
||||
|
||||
@findex CONFIGURE_MALLOC_STATISTICS
|
||||
|
||||
The @code{CONFIGURE_MALLOC_STATISTICS} @code{confdefs.h} constant
|
||||
must be defined when the application is configured for the full
|
||||
set of statistics information to be available.
|
||||
NONE
|
||||
|
||||
@subheading EXAMPLES:
|
||||
|
||||
The following is an example of how to use the @code{malloc} command.
|
||||
|
||||
@example
|
||||
SHLL [/] $ malloc info
|
||||
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
|
||||
SHLL [/] $ malloc stats
|
||||
Malloc statistics
|
||||
avail:3552k allocated:9k (0%) max:10k (0%) lifetime:21k freed:12k
|
||||
Call counts: malloc:203 free:93 realloc:0 calloc:20
|
||||
SHLL [/] $ malloc info
|
||||
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
|
||||
SHLL [/] $ malloc stats
|
||||
Malloc statistics
|
||||
avail:3552k allocated:9k (0%) max:10k (0%) lifetime:23k freed:14k
|
||||
Call counts: malloc:205 free:95 realloc:0 calloc:20
|
||||
SHLL [/] $ malloc walk
|
||||
malloc walk
|
||||
PASS[0]: page size 8, min block size 48
|
||||
area begin 0x00210210, area end 0x0FFFC000
|
||||
first block 0x00210214, last block 0x0FFFBFDC
|
||||
first free 0x00228084, last free 0x00228354
|
||||
PASS[0]: block 0x00210214: size 88
|
||||
...
|
||||
PASS[0]: block 0x00220154: size 144
|
||||
PASS[0]: block 0x002201E4: size 168, prev 0x002205BC, next 0x00228354 (= last free)
|
||||
PASS[0]: block 0x0022028C: size 168, prev_size 168
|
||||
...
|
||||
PASS[0]: block 0x00226E7C: size 4136
|
||||
PASS[0]: block 0x00227EA4: size 408, prev 0x00228084 (= first free), next 0x00226CE4
|
||||
PASS[0]: block 0x0022803C: size 72, prev_size 408
|
||||
PASS[0]: block 0x00228084: size 648, prev 0x0020F75C (= head), next 0x00227EA4
|
||||
PASS[0]: block 0x0022830C: size 72, prev_size 648
|
||||
PASS[0]: block 0x00228354: size 266157192, prev 0x002201E4, next 0x0020F75C (= tail)
|
||||
PASS[0]: block 0x0FFFBFDC: size 4028711480, prev_size 266157192
|
||||
@end example
|
||||
|
||||
Note that in the above example, the lifetime allocated and free
|
||||
values have increased between the two calls to @code{malloc stats}
|
||||
even though the amount of memory available in the C Program Heap
|
||||
is the same in both the @code{malloc info} invocations. This indicates
|
||||
that memory was allocated and freed as a side-effect of the commands.
|
||||
|
||||
@subheading CONFIGURATION:
|
||||
|
||||
@findex CONFIGURE_SHELL_NO_COMMAND_MALLOC
|
||||
|
||||
@@ -2433,37 +2433,6 @@ This section defines the file system and IO library
|
||||
related configuration parameters supported by
|
||||
@code{<rtems/confdefs.h>}.
|
||||
|
||||
@c
|
||||
@c === CONFIGURE_MALLOC_STATISTICS ===
|
||||
@c
|
||||
@subsection Enable Malloc Family Statistics
|
||||
|
||||
@findex CONFIGURE_MALLOC_STATISTICS
|
||||
|
||||
|
||||
@table @b
|
||||
@item CONSTANT:
|
||||
@code{CONFIGURE_MALLOC_STATISTICS}
|
||||
|
||||
@item DATA TYPE:
|
||||
Boolean feature macro.
|
||||
|
||||
@item RANGE:
|
||||
Defined or undefined.
|
||||
|
||||
@item DEFAULT VALUE:
|
||||
This is not defined by default, and Malloc Statistics are disabled.
|
||||
|
||||
@end table
|
||||
|
||||
@subheading DESCRIPTION:
|
||||
This configuration parameter is defined when the application wishes to
|
||||
enable the gathering of more detailed statistics on the C Malloc Family
|
||||
of routines.
|
||||
|
||||
@subheading NOTES:
|
||||
None.
|
||||
|
||||
@c
|
||||
@c === CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS ===
|
||||
@c
|
||||
|
||||
@@ -24,7 +24,7 @@ _SUBDIRS += capture01
|
||||
|
||||
_SUBDIRS += bspcmdline01 cpuuse devfs01 devfs02 devfs03 devfs04 \
|
||||
deviceio01 devnullfatal01 dumpbuf01 gxx01 top\
|
||||
malloctest malloc02 malloc03 malloc04 malloc05 heapwalk \
|
||||
malloctest malloc02 malloc03 malloc04 heapwalk \
|
||||
putenvtest monitor monitor02 rtmonuse stackchk stackchk01 \
|
||||
termios termios01 termios02 termios03 termios04 termios05 \
|
||||
termios06 termios07 termios08 \
|
||||
|
||||
@@ -117,7 +117,6 @@ malloctest/Makefile
|
||||
malloc02/Makefile
|
||||
malloc03/Makefile
|
||||
malloc04/Makefile
|
||||
malloc05/Makefile
|
||||
monitor/Makefile
|
||||
monitor02/Makefile
|
||||
mouse01/Makefile
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
|
||||
rtems_tests_PROGRAMS = malloc05
|
||||
malloc05_SOURCES = init.c
|
||||
|
||||
dist_rtems_tests_DATA = malloc05.scn
|
||||
dist_rtems_tests_DATA += malloc05.doc
|
||||
|
||||
include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
|
||||
include $(top_srcdir)/../automake/compile.am
|
||||
include $(top_srcdir)/../automake/leaf.am
|
||||
|
||||
AM_CPPFLAGS += -I$(top_srcdir)/../support/include
|
||||
|
||||
LINK_OBJS = $(malloc05_OBJECTS)
|
||||
LINK_LIBS = $(malloc05_LDLIBS)
|
||||
|
||||
malloc05$(EXEEXT): $(malloc05_OBJECTS) $(malloc05_DEPENDENCIES)
|
||||
@rm -f malloc05$(EXEEXT)
|
||||
$(make-exe)
|
||||
|
||||
include $(top_srcdir)/../automake/local.am
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 1989-2012.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <tmacros.h>
|
||||
#include "test_support.h"
|
||||
#include <rtems/malloc.h>
|
||||
|
||||
const char rtems_test_name[] = "MALLOC 5";
|
||||
|
||||
/* forward declarations to avoid warnings */
|
||||
rtems_task Init(rtems_task_argument argument);
|
||||
|
||||
rtems_task Init(
|
||||
rtems_task_argument argument
|
||||
)
|
||||
{
|
||||
int sc;
|
||||
rtems_malloc_statistics_t stats;
|
||||
|
||||
TEST_BEGIN();
|
||||
|
||||
puts( "malloc_get_statistics( NULL ) - returns -1" );
|
||||
sc = malloc_get_statistics( NULL );
|
||||
rtems_test_assert( sc == -1 );
|
||||
|
||||
puts( "malloc_get_statistics( &stats ) - returns -0" );
|
||||
sc = malloc_get_statistics( &stats );
|
||||
rtems_test_assert( sc == 0 );
|
||||
|
||||
TEST_END();
|
||||
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
/* configuration information */
|
||||
|
||||
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
|
||||
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
|
||||
|
||||
#define CONFIGURE_MAXIMUM_TASKS 1
|
||||
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
|
||||
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
|
||||
#include <rtems/confdefs.h>
|
||||
/* end of file */
|
||||
@@ -1,19 +0,0 @@
|
||||
# COPYRIGHT (c) 1989-2010.
|
||||
# On-Line Applications Research Corporation (OAR).
|
||||
#
|
||||
# The license and distribution terms for this file may be
|
||||
# found in the file LICENSE in this distribution or at
|
||||
# http://www.rtems.org/license/LICENSE.
|
||||
#
|
||||
|
||||
This file describes the directives and concepts tested by this test set.
|
||||
|
||||
test set name: malloc05
|
||||
|
||||
directives:
|
||||
|
||||
malloc_get_statistics
|
||||
|
||||
concepts:
|
||||
|
||||
+ Fully exercise malloc_get_statistics.
|
||||
@@ -1,4 +0,0 @@
|
||||
*** TEST MALLOC05 ***
|
||||
malloc_get_statistics( NULL ) - returns -1
|
||||
malloc_get_statistics( &stats ) - returns -0
|
||||
*** END OF TEST MALLOC05 ***
|
||||
@@ -59,7 +59,6 @@ rtems_task Task_1_through_5(
|
||||
}
|
||||
printf("mallocing %d bytes\n",mem_amt);
|
||||
memset( mem_ptr, mem_amt, mem_amt );
|
||||
malloc_report_statistics();
|
||||
malloc_walk_ok = malloc_walk( 1, false );
|
||||
rtems_test_assert( malloc_walk_ok );
|
||||
status = rtems_task_wake_after(
|
||||
|
||||
Reference in New Issue
Block a user