introduce WAMR memory profiling tool (experimental) (#390)

This commit is contained in:
Xu Jun
2020-09-18 18:04:56 +08:00
committed by GitHub
parent 04a7cc322f
commit 0226dbbb3d
27 changed files with 848 additions and 205 deletions

View File

@ -385,10 +385,6 @@ gc_alloc_vo_internal(void *vheap, gc_size_t size,
/* clear buffer appended by GC_ALIGN_8() */
memset((uint8*)ret + size, 0, tot_size - tot_size_unaligned);
#if BH_ENABLE_MEMORY_PROFILING != 0
os_printf("HEAP.ALLOC: heap: %p, size: %u\n", heap, size);
#endif
finish:
os_mutex_unlock(&heap->lock);
return ret;
@ -469,10 +465,6 @@ gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size,
ret = hmu_to_obj(hmu);
#if BH_ENABLE_MEMORY_PROFILING != 0
os_printf("HEAP.ALLOC: heap: %p, size: %u\n", heap, size);
#endif
finish:
os_mutex_unlock(&heap->lock);
@ -548,9 +540,6 @@ gc_free_vo_internal(void *vheap, gc_object_t obj,
g_total_free += size;
heap->total_free_size += size;
#if BH_ENABLE_MEMORY_PROFILING != 0
os_printf("HEAP.FREE, heap: %p, size: %u\n", heap, size);
#endif
if (!hmu_get_pinuse(hmu)) {
prev = (hmu_t*) ((char*) hmu - *((int*) hmu - 1));
@ -600,6 +589,12 @@ gc_dump_heap_stats(gc_heap_t *heap)
g_total_malloc, g_total_free, g_total_malloc - g_total_free);
}
uint32
gc_get_heap_highmark_size(gc_heap_t *heap)
{
return heap->highmark_size;
}
void
gci_dump(gc_heap_t *heap)
{

View File

@ -145,7 +145,9 @@ hmu_verify(hmu_t *hmu);
* HMU free chunk management
*/
#ifndef HMU_NORMAL_NODE_CNT
#define HMU_NORMAL_NODE_CNT 32
#endif
#define HMU_FC_NORMAL_MAX_SIZE ((HMU_NORMAL_NODE_CNT - 1) << 3)
#define HMU_IS_FC_NORMAL(size) ((size) < HMU_FC_NORMAL_MAX_SIZE)
#if HMU_FC_NORMAL_MAX_SIZE >= GC_MAX_HEAP_SIZE

View File

@ -9,16 +9,17 @@ gc_handle_t
gc_init_with_pool(char *buf, gc_size_t buf_size)
{
char *buf_end = buf + buf_size;
char *buf_aligned = (char*) (((uintptr_t) buf + 7) & (uintptr_t)~7);
char *buf_aligned = (char*)(((uintptr_t) buf + 7) & (uintptr_t)~7);
char *base_addr = buf_aligned + sizeof(gc_heap_t);
gc_heap_t *heap = (gc_heap_t*) buf_aligned;
gc_heap_t *heap = (gc_heap_t*)buf_aligned;
gc_size_t heap_max_size;
hmu_normal_node_t *p = NULL;
hmu_tree_node_t *root = NULL, *q = NULL;
int i = 0, ret;
if (buf_size < 1024) {
os_printf("[GC_ERROR]heap_init_size(%d) < 1024\n", buf_size);
if (buf_size < APP_HEAP_SIZE_MIN) {
os_printf("[GC_ERROR]heap init buf size (%u) < %u\n",
buf_size, APP_HEAP_SIZE_MIN);
return NULL;
}
@ -66,12 +67,14 @@ gc_init_with_pool(char *buf, gc_size_t buf_size)
q->parent = root;
q->size = heap->current_size;
bh_assert(root->size <= HMU_FC_NORMAL_MAX_SIZE
&& HMU_FC_NORMAL_MAX_SIZE < q->size);
bh_assert(root->size <= HMU_FC_NORMAL_MAX_SIZE);
#if BH_ENABLE_MEMORY_PROFILING != 0
os_printf("heap is successfully initialized with max_size=%u.\n",
heap_max_size);
#if WASM_ENABLE_MEMORY_TRACING != 0
os_printf("Heap created, total size: %u\n", buf_size);
os_printf(" heap struct size: %u\n", sizeof(gc_heap_t));
os_printf(" actual heap size: %u\n", heap_max_size);
os_printf(" padding bytes: %u\n",
buf_size - sizeof(gc_heap_t) - heap_max_size);
#endif
return heap;
}