Print heap memory usage statistics before exit (host version).

This commit is contained in:
Ruben Ayrapetyan
2014-07-25 19:09:10 +04:00
parent d90dccde9a
commit 5e4078095a
4 changed files with 63 additions and 51 deletions
+59 -49
View File
@@ -417,63 +417,73 @@ mem_heap_recommend_allocation_size( size_t minimum_allocation_size) /**< minimum
* Print heap * Print heap
*/ */
void void
mem_heap_print( bool dump_block_data) /**< print block with data (true) mem_heap_print( bool dump_block_headers, /**< print block headers */
or print only block header (false) */ bool dump_block_data, /**< print block with data (true)
or print only block header (false) */
bool dump_stats) /**< print heap stats */
{ {
mem_check_heap(); mem_check_heap();
__printf("Heap: start=%p size=%lu, first block->%p, last block->%p\n", JERRY_ASSERT( !dump_block_data || dump_block_headers );
mem_heap.heap_start,
mem_heap.heap_size,
(void*) mem_heap.first_block_p,
(void*) mem_heap.last_block_p);
for ( mem_block_header_t *block_p = mem_heap.first_block_p; if ( dump_block_headers )
block_p != NULL;
block_p = block_p->neighbours[ MEM_DIRECTION_NEXT ] )
{
__printf("Block (%p): magic num=0x%08x, size in chunks=%lu, previous block->%p next block->%p\n",
(void*) block_p,
block_p->magic_num,
mem_get_block_chunks_count( block_p),
(void*) block_p->neighbours[ MEM_DIRECTION_PREV ],
(void*) block_p->neighbours[ MEM_DIRECTION_NEXT ]);
if ( dump_block_data )
{ {
uint8_t *block_data_p = (uint8_t*) (block_p + 1); __printf("Heap: start=%p size=%lu, first block->%p, last block->%p\n",
for ( uint32_t offset = 0; mem_heap.heap_start,
offset < mem_get_block_data_space_size( block_p); mem_heap.heap_size,
offset++ ) (void*) mem_heap.first_block_p,
{ (void*) mem_heap.last_block_p);
__printf("%02x ", block_data_p[ offset ]);
} for ( mem_block_header_t *block_p = mem_heap.first_block_p;
__printf("\n"); block_p != NULL;
block_p = block_p->neighbours[ MEM_DIRECTION_NEXT ] )
{
__printf("Block (%p): magic num=0x%08x, size in chunks=%lu, previous block->%p next block->%p\n",
(void*) block_p,
block_p->magic_num,
mem_get_block_chunks_count( block_p),
(void*) block_p->neighbours[ MEM_DIRECTION_PREV ],
(void*) block_p->neighbours[ MEM_DIRECTION_NEXT ]);
if ( dump_block_data )
{
uint8_t *block_data_p = (uint8_t*) (block_p + 1);
for ( uint32_t offset = 0;
offset < mem_get_block_data_space_size( block_p);
offset++ )
{
__printf("%02x ", block_data_p[ offset ]);
}
__printf("\n");
}
}
} }
}
#ifdef MEM_STATS #ifdef MEM_STATS
__printf("Heap stats:\n"); if ( dump_stats )
__printf(" Size = %lu\n" {
" Blocks count = %lu\n" __printf("Heap stats:\n");
" Allocated blocks count = %lu\n" __printf(" Size = %lu\n"
" Allocated chunks count = %lu\n" " Blocks count = %lu\n"
" Allocated bytes count = %lu\n" " Allocated blocks count = %lu\n"
" Waste bytes count = %lu\n" " Allocated chunks count = %lu\n"
" Peak allocated blocks count = %lu\n" " Allocated bytes count = %lu\n"
" Peak allocated chunks count = %lu\n" " Waste bytes count = %lu\n"
" Peak allocated bytes count = %lu\n" " Peak allocated blocks count = %lu\n"
" Peak waste bytes count = %lu\n", " Peak allocated chunks count = %lu\n"
mem_heap_stats.size, " Peak allocated bytes count = %lu\n"
mem_heap_stats.blocks, " Peak waste bytes count = %lu\n",
mem_heap_stats.allocated_blocks, mem_heap_stats.size,
mem_heap_stats.allocated_chunks, mem_heap_stats.blocks,
mem_heap_stats.allocated_bytes, mem_heap_stats.allocated_blocks,
mem_heap_stats.waste_bytes, mem_heap_stats.allocated_chunks,
mem_heap_stats.peak_allocated_blocks, mem_heap_stats.allocated_bytes,
mem_heap_stats.peak_allocated_chunks, mem_heap_stats.waste_bytes,
mem_heap_stats.peak_allocated_bytes, mem_heap_stats.peak_allocated_blocks,
mem_heap_stats.peak_waste_bytes); mem_heap_stats.peak_allocated_chunks,
mem_heap_stats.peak_allocated_bytes,
mem_heap_stats.peak_waste_bytes);
}
#endif /* MEM_STATS */ #endif /* MEM_STATS */
__printf("\n"); __printf("\n");
+1 -1
View File
@@ -42,7 +42,7 @@ extern void mem_heap_init(uint8_t *heap_start, size_t heap_size);
extern uint8_t* mem_heap_alloc_block(size_t size_in_bytes, mem_heap_alloc_term_t alloc_term); extern uint8_t* mem_heap_alloc_block(size_t size_in_bytes, mem_heap_alloc_term_t alloc_term);
extern void mem_heap_free_block(uint8_t *ptr); extern void mem_heap_free_block(uint8_t *ptr);
extern size_t mem_heap_recommend_allocation_size(size_t minimum_allocation_size); extern size_t mem_heap_recommend_allocation_size(size_t minimum_allocation_size);
extern void mem_heap_print(bool dump_block_data); extern void mem_heap_print(bool dump_block_headers, bool dump_block_data, bool dump_stats);
#ifdef MEM_STATS #ifdef MEM_STATS
/** /**
+2
View File
@@ -144,6 +144,8 @@ main (int argc __unused,
jerry_run( source_p, jerry_run( source_p,
source_size); source_size);
mem_heap_print( false, false, true);
return 0; return 0;
} }
#endif #endif
+1 -1
View File
@@ -82,7 +82,7 @@ main( int __unused argc,
} }
} }
mem_heap_print( false); mem_heap_print( true, false, true);
return 0; return 0;
} /* main */ } /* main */