[PATCH 2/2] score: Return heap stats via _Heap_Get_information

Gedare Bloom gedare at rtems.org
Thu Nov 27 15:38:52 UTC 2014


OK. A general comment it it would be nice to unify RTEMS various
"statistics" into a common format for easier printing and transferring
off-board.

-gedare

On Thu, Nov 27, 2014 at 7:26 AM, Sebastian Huber
<sebastian.huber at embedded-brains.de> wrote:
> Print out heap statistics via the MALLOC and WKSPACE shell commands.
> ---
>  cpukit/libmisc/shell/internal.h         |  7 ++++--
>  cpukit/libmisc/shell/main_mallocinfo.c  |  1 +
>  cpukit/libmisc/shell/main_wkspaceinfo.c |  3 ++-
>  cpukit/libmisc/shell/print_heapinfo.c   | 39 +++++++++++++++++++++++++++------
>  cpukit/score/include/rtems/score/heap.h |  3 ++-
>  cpukit/score/src/heapgetinfo.c          |  1 +
>  doc/shell/memory.t                      | 31 +++++++++++++++++++++-----
>  7 files changed, 68 insertions(+), 17 deletions(-)
>
> diff --git a/cpukit/libmisc/shell/internal.h b/cpukit/libmisc/shell/internal.h
> index 0187e5f..8ec2da0 100644
> --- a/cpukit/libmisc/shell/internal.h
> +++ b/cpukit/libmisc/shell/internal.h
> @@ -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);
>
> diff --git a/cpukit/libmisc/shell/main_mallocinfo.c b/cpukit/libmisc/shell/main_mallocinfo.c
> index 54c602a..43e9883 100644
> --- a/cpukit/libmisc/shell/main_mallocinfo.c
> +++ b/cpukit/libmisc/shell/main_mallocinfo.c
> @@ -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;
> diff --git a/cpukit/libmisc/shell/main_wkspaceinfo.c b/cpukit/libmisc/shell/main_wkspaceinfo.c
> index f4f6f4d..a990652 100644
> --- a/cpukit/libmisc/shell/main_wkspaceinfo.c
> +++ b/cpukit/libmisc/shell/main_wkspaceinfo.c
> @@ -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;
>  }
> diff --git a/cpukit/libmisc/shell/print_heapinfo.c b/cpukit/libmisc/shell/print_heapinfo.c
> index 12bc363..4ac9c96 100644
> --- a/cpukit/libmisc/shell/print_heapinfo.c
> +++ b/cpukit/libmisc/shell/print_heapinfo.c
> @@ -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
> +  );
> +}
> diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h
> index 0120a2b..6042a13 100644
> --- a/cpukit/score/include/rtems/score/heap.h
> +++ b/cpukit/score/include/rtems/score/heap.h
> @@ -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;
>
>  /**
> diff --git a/cpukit/score/src/heapgetinfo.c b/cpukit/score/src/heapgetinfo.c
> index 8565be4..287d269 100644
> --- a/cpukit/score/src/heapgetinfo.c
> +++ b/cpukit/score/src/heapgetinfo.c
> @@ -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;
>  }
> diff --git a/doc/shell/memory.t b/doc/shell/memory.t
> index 0fdf1f8..e8363ae 100644
> --- a/doc/shell/memory.t
> +++ b/doc/shell/memory.t
> @@ -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
> + at item Instance number
> + at item Size of the allocatable area in bytes
> + at item Minimum free size ever in bytes
> + at item Maximum number of free blocks ever
> + at item Maximum number of blocks searched ever
> + at item Total number of successful allocations
> + at item Total number of searches ever
> + at item Total number of successful calls to free
> + at 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
> --
> 1.8.4.5
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel



More information about the devel mailing list