Changeset 01557b0 in rtems
- Timestamp:
- 11/27/14 10:44:48 (9 years ago)
- Branches:
- 4.11, 5, 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)
- Files:
-
- 8 deleted
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/libcsupport/Makefile.am
r3b4ca3a r01557b0 99 99 src/free.c src/_free_r.c \ 100 100 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 \ 105 104 src/rtems_memalign.c src/malloc_deferred.c \ 106 105 src/malloc_dirtier.c src/malloc_p.h src/rtems_malloc.c \ -
cpukit/libcsupport/include/rtems/malloc.h
r3b4ca3a r01557b0 49 49 ); 50 50 51 /*52 * Malloc Statistics Structure53 */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 plugin68 */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_t76 rtems_malloc_statistics_helpers_table;77 extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers;78 79 51 extern ptrdiff_t RTEMS_Malloc_Sbrk_amount; 80 52 … … 120 92 void *start, 121 93 size_t size 122 );123 124 /**125 * @brief Print Malloc Statistic Usage Report126 *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 *stats133 );134 135 /**136 * @brief Print Malloc Statistic Usage Report137 *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 Report146 *147 * This method prints a malloc statistics report.148 *149 * @param[in] context is the context to pass to the print handler150 * @param[in] print is the print handler151 *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 print157 94 ); 158 95 -
cpukit/libcsupport/src/calloc.c
r3b4ca3a r01557b0 20 20 21 21 #if defined(RTEMS_NEWLIB) && !defined(HAVE_CALLOC) 22 #include "malloc_p.h"23 22 #include <stdlib.h> 24 23 #include <string.h> … … 32 31 size_t length; 33 32 34 MSBUMP(calloc_calls, 1);35 36 33 length = nelem * elsize; 37 34 cptr = malloc( length ); … … 39 36 memset( cptr, '\0', length ); 40 37 41 MSBUMP(malloc_calls, (uint32_t) -1); /* subtract off the malloc */42 43 38 return cptr; 44 39 } -
cpukit/libcsupport/src/free.c
r3b4ca3a r01557b0 25 25 #include <rtems/score/sysstate.h> 26 26 27 #include "malloc_p.h" 28 27 29 void free( 28 30 void *ptr 29 31 ) 30 32 { 31 MSBUMP(free_calls, 1);32 33 33 if ( !ptr ) 34 34 return; … … 42 42 } 43 43 44 /*45 * If configured, update the statistics46 */47 if ( rtems_malloc_statistics_helpers )48 (*rtems_malloc_statistics_helpers->at_free)(ptr);49 50 44 if ( !_Protected_heap_Free( RTEMS_Malloc_Heap, ptr ) ) { 51 45 printk( "Program heap: free of bad pointer %p -- range %p - %p \n", -
cpukit/libcsupport/src/malloc.c
r3b4ca3a r01557b0 30 30 { 31 31 void *return_this; 32 33 MSBUMP(malloc_calls, 1);34 32 35 33 /* … … 72 70 (*rtems_malloc_dirty_helper)( return_this, size ); 73 71 74 /*75 * If configured, update the statistics76 */77 if ( rtems_malloc_statistics_helpers )78 (*rtems_malloc_statistics_helpers->at_malloc)(return_this);79 80 72 return return_this; 81 73 } -
cpukit/libcsupport/src/malloc_initialize.c
r3b4ca3a r01557b0 23 23 24 24 #ifdef RTEMS_NEWLIB 25 rtems_malloc_statistics_t rtems_malloc_statistics;26 27 25 void RTEMS_Malloc_Initialize( 28 26 const Heap_Area *areas, … … 60 58 } 61 59 } 62 63 /*64 * If configured, initialize the statistics support65 */66 if ( rtems_malloc_statistics_helpers != NULL ) {67 (*rtems_malloc_statistics_helpers->initialize)();68 }69 70 MSBUMP( space_available, _Protected_heap_Get_size( heap ) );71 60 } 72 61 #else -
cpukit/libcsupport/src/malloc_p.h
r3b4ca3a r01557b0 23 23 24 24 /* 25 * Malloc Statistics Structure26 */27 extern rtems_malloc_statistics_t rtems_malloc_statistics;28 29 #define MSBUMP(_f,_n) rtems_malloc_statistics._f += (_n)30 31 /*32 25 * Process deferred free operations 33 26 */ -
cpukit/libcsupport/src/posix_memalign.c
r3b4ca3a r01557b0 2 2 * @file 3 3 * 4 * @brief Update call statistics5 4 * @ingroup libcsupport 6 5 */ … … 31 30 ) 32 31 { 33 /*34 * Update call statistics35 */36 MSBUMP(memalign_calls, 1);37 38 32 if (((alignment - 1) & alignment) != 0 || (alignment < sizeof(void *))) 39 33 return EINVAL; -
cpukit/libcsupport/src/realloc.c
r3b4ca3a r01557b0 35 35 uintptr_t old_size; 36 36 char *new_area; 37 38 MSBUMP(realloc_calls, 1);39 37 40 38 /* … … 78 76 new_area = malloc( size ); 79 77 80 MSBUMP(malloc_calls, (uint32_t) -1); /* subtract off the malloc */81 82 78 if ( !new_area ) { 83 79 return (void *) 0; -
cpukit/libcsupport/src/rtems_heap_extend_via_sbrk.c
r3b4ca3a r01557b0 53 53 54 54 if ( ok ) { 55 MSBUMP( space_available, sbrk_size );56 57 55 return_this = _Protected_heap_Allocate( heap, alloc_size ); 58 56 } else { -
cpukit/libcsupport/src/rtems_memalign.c
r3b4ca3a r01557b0 63 63 return ENOMEM; 64 64 65 /*66 * If configured, update the more involved statistics67 */68 if ( rtems_malloc_statistics_helpers )69 (*rtems_malloc_statistics_helpers->at_malloc)(pointer);70 71 65 *pointer = return_this; 72 66 return 0; -
cpukit/libmisc/shell/main_mallocinfo.c
r3b4ca3a r01557b0 20 20 #include <rtems/malloc.h> 21 21 #include <rtems/libcsupport.h> 22 #include <rtems/shell .h>22 #include <rtems/shellconfig.h> 23 23 24 24 #include "internal.h" … … 29 29 ) 30 30 { 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 32 36 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 } 33 41 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; 51 43 } 52 44 53 45 rtems_shell_cmd_t rtems_shell_MALLOC_INFO_Command = { 54 46 "malloc", /* name */ 55 " [info|stats]",/* usage */47 "malloc [walk]", /* usage */ 56 48 "mem", /* topic */ 57 49 rtems_shell_main_malloc_info, /* command */ -
cpukit/sapi/include/confdefs.h
r3b4ca3a r01557b0 1116 1116 #ifdef CONFIGURE_INIT 1117 1117 /** 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_STATISTICS1123 NULL;1124 #else1125 &rtems_malloc_statistics_helpers_table;1126 #endif1127 #endif1128 1129 #ifdef CONFIGURE_INIT1130 /**1131 1118 * This configures the sbrk() support for the malloc family. 1132 1119 * By default it is assumed that the BSP provides all available -
doc/shell/memory.t
r3b4ca3a r01557b0 531 531 532 532 @example 533 malloc [ info|stats]533 malloc [walk] 534 534 @end example 535 535 536 536 @subheading DESCRIPTION: 537 537 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: 538 This command prints information about the current state of the C Program Heap 539 used by the @code{malloc()} family of calls if no or invalid options are passed 540 to the command. This includes the following information: 545 541 546 542 @itemize @bullet … … 553 549 @end itemize 554 550 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 551 When the subcommand @code{walk} is specified, then a heap walk will be 552 performed and information about each block is printed out. 572 553 573 554 @subheading EXIT STATUS: … … 577 558 @subheading NOTES: 578 559 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. 560 NONE 584 561 585 562 @subheading EXAMPLES: … … 588 565 589 566 @example 590 SHLL [/] $ malloc info567 SHLL [/] $ malloc 591 568 Number of free blocks: 3 592 569 Largest free block: 3626672 … … 595 572 Largest used block: 1048 596 573 Total 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. 574 SHLL [/] $ malloc walk 575 malloc walk 576 PASS[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 580 PASS[0]: block 0x00210214: size 88 581 ... 582 PASS[0]: block 0x00220154: size 144 583 PASS[0]: block 0x002201E4: size 168, prev 0x002205BC, next 0x00228354 (= last free) 584 PASS[0]: block 0x0022028C: size 168, prev_size 168 585 ... 586 PASS[0]: block 0x00226E7C: size 4136 587 PASS[0]: block 0x00227EA4: size 408, prev 0x00228084 (= first free), next 0x00226CE4 588 PASS[0]: block 0x0022803C: size 72, prev_size 408 589 PASS[0]: block 0x00228084: size 648, prev 0x0020F75C (= head), next 0x00227EA4 590 PASS[0]: block 0x0022830C: size 72, prev_size 648 591 PASS[0]: block 0x00228354: size 266157192, prev 0x002201E4, next 0x0020F75C (= tail) 592 PASS[0]: block 0x0FFFBFDC: size 4028711480, prev_size 266157192 593 @end example 619 594 620 595 @subheading CONFIGURATION: -
doc/user/conf.t
r3b4ca3a r01557b0 2433 2433 related configuration parameters supported by 2434 2434 @code{<rtems/confdefs.h>}. 2435 2436 @c2437 @c === CONFIGURE_MALLOC_STATISTICS ===2438 @c2439 @subsection Enable Malloc Family Statistics2440 2441 @findex CONFIGURE_MALLOC_STATISTICS2442 2443 2444 @table @b2445 @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 table2458 2459 @subheading DESCRIPTION:2460 This configuration parameter is defined when the application wishes to2461 enable the gathering of more detailed statistics on the C Malloc Family2462 of routines.2463 2464 @subheading NOTES:2465 None.2466 2435 2467 2436 @c -
testsuites/libtests/Makefile.am
r3b4ca3a r01557b0 25 25 _SUBDIRS += bspcmdline01 cpuuse devfs01 devfs02 devfs03 devfs04 \ 26 26 deviceio01 devnullfatal01 dumpbuf01 gxx01 top\ 27 malloctest malloc02 malloc03 malloc04 malloc05heapwalk \27 malloctest malloc02 malloc03 malloc04 heapwalk \ 28 28 putenvtest monitor monitor02 rtmonuse stackchk stackchk01 \ 29 29 termios termios01 termios02 termios03 termios04 termios05 \ -
testsuites/libtests/configure.ac
r3b4ca3a r01557b0 118 118 malloc03/Makefile 119 119 malloc04/Makefile 120 malloc05/Makefile121 120 monitor/Makefile 122 121 monitor02/Makefile -
testsuites/libtests/malloctest/task1.c
r3b4ca3a r01557b0 60 60 printf("mallocing %d bytes\n",mem_amt); 61 61 memset( mem_ptr, mem_amt, mem_amt ); 62 malloc_report_statistics();63 62 malloc_walk_ok = malloc_walk( 1, false ); 64 63 rtems_test_assert( malloc_walk_ok );
Note: See TracChangeset
for help on using the changeset viewer.