Eliminate code duplication in memory statistics printing

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss 2016-02-04 18:14:22 +01:00 committed by László Langó
parent 2221c00ad9
commit 196e8196fc
3 changed files with 34 additions and 39 deletions

View File

@ -51,29 +51,14 @@ mem_finalize (bool is_show_mem_stats) /**< show heap memory stats
{
mem_pools_finalize ();
#ifdef MEM_STATS
if (is_show_mem_stats)
{
mem_heap_print (false, false, true);
#ifdef MEM_STATS
mem_pools_stats_t stats;
mem_pools_get_stats (&stats);
printf ("Pools stats:\n");
printf (" Chunk size: %zu\n"
" Pools: %zu\n"
" Allocated chunks: %zu\n"
" Free chunks: %zu\n"
" Peak pools: %zu\n"
" Peak allocated chunks: %zu\n\n",
MEM_POOL_CHUNK_SIZE,
stats.pools_count,
stats.allocated_chunks,
stats.free_chunks,
stats.peak_pools_count,
stats.peak_allocated_chunks);
#endif /* MEM_STATS */
mem_stats_print ();
}
#else /* MEM_STATS */
(void) is_show_mem_stats;
#endif /* !MEM_STATS */
mem_heap_finalize ();
} /* mem_finalize */
@ -158,13 +143,13 @@ mem_stats_reset_peak (void)
void
mem_stats_print (void)
{
mem_heap_print (false, false, true);
mem_heap_stats_print ();
mem_pools_stats_t stats;
mem_pools_get_stats (&stats);
printf ("Pools stats:\n");
printf (" Chunk size: %zu\n"
printf (" Chunk size: %zu\n"
" Pools: %zu\n"
" Allocated chunks: %zu\n"
" Free chunks: %zu\n"

View File

@ -944,23 +944,7 @@ mem_heap_print (bool dump_block_headers, /**< print block headers */
#ifdef MEM_STATS
if (dump_stats)
{
printf ("Heap stats:\n");
printf (" Heap size = %zu bytes\n"
" Chunk size = %zu bytes\n"
" Allocated chunks count = %zu\n"
" Allocated = %zu bytes\n"
" Waste = %zu bytes\n"
" Peak allocated chunks count = %zu\n"
" Peak allocated = %zu bytes\n"
" Peak waste = %zu bytes\n",
mem_heap_stats.size,
MEM_HEAP_CHUNK_SIZE,
mem_heap_stats.allocated_chunks,
mem_heap_stats.allocated_bytes,
mem_heap_stats.waste_bytes,
mem_heap_stats.peak_allocated_chunks,
mem_heap_stats.peak_allocated_bytes,
mem_heap_stats.peak_waste_bytes);
mem_heap_stats_print ();
}
#else /* MEM_STATS */
(void) dump_stats;
@ -1108,6 +1092,31 @@ mem_heap_stat_free (size_t first_chunk_index, /**< first chunk of the freed area
mem_heap_stats.allocated_bytes -= bytes;
mem_heap_stats.waste_bytes -= waste_bytes;
} /* mem_heap_stat_free */
/**
* Print heap statistics
*/
void
mem_heap_stats_print (void)
{
printf ("Heap stats:\n");
printf (" Heap size = %zu bytes\n"
" Chunk size = %zu bytes\n"
" Allocated chunks count = %zu\n"
" Allocated = %zu bytes\n"
" Waste = %zu bytes\n"
" Peak allocated chunks count = %zu\n"
" Peak allocated = %zu bytes\n"
" Peak waste = %zu bytes\n",
mem_heap_stats.size,
MEM_HEAP_CHUNK_SIZE,
mem_heap_stats.allocated_chunks,
mem_heap_stats.allocated_bytes,
mem_heap_stats.waste_bytes,
mem_heap_stats.peak_allocated_chunks,
mem_heap_stats.peak_allocated_bytes,
mem_heap_stats.peak_waste_bytes);
} /* mem_heap_stats_print */
#endif /* MEM_STATS */
/**

View File

@ -81,6 +81,7 @@ typedef struct
extern void mem_heap_get_stats (mem_heap_stats_t *);
extern void mem_heap_stats_reset_peak (void);
extern void mem_heap_stats_print (void);
#endif /* MEM_STATS */
#ifdef JERRY_VALGRIND_FREYA