aboutsummaryrefslogtreecommitdiff
path: root/jerry-core
diff options
context:
space:
mode:
authorAkos Kiss <akiss@inf.u-szeged.hu>2016-02-04 18:14:22 +0100
committerLászló Langó <llango.u-szeged@partner.samsung.com>2016-02-09 14:19:28 +0100
commit196e8196fc67d296dc6d350810ee71a1a2de7dbe (patch)
treeee1af3766c2044e8a8812ab758d72ac6a8e8383b /jerry-core
parent2221c00ad97f856dd464233ab6d99678f61cb466 (diff)
Eliminate code duplication in memory statistics printing
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
Diffstat (limited to 'jerry-core')
-rw-r--r--jerry-core/mem/mem-allocator.cpp29
-rw-r--r--jerry-core/mem/mem-heap.cpp43
-rw-r--r--jerry-core/mem/mem-heap.h1
3 files changed, 34 insertions, 39 deletions
diff --git a/jerry-core/mem/mem-allocator.cpp b/jerry-core/mem/mem-allocator.cpp
index 2fd89168..473a1e68 100644
--- a/jerry-core/mem/mem-allocator.cpp
+++ b/jerry-core/mem/mem-allocator.cpp
@@ -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"
diff --git a/jerry-core/mem/mem-heap.cpp b/jerry-core/mem/mem-heap.cpp
index f296fa4b..6b76a566 100644
--- a/jerry-core/mem/mem-heap.cpp
+++ b/jerry-core/mem/mem-heap.cpp
@@ -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 */
/**
diff --git a/jerry-core/mem/mem-heap.h b/jerry-core/mem/mem-heap.h
index d70231a4..a5d6daa0 100644
--- a/jerry-core/mem/mem-heap.h
+++ b/jerry-core/mem/mem-heap.h
@@ -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