Changeset 01557b0 in rtems


Ignore:
Timestamp:
Nov 27, 2014, 10:44:48 AM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
2c3c657
Parents:
3b4ca3a
git-author:
Sebastian Huber <sebastian.huber@…> (11/27/14 10:44:48)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/28/14 10:23:53)
Message:

libcsupport: Delete malloc statistics

Use the heap handler statistics instead. Add heap walk option to MALLOC
shell command.

close #1367

Files:
8 deleted
18 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/Makefile.am

    r3b4ca3a r01557b0  
    9999    src/free.c src/_free_r.c \
    100100    src/_realloc_r.c src/mallocfreespace.c \
    101    src/mallocgetheapptr.c src/mallocsetheapptr.c \
    102     src/mallocinfo.c src/malloc_walk.c src/malloc_get_statistics.c \
    103     src/malloc_report_statistics.c src/malloc_report_statistics_plugin.c \
    104     src/malloc_statistics_helpers.c src/posix_memalign.c \
     101    src/mallocgetheapptr.c src/mallocsetheapptr.c \
     102    src/mallocinfo.c src/malloc_walk.c \
     103    src/posix_memalign.c \
    105104    src/rtems_memalign.c src/malloc_deferred.c \
    106105    src/malloc_dirtier.c src/malloc_p.h src/rtems_malloc.c \
  • cpukit/libcsupport/include/rtems/malloc.h

    r3b4ca3a r01557b0  
    4949);
    5050
    51 /*
    52  *  Malloc Statistics Structure
    53  */
    54 typedef struct {
    55     uint32_t    space_available;             /* current size of malloc area */
    56     uint32_t    malloc_calls;                /* # calls to malloc */
    57     uint32_t    memalign_calls;              /* # calls to memalign */
    58     uint32_t    free_calls;
    59     uint32_t    realloc_calls;
    60     uint32_t    calloc_calls;
    61     uint32_t    max_depth;                   /* most ever malloc'd at 1 time */
    62     uintmax_t   lifetime_allocated;
    63     uintmax_t   lifetime_freed;
    64 } rtems_malloc_statistics_t;
    65 
    66 /*
    67  *  Malloc statistics plugin
    68  */
    69 typedef struct {
    70   void (*initialize)(void);
    71   void (*at_malloc)(void *);
    72   void (*at_free)(void *);
    73 } rtems_malloc_statistics_functions_t;
    74 
    75 extern rtems_malloc_statistics_functions_t
    76   rtems_malloc_statistics_helpers_table;
    77 extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers;
    78 
    7951extern ptrdiff_t RTEMS_Malloc_Sbrk_amount;
    8052
     
    12092  void   *start,
    12193  size_t  size
    122 );
    123 
    124 /**
    125  *  @brief Print Malloc Statistic Usage Report
    126  *
    127  *  This method fills in the called provided malloc statistics area.
    128  *
    129  *  @return This method returns 0 if successful and -1 on error.
    130  */
    131 int malloc_get_statistics(
    132   rtems_malloc_statistics_t *stats
    133 );
    134 
    135 /**
    136  *  @brief Print Malloc Statistic Usage Report
    137  *
    138  *  This method prints a malloc statistics report.
    139  *
    140  *  @note It uses printk to print the report.
    141  */
    142 void malloc_report_statistics(void);
    143 
    144 /**
    145  *  @brief Print Malloc Statistic Usage Report
    146  *
    147  *  This method prints a malloc statistics report.
    148  *
    149  *  @param[in] context is the context to pass to the print handler
    150  *  @param[in] print is the print handler
    151  *
    152  *  @note It uses the CALLER's routine to print the report.
    153  */
    154 void malloc_report_statistics_with_plugin(
    155   void                  *context,
    156   rtems_printk_plugin_t  print
    15794);
    15895
  • cpukit/libcsupport/src/calloc.c

    r3b4ca3a r01557b0  
    2020
    2121#if defined(RTEMS_NEWLIB) && !defined(HAVE_CALLOC)
    22 #include "malloc_p.h"
    2322#include <stdlib.h>
    2423#include <string.h>
     
    3231  size_t  length;
    3332
    34   MSBUMP(calloc_calls, 1);
    35 
    3633  length = nelem * elsize;
    3734  cptr = malloc( length );
     
    3936    memset( cptr, '\0', length );
    4037
    41   MSBUMP(malloc_calls, (uint32_t) -1);   /* subtract off the malloc */
    42 
    4338  return cptr;
    4439}
  • cpukit/libcsupport/src/free.c

    r3b4ca3a r01557b0  
    2525#include <rtems/score/sysstate.h>
    2626
     27#include "malloc_p.h"
     28
    2729void free(
    2830  void *ptr
    2931)
    3032{
    31   MSBUMP(free_calls, 1);
    32 
    3333  if ( !ptr )
    3434    return;
     
    4242  }
    4343
    44   /*
    45    *  If configured, update the statistics
    46    */
    47   if ( rtems_malloc_statistics_helpers )
    48     (*rtems_malloc_statistics_helpers->at_free)(ptr);
    49 
    5044  if ( !_Protected_heap_Free( RTEMS_Malloc_Heap, ptr ) ) {
    5145    printk( "Program heap: free of bad pointer %p -- range %p - %p \n",
  • cpukit/libcsupport/src/malloc.c

    r3b4ca3a r01557b0  
    3030{
    3131  void        *return_this;
    32 
    33   MSBUMP(malloc_calls, 1);
    3432
    3533  /*
     
    7270    (*rtems_malloc_dirty_helper)( return_this, size );
    7371
    74   /*
    75    *  If configured, update the statistics
    76    */
    77   if ( rtems_malloc_statistics_helpers )
    78     (*rtems_malloc_statistics_helpers->at_malloc)(return_this);
    79 
    8072  return return_this;
    8173}
  • cpukit/libcsupport/src/malloc_initialize.c

    r3b4ca3a r01557b0  
    2323
    2424#ifdef RTEMS_NEWLIB
    25 rtems_malloc_statistics_t rtems_malloc_statistics;
    26 
    2725void RTEMS_Malloc_Initialize(
    2826  const Heap_Area *areas,
     
    6058    }
    6159  }
    62 
    63   /*
    64    *  If configured, initialize the statistics support
    65    */
    66   if ( rtems_malloc_statistics_helpers != NULL ) {
    67     (*rtems_malloc_statistics_helpers->initialize)();
    68   }
    69 
    70   MSBUMP( space_available, _Protected_heap_Get_size( heap ) );
    7160}
    7261#else
  • cpukit/libcsupport/src/malloc_p.h

    r3b4ca3a r01557b0  
    2323
    2424/*
    25  *  Malloc Statistics Structure
    26  */
    27 extern rtems_malloc_statistics_t rtems_malloc_statistics;
    28 
    29 #define MSBUMP(_f,_n)    rtems_malloc_statistics._f += (_n)
    30 
    31 /*
    3225 *  Process deferred free operations
    3326 */
  • cpukit/libcsupport/src/posix_memalign.c

    r3b4ca3a r01557b0  
    22 * @file
    33 *
    4  * @brief Update call statistics
    54 * @ingroup libcsupport
    65 */
     
    3130)
    3231{
    33   /*
    34    *  Update call statistics
    35    */
    36   MSBUMP(memalign_calls, 1);
    37 
    3832  if (((alignment - 1) & alignment) != 0 || (alignment < sizeof(void *)))
    3933    return EINVAL;
  • cpukit/libcsupport/src/realloc.c

    r3b4ca3a r01557b0  
    3535  uintptr_t old_size;
    3636  char    *new_area;
    37 
    38   MSBUMP(realloc_calls, 1);
    3937
    4038  /*
     
    7876  new_area = malloc( size );
    7977
    80   MSBUMP(malloc_calls, (uint32_t) -1);   /* subtract off the malloc */
    81 
    8278  if ( !new_area ) {
    8379    return (void *) 0;
  • cpukit/libcsupport/src/rtems_heap_extend_via_sbrk.c

    r3b4ca3a r01557b0  
    5353
    5454      if ( ok ) {
    55         MSBUMP( space_available, sbrk_size );
    56 
    5755        return_this = _Protected_heap_Allocate( heap, alloc_size );
    5856      } else {
  • cpukit/libcsupport/src/rtems_memalign.c

    r3b4ca3a r01557b0  
    6363    return ENOMEM;
    6464
    65   /*
    66    *  If configured, update the more involved statistics
    67    */
    68   if ( rtems_malloc_statistics_helpers )
    69     (*rtems_malloc_statistics_helpers->at_malloc)(pointer);
    70 
    7165  *pointer = return_this;
    7266  return 0;
  • cpukit/libmisc/shell/main_mallocinfo.c

    r3b4ca3a r01557b0  
    2020#include <rtems/malloc.h>
    2121#include <rtems/libcsupport.h>
    22 #include <rtems/shell.h>
     22#include <rtems/shellconfig.h>
    2323
    2424#include "internal.h"
     
    2929)
    3030{
    31   if ( argc == 2 ) {
     31  if ( argc == 2 && strcmp( argv[ 1 ], "walk" ) == 0 ) {
     32    malloc_walk( 0, true );
     33  } else {
     34    region_information_block info;
     35
    3236    rtems_shell_print_unified_work_area_message();
     37    malloc_info( &info );
     38    rtems_shell_print_heap_info( "free", &info.Free );
     39    rtems_shell_print_heap_info( "used", &info.Used );
     40  }
    3341
    34     if ( !strcmp( argv[1], "info" ) ) {
    35       region_information_block info;
    36 
    37       malloc_info( &info );
    38       rtems_shell_print_heap_info( "free", &info.Free );
    39       rtems_shell_print_heap_info( "used", &info.Used );
    40       return 0;
    41     } else if ( !strcmp( argv[1], "stats" ) ) {
    42       malloc_report_statistics_with_plugin(
    43         stdout,
    44         (rtems_printk_plugin_t) fprintf
    45       );
    46       return 0;
    47     }
    48   }
    49   fprintf( stderr, "%s: [info|stats]\n", argv[0] );
    50   return -1;
     42  return 0;
    5143}
    5244
    5345rtems_shell_cmd_t rtems_shell_MALLOC_INFO_Command = {
    5446  "malloc",                                   /* name */
    55   "[info|stats]",                             /* usage */
     47  "malloc [walk]",                            /* usage */
    5648  "mem",                                      /* topic */
    5749  rtems_shell_main_malloc_info,               /* command */
  • cpukit/sapi/include/confdefs.h

    r3b4ca3a r01557b0  
    11161116#ifdef CONFIGURE_INIT
    11171117  /**
    1118    * This configures the malloc family statistics to be available.
    1119    * By default only function call counts are kept.
    1120    */
    1121   rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers =
    1122     #ifndef CONFIGURE_MALLOC_STATISTICS
    1123       NULL;
    1124     #else
    1125       &rtems_malloc_statistics_helpers_table;
    1126     #endif
    1127 #endif
    1128 
    1129 #ifdef CONFIGURE_INIT
    1130   /**
    11311118   * This configures the sbrk() support for the malloc family.
    11321119   * By default it is assumed that the BSP provides all available
  • doc/shell/memory.t

    r3b4ca3a r01557b0  
    531531
    532532@example
    533 malloc [info|stats]
     533malloc [walk]
    534534@end example
    535535
    536536@subheading DESCRIPTION:
    537537
    538 This command prints either information or statistics about the
    539 C Program Heap used by the @code{malloc} family of calls based upon
    540 the value of the first argument passed to the command.
    541 
    542 When the subcommand @code{info} is specified, information on the
    543 current state of the C Program Heap is reported.  This includes the following
    544 information:
     538This command prints information about the current state of the C Program Heap
     539used by the @code{malloc()} family of calls if no or invalid options are passed
     540to the command.  This includes the following information:
    545541
    546542@itemize @bullet
     
    553549@end itemize
    554550
    555 When the subcommand @code{stats} is specified, statistics on the
    556 the C Program Heap are reported.  Malloc Family Statistics must
    557 be enabled for all of the values to be updated.  The statistics
    558 available includes the following information:
    559 
    560 @itemize @bullet
    561 @item
    562 @item Currently available memory (in kilobytes)
    563 @item Currently allocated memory (in kilobytes)
    564 @item Maximum amount of memory ever allocated (in kilobytes)
    565 @item Lifetime tally of allocated memory  (in kilobytes)
    566 @item Lifetime tally of freed memory (in kilobytes)
    567 @item Number of calls to @code{malloc}
    568 @item Number of calls to @code{free}
    569 @item Number of calls to @code{realloc}
    570 @item Number of calls to @code{calloc}
    571 @end itemize
     551When the subcommand @code{walk} is specified, then a heap walk will be
     552performed and information about each block is printed out.
    572553
    573554@subheading EXIT STATUS:
     
    577558@subheading NOTES:
    578559
    579 @findex CONFIGURE_MALLOC_STATISTICS
    580 
    581 The @code{CONFIGURE_MALLOC_STATISTICS} @code{confdefs.h} constant
    582 must be defined when the application is configured for the full
    583 set of statistics information to be available.
     560NONE
    584561
    585562@subheading EXAMPLES:
     
    588565
    589566@example
    590 SHLL [/] $ malloc info
     567SHLL [/] $ malloc
    591568Number of free blocks: 3
    592569Largest free block:    3626672
     
    595572Largest used block:    1048
    596573Total bytes used:      10136
    597 SHLL [/] $ malloc stats
    598 Malloc statistics
    599   avail:3552k  allocated:9k (0%) max:10k (0%) lifetime:21k freed:12k
    600   Call counts:   malloc:203   free:93   realloc:0   calloc:20
    601 SHLL [/] $ malloc info
    602 Number of free blocks: 3
    603 Largest free block:    3626672
    604 Total bytes free:      3627768
    605 Number of used blocks: 130
    606 Largest used block:    1048
    607 Total bytes used:      10136
    608 SHLL [/] $ malloc stats
    609 Malloc statistics
    610   avail:3552k  allocated:9k (0%) max:10k (0%) lifetime:23k freed:14k
    611   Call counts:   malloc:205   free:95   realloc:0   calloc:20
    612 @end example
    613 
    614 Note that in the above example, the lifetime allocated and free
    615 values have increased between the two calls to @code{malloc stats}
    616 even though the amount of memory available in the C Program Heap
    617 is the same in both the @code{malloc info} invocations. This indicates
    618 that memory was allocated and freed as a side-effect of the commands.
     574SHLL [/] $ malloc walk
     575malloc walk
     576PASS[0]: page size 8, min block size 48
     577        area begin 0x00210210, area end 0x0FFFC000
     578        first block 0x00210214, last block 0x0FFFBFDC
     579        first free 0x00228084, last free 0x00228354
     580PASS[0]: block 0x00210214: size 88
     581...
     582PASS[0]: block 0x00220154: size 144
     583PASS[0]: block 0x002201E4: size 168, prev 0x002205BC, next 0x00228354 (= last free)
     584PASS[0]: block 0x0022028C: size 168, prev_size 168
     585...
     586PASS[0]: block 0x00226E7C: size 4136
     587PASS[0]: block 0x00227EA4: size 408, prev 0x00228084 (= first free), next 0x00226CE4
     588PASS[0]: block 0x0022803C: size 72, prev_size 408
     589PASS[0]: block 0x00228084: size 648, prev 0x0020F75C (= head), next 0x00227EA4
     590PASS[0]: block 0x0022830C: size 72, prev_size 648
     591PASS[0]: block 0x00228354: size 266157192, prev 0x002201E4, next 0x0020F75C (= tail)
     592PASS[0]: block 0x0FFFBFDC: size 4028711480, prev_size 266157192
     593@end example
    619594
    620595@subheading CONFIGURATION:
  • doc/user/conf.t

    r3b4ca3a r01557b0  
    24332433related configuration parameters supported by
    24342434@code{<rtems/confdefs.h>}.
    2435 
    2436 @c
    2437 @c === CONFIGURE_MALLOC_STATISTICS ===
    2438 @c
    2439 @subsection Enable Malloc Family Statistics
    2440 
    2441 @findex CONFIGURE_MALLOC_STATISTICS
    2442 
    2443 
    2444 @table @b
    2445 @item CONSTANT:
    2446 @code{CONFIGURE_MALLOC_STATISTICS}
    2447 
    2448 @item DATA TYPE:
    2449 Boolean feature macro.
    2450 
    2451 @item RANGE:
    2452 Defined or undefined.
    2453 
    2454 @item DEFAULT VALUE:
    2455 This is not defined by default, and Malloc Statistics are disabled.
    2456 
    2457 @end table
    2458 
    2459 @subheading DESCRIPTION:
    2460 This configuration parameter is defined when the application wishes to
    2461 enable the gathering of more detailed statistics on the C Malloc Family
    2462 of routines.
    2463 
    2464 @subheading NOTES:
    2465 None.
    24662435
    24672436@c
  • testsuites/libtests/Makefile.am

    r3b4ca3a r01557b0  
    2525_SUBDIRS += bspcmdline01 cpuuse devfs01 devfs02 devfs03 devfs04 \
    2626    deviceio01 devnullfatal01 dumpbuf01 gxx01 top\
    27     malloctest malloc02 malloc03 malloc04 malloc05 heapwalk \
     27    malloctest malloc02 malloc03 malloc04 heapwalk \
    2828    putenvtest monitor monitor02 rtmonuse stackchk stackchk01 \
    2929    termios termios01 termios02 termios03 termios04 termios05 \
  • testsuites/libtests/configure.ac

    r3b4ca3a r01557b0  
    118118malloc03/Makefile
    119119malloc04/Makefile
    120 malloc05/Makefile
    121120monitor/Makefile
    122121monitor02/Makefile
  • testsuites/libtests/malloctest/task1.c

    r3b4ca3a r01557b0  
    6060    printf("mallocing %d bytes\n",mem_amt);
    6161    memset( mem_ptr, mem_amt, mem_amt );
    62     malloc_report_statistics();
    6362    malloc_walk_ok = malloc_walk( 1, false );
    6463    rtems_test_assert( malloc_walk_ok );
Note: See TracChangeset for help on using the changeset viewer.