Skip to content

Commit 81183b3

Browse files
committed
use log for memory comsumption
1 parent 1446918 commit 81183b3

10 files changed

Lines changed: 48 additions & 87 deletions

File tree

build-scripts/SConscript_config

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ if GetDepend(['WAMR_BUILD_MEMORY_PROFILING']):
103103
CPPDEFINES += ['WASM_ENABLE_MEMORY_PROFILING=1']
104104
print('[WAMR] Memory profiling enabled')
105105

106-
if GetDepend(['WAMR_BUILD_MEM_PROFILING_USE_LOG']):
107-
CPPDEFINES += ['WASM_MEM_PROFILING_USE_LOG=1']
108-
print('[WAMR] Memory profiling uses structured logging')
109-
110106
if GetDepend(['WAMR_BUILD_MEMORY_TRACING']):
111107
CPPDEFINES += ['WASM_ENABLE_MEMORY_TRACING=1']
112108
print('[WAMR] Memory tracing enabled')

build-scripts/config_common.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,6 @@ if (WAMR_BUILD_MEMORY_PROFILING EQUAL 1)
478478
add_definitions (-DWASM_ENABLE_MEMORY_PROFILING=1)
479479
message (" Memory profiling enabled")
480480
endif ()
481-
if (WAMR_BUILD_MEM_PROFILING_USE_LOG EQUAL 1)
482-
add_definitions (-DWASM_MEM_PROFILING_USE_LOG=1)
483-
message (" Memory profiling uses structured logging")
484-
endif ()
485481
if (WAMR_BUILD_MEMORY_TRACING EQUAL 1)
486482
add_definitions (-DWASM_ENABLE_MEMORY_TRACING=1)
487483
message (" Memory tracing enabled")

build-scripts/esp-idf/wamr/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ if (NOT CMAKE_BUILD_EARLY_EXPANSION)
5656
set (WAMR_BUILD_MEMORY_PROFILING 1)
5757
endif ()
5858

59-
if (CONFIG_WAMR_ENABLE_MEM_PROFILING_USE_LOG)
60-
set (WAMR_BUILD_MEM_PROFILING_USE_LOG 1)
61-
endif ()
62-
6359
if (CONFIG_WAMR_ENABLE_MEMORY_TRACING)
6460
set (WAMR_BUILD_MEMORY_TRACING 1)
6561
endif ()

core/config.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,6 @@ unless used elsewhere */
347347
#define WASM_ENABLE_MEMORY_TRACING 0
348348
#endif
349349

350-
/* Use structured logging (LOG_VERBOSE) instead of os_printf for memory
351-
profiling/tracing output. When enabled, output respects the log verbose
352-
level set by bh_log_set_verbose_level(). */
353-
#ifndef WASM_MEM_PROFILING_USE_LOG
354-
#define WASM_MEM_PROFILING_USE_LOG 0
355-
#endif
356-
357350
/* Performance profiling */
358351
#ifndef WASM_ENABLE_PERF_PROFILING
359352
#define WASM_ENABLE_PERF_PROFILING 0

core/iwasm/common/wasm_native.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ register_natives(const char *module_name, NativeSymbol *native_symbols,
268268
if (!(node = wasm_runtime_malloc(sizeof(NativeSymbolsNode))))
269269
return false;
270270
#if WASM_ENABLE_MEMORY_TRACING != 0
271-
MEM_PROF_PRINTF("Register native, size: %u\n", sizeof(NativeSymbolsNode));
271+
LOG_VERBOSE("Register native, size: %u", sizeof(NativeSymbolsNode));
272272
#endif
273273

274274
node->module_name = module_name;

core/iwasm/common/wasm_runtime_common.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,26 +2029,26 @@ wasm_runtime_dump_module_mem_consumption(const WASMModuleCommon *module)
20292029
}
20302030
#endif
20312031

2032-
MEM_PROF_PRINTF("WASM module memory consumption, total size: %u\n",
2032+
LOG_VERBOSE("WASM module memory consumption, total size: %u",
20332033
mem_conspn.total_size);
2034-
MEM_PROF_PRINTF(" module struct size: %u\n",
2034+
LOG_VERBOSE(" module struct size: %u",
20352035
mem_conspn.module_struct_size);
2036-
MEM_PROF_PRINTF(" types size: %u\n", mem_conspn.types_size);
2037-
MEM_PROF_PRINTF(" imports size: %u\n", mem_conspn.imports_size);
2038-
MEM_PROF_PRINTF(" funcs size: %u\n", mem_conspn.functions_size);
2039-
MEM_PROF_PRINTF(" tables size: %u\n", mem_conspn.tables_size);
2040-
MEM_PROF_PRINTF(" memories size: %u\n", mem_conspn.memories_size);
2041-
MEM_PROF_PRINTF(" globals size: %u\n", mem_conspn.globals_size);
2042-
MEM_PROF_PRINTF(" exports size: %u\n", mem_conspn.exports_size);
2043-
MEM_PROF_PRINTF(" table segs size: %u\n", mem_conspn.table_segs_size);
2044-
MEM_PROF_PRINTF(" data segs size: %u\n", mem_conspn.data_segs_size);
2045-
MEM_PROF_PRINTF(" const strings size: %u\n", mem_conspn.const_strs_size);
2036+
LOG_VERBOSE(" types size: %u", mem_conspn.types_size);
2037+
LOG_VERBOSE(" imports size: %u", mem_conspn.imports_size);
2038+
LOG_VERBOSE(" funcs size: %u", mem_conspn.functions_size);
2039+
LOG_VERBOSE(" tables size: %u", mem_conspn.tables_size);
2040+
LOG_VERBOSE(" memories size: %u", mem_conspn.memories_size);
2041+
LOG_VERBOSE(" globals size: %u", mem_conspn.globals_size);
2042+
LOG_VERBOSE(" exports size: %u", mem_conspn.exports_size);
2043+
LOG_VERBOSE(" table segs size: %u", mem_conspn.table_segs_size);
2044+
LOG_VERBOSE(" data segs size: %u", mem_conspn.data_segs_size);
2045+
LOG_VERBOSE(" const strings size: %u", mem_conspn.const_strs_size);
20462046
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
2047-
MEM_PROF_PRINTF(" custom sections size: %u\n",
2047+
LOG_VERBOSE(" custom sections size: %u",
20482048
mem_conspn.custom_sections_size);
20492049
#endif
20502050
#if WASM_ENABLE_AOT != 0
2051-
MEM_PROF_PRINTF(" aot code size: %u\n", mem_conspn.aot_code_size);
2051+
LOG_VERBOSE(" aot code size: %u", mem_conspn.aot_code_size);
20522052
#endif
20532053
}
20542054

@@ -2071,16 +2071,16 @@ wasm_runtime_dump_module_inst_mem_consumption(
20712071
}
20722072
#endif
20732073

2074-
MEM_PROF_PRINTF("WASM module inst memory consumption, total size: %lu\n",
2074+
LOG_VERBOSE("WASM module inst memory consumption, total size: %lu",
20752075
mem_conspn.total_size);
2076-
MEM_PROF_PRINTF(" module inst struct size: %u\n",
2076+
LOG_VERBOSE(" module inst struct size: %u",
20772077
mem_conspn.module_inst_struct_size);
2078-
MEM_PROF_PRINTF(" memories size: %lu\n", mem_conspn.memories_size);
2079-
MEM_PROF_PRINTF(" app heap size: %u\n", mem_conspn.app_heap_size);
2080-
MEM_PROF_PRINTF(" tables size: %u\n", mem_conspn.tables_size);
2081-
MEM_PROF_PRINTF(" functions size: %u\n", mem_conspn.functions_size);
2082-
MEM_PROF_PRINTF(" globals size: %u\n", mem_conspn.globals_size);
2083-
MEM_PROF_PRINTF(" exports size: %u\n", mem_conspn.exports_size);
2078+
LOG_VERBOSE(" memories size: %lu", mem_conspn.memories_size);
2079+
LOG_VERBOSE(" app heap size: %u", mem_conspn.app_heap_size);
2080+
LOG_VERBOSE(" tables size: %u", mem_conspn.tables_size);
2081+
LOG_VERBOSE(" functions size: %u", mem_conspn.functions_size);
2082+
LOG_VERBOSE(" globals size: %u", mem_conspn.globals_size);
2083+
LOG_VERBOSE(" exports size: %u", mem_conspn.exports_size);
20842084
}
20852085

20862086
void
@@ -2089,15 +2089,15 @@ wasm_runtime_dump_exec_env_mem_consumption(const WASMExecEnv *exec_env)
20892089
uint32 total_size =
20902090
offsetof(WASMExecEnv, wasm_stack_u.bottom) + exec_env->wasm_stack_size;
20912091

2092-
MEM_PROF_PRINTF("Exec env memory consumption, total size: %u\n",
2092+
LOG_VERBOSE("Exec env memory consumption, total size: %u",
20932093
total_size);
2094-
MEM_PROF_PRINTF(" exec env struct size: %u\n",
2094+
LOG_VERBOSE(" exec env struct size: %u",
20952095
offsetof(WASMExecEnv, wasm_stack_u.bottom));
20962096
#if WASM_ENABLE_INTERP != 0 && WASM_ENABLE_FAST_INTERP == 0
2097-
MEM_PROF_PRINTF(" block addr cache size: %u\n",
2097+
LOG_VERBOSE(" block addr cache size: %u",
20982098
sizeof(exec_env->block_addr_cache));
20992099
#endif
2100-
MEM_PROF_PRINTF(" stack size: %u\n", exec_env->wasm_stack_size);
2100+
LOG_VERBOSE(" stack size: %u", exec_env->wasm_stack_size);
21012101
}
21022102

21032103
uint32
@@ -2158,20 +2158,20 @@ wasm_runtime_dump_mem_consumption(WASMExecEnv *exec_env)
21582158
+ exec_env->wasm_stack_size + module_mem_consps.total_size
21592159
+ module_inst_mem_consps.total_size;
21602160

2161-
MEM_PROF_PRINTF("\nMemory consumption summary (bytes):\n");
2161+
LOG_VERBOSE("Memory consumption summary (bytes):");
21622162
wasm_runtime_dump_module_mem_consumption(module_common);
21632163
wasm_runtime_dump_module_inst_mem_consumption(module_inst_common);
21642164
wasm_runtime_dump_exec_env_mem_consumption(exec_env);
2165-
MEM_PROF_PRINTF("\nTotal memory consumption of module, module inst and "
2166-
"exec env: %" PRIu64 "\n",
2165+
LOG_VERBOSE("Total memory consumption of module, module inst and "
2166+
"exec env: %" PRIu64,
21672167
total_size);
2168-
MEM_PROF_PRINTF("Total interpreter stack used: %u\n",
2168+
LOG_VERBOSE("Total interpreter stack used: %u",
21692169
exec_env->max_wasm_stack_used);
21702170

21712171
if (max_aux_stack_used != (uint32)-1)
2172-
MEM_PROF_PRINTF("Total auxiliary stack used: %u\n", max_aux_stack_used);
2172+
LOG_VERBOSE("Total auxiliary stack used: %u", max_aux_stack_used);
21732173
else
2174-
MEM_PROF_PRINTF("Total aux stack used: no enough info to profile\n");
2174+
LOG_VERBOSE("Total aux stack used: no enough info to profile");
21752175

21762176
/*
21772177
* Report the native stack usage estimation.
@@ -2183,13 +2183,13 @@ wasm_runtime_dump_mem_consumption(WASMExecEnv *exec_env)
21832183
* It doesn't cover host func implementations, signal handlers, etc.
21842184
*/
21852185
if (exec_env->native_stack_top_min != (void *)UINTPTR_MAX)
2186-
MEM_PROF_PRINTF("Native stack left: %zd\n",
2186+
LOG_VERBOSE("Native stack left: %zd",
21872187
exec_env->native_stack_top_min
21882188
- exec_env->native_stack_boundary);
21892189
else
2190-
MEM_PROF_PRINTF("Native stack left: no enough info to profile\n");
2190+
LOG_VERBOSE("Native stack left: no enough info to profile");
21912191

2192-
MEM_PROF_PRINTF("Total app heap used: %u\n", app_heap_peak_size);
2192+
LOG_VERBOSE("Total app heap used: %u", app_heap_peak_size);
21932193
}
21942194
#endif /* end of (WASM_ENABLE_MEMORY_PROFILING != 0) \
21952195
|| (WASM_ENABLE_MEMORY_TRACING != 0) */

core/shared/mem-alloc/ems/ems_kfc.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ gc_init_with_pool(char *buf, gc_size_t buf_size)
7676
heap_max_size = (uint32)(buf_end - base_addr) & (uint32)~7;
7777

7878
#if WASM_ENABLE_MEMORY_TRACING != 0
79-
MEM_PROF_PRINTF("Heap created, total size: %u\n", buf_size);
80-
MEM_PROF_PRINTF(" heap struct size: %u\n", sizeof(gc_heap_t));
81-
MEM_PROF_PRINTF(" actual heap size: %u\n", heap_max_size);
82-
MEM_PROF_PRINTF(" padding bytes: %u\n",
83-
buf_size - sizeof(gc_heap_t) - heap_max_size);
79+
LOG_VERBOSE("Heap created, total size: %u", buf_size);
80+
LOG_VERBOSE(" heap struct size: %u", sizeof(gc_heap_t));
81+
LOG_VERBOSE(" actual heap size: %u", heap_max_size);
82+
LOG_VERBOSE(" padding bytes: %u",
83+
buf_size - sizeof(gc_heap_t) - heap_max_size);
8484
#endif
8585
return gc_init_internal(heap, base_addr, heap_max_size);
8686
}
@@ -119,11 +119,11 @@ gc_init_with_struct_and_pool(char *struct_buf, gc_size_t struct_buf_size,
119119
heap_max_size = (uint32)(pool_buf_end - base_addr) & (uint32)~7;
120120

121121
#if WASM_ENABLE_MEMORY_TRACING != 0
122-
MEM_PROF_PRINTF("Heap created, total size: %u\n",
123-
struct_buf_size + pool_buf_size);
124-
MEM_PROF_PRINTF(" heap struct size: %u\n", sizeof(gc_heap_t));
125-
MEM_PROF_PRINTF(" actual heap size: %u\n", heap_max_size);
126-
MEM_PROF_PRINTF(" padding bytes: %u\n", pool_buf_size - heap_max_size);
122+
LOG_VERBOSE("Heap created, total size: %u",
123+
struct_buf_size + pool_buf_size);
124+
LOG_VERBOSE(" heap struct size: %u", sizeof(gc_heap_t));
125+
LOG_VERBOSE(" actual heap size: %u", heap_max_size);
126+
LOG_VERBOSE(" padding bytes: %u", pool_buf_size - heap_max_size);
127127
#endif
128128
return gc_init_internal(heap, base_addr, heap_max_size);
129129
}

core/shared/utils/bh_log.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,6 @@ bh_log_proc_mem(const char *function, uint32 line);
8787

8888
#define LOG_PROC_MEM(...) bh_log_proc_mem(__FUNCTION__, __LINE__)
8989

90-
/*
91-
* MEM_PROF_PRINTF: output macro for memory profiling/tracing.
92-
* When WASM_MEM_PROFILING_USE_LOG is enabled, routes output through
93-
* LOG_VERBOSE (respects log level filtering, adds timestamps).
94-
* Otherwise, uses os_printf for direct output (original behavior).
95-
*/
96-
#if WASM_MEM_PROFILING_USE_LOG != 0
97-
#define MEM_PROF_PRINTF(...) LOG_VERBOSE(__VA_ARGS__)
98-
#else
99-
#define MEM_PROF_PRINTF(...) os_printf(__VA_ARGS__)
100-
#endif
101-
10290
#ifdef __cplusplus
10391
}
10492
#endif

core/shared/utils/uncommon/bh_read_file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ bh_read_file_to_buffer(const char *filename, uint32 *ret_size)
4848
return NULL;
4949
}
5050
#if WASM_ENABLE_MEMORY_TRACING != 0
51-
MEM_PROF_PRINTF("Read file, total size: %u\n", file_size);
51+
LOG_VERBOSE("Read file, total size: %u", file_size);
5252
#endif
5353

5454
read_size = _read(file, buffer, file_size);
@@ -99,7 +99,7 @@ bh_read_file_to_buffer(const char *filename, uint32 *ret_size)
9999
return NULL;
100100
}
101101
#if WASM_ENABLE_MEMORY_TRACING != 0
102-
MEM_PROF_PRINTF("Read file, total size: %u\n", file_size);
102+
LOG_VERBOSE("Read file, total size: %u", file_size);
103103
#endif
104104

105105
read_size = (uint32)read(file, buffer, file_size);

doc/build_wamr.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
7979
| [WAMR_BUILD_LOAD_CUSTOM_SECTION](#load-wasm-custom-sections) | loading custom sections |
8080
| [WAMR_BUILD_MEMORY64](#memory64-feature) | memory64 support |
8181
| [WAMR_BUILD_MEMORY_PROFILING](#memory-profiling-experiment) | memory profiling |
82-
| [WAMR_BUILD_MEM_PROFILING_USE_LOG](#memory-profiling-structured-logging) | memory profiling structured logging |
8382
| [WAMR_BUILD_MEMORY_TRACING](#memory-tracing) | memory tracing |
8483
| [WAMR_BUILD_MINI_LOADER](#wasm-mini-loader) :warning: :exclamation: | mini loader |
8584
| [WAMR_BUILD_MODULE_INST_CONTEXT](#module-instance-context-apis) | module instance context |
@@ -386,13 +385,6 @@ SIMDE (SIMD Everywhere) implements SIMD operations in fast interpreter mode.
386385
> [!NOTE]
387386
> When enabled, call `void wasm_runtime_dump_mem_consumption(wasm_exec_env_t exec_env)` to dump memory usage. Currently only module, module_instance, and exec_env memory are measured; other components such as `wasi-ctx`, `multi-module`, and `thread-manager` are not included. See [Memory usage estimation for a module](./memory_usage.md).
388387
389-
### **memory profiling structured logging**
390-
391-
- **WAMR_BUILD_MEM_PROFILING_USE_LOG**=1/0, default to off.
392-
393-
> [!NOTE]
394-
> When enabled, memory profiling and tracing output uses structured logging (`LOG_VERBOSE`) instead of `os_printf`. Output then respects the log verbose level set by `bh_log_set_verbose_level()` and includes timestamps.
395-
396388
### **memory tracing**
397389

398390
- **WAMR_BUILD_MEMORY_TRACING**=1/0, default to off.

0 commit comments

Comments
 (0)