Skip to content

Commit da8c8f8

Browse files
Add more detailed profiling blocks and more granularity. NFC (#18145)
1 parent 9cfb7cf commit da8c8f8

File tree

1 file changed

+38
-26
lines changed

1 file changed

+38
-26
lines changed

emcc.py

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3536,42 +3536,48 @@ def phase_binaryen(target, options, wasm_target):
35363536
dwarf_info = settings.DEBUG_LEVEL >= 3
35373537
if dwarf_info:
35383538
diagnostics.warning('limited-postlink-optimizations', 'running limited binaryen optimizations because DWARF info requested (or indirectly required)')
3539-
building.run_wasm_opt(wasm_target,
3540-
wasm_target,
3541-
args=passes,
3542-
debug=intermediate_debug_info)
3543-
building.save_intermediate(wasm_target, 'byn.wasm')
3539+
with ToolchainProfiler.profile_block('wasm_opt'):
3540+
building.run_wasm_opt(wasm_target,
3541+
wasm_target,
3542+
args=passes,
3543+
debug=intermediate_debug_info)
3544+
building.save_intermediate(wasm_target, 'byn.wasm')
35443545
elif strip_debug or strip_producers:
35453546
# we are not running wasm-opt. if we need to strip certain sections
35463547
# then do so using llvm-objcopy which is fast and does not rewrite the
35473548
# code (which is better for debug info)
35483549
sections = ['producers'] if strip_producers else []
3549-
building.strip(wasm_target, wasm_target, debug=strip_debug, sections=sections)
3550-
building.save_intermediate(wasm_target, 'strip.wasm')
3550+
with ToolchainProfiler.profile_block('strip_producers'):
3551+
building.strip(wasm_target, wasm_target, debug=strip_debug, sections=sections)
3552+
building.save_intermediate(wasm_target, 'strip.wasm')
35513553

35523554
if settings.EVAL_CTORS:
3553-
building.eval_ctors(final_js, wasm_target, debug_info=intermediate_debug_info)
3554-
building.save_intermediate(wasm_target, 'ctors.wasm')
3555+
with ToolchainProfiler.profile_block('eval_ctors'):
3556+
building.eval_ctors(final_js, wasm_target, debug_info=intermediate_debug_info)
3557+
building.save_intermediate(wasm_target, 'ctors.wasm')
35553558

35563559
# after generating the wasm, do some final operations
35573560

35583561
if final_js:
35593562
if settings.SUPPORT_BIG_ENDIAN:
3560-
final_js = building.little_endian_heap(final_js)
3563+
with ToolchainProfiler.profile_block('little_endian_heap'):
3564+
final_js = building.little_endian_heap(final_js)
35613565

35623566
# >=2GB heap support requires pointers in JS to be unsigned. rather than
35633567
# require all pointers to be unsigned by default, which increases code size
35643568
# a little, keep them signed, and just unsign them here if we need that.
35653569
if settings.CAN_ADDRESS_2GB:
3566-
final_js = building.use_unsigned_pointers_in_js(final_js)
3570+
with ToolchainProfiler.profile_block('use_unsigned_pointers_in_js'):
3571+
final_js = building.use_unsigned_pointers_in_js(final_js)
35673572

35683573
# pthreads memory growth requires some additional JS fixups.
35693574
# note that we must do this after handling of unsigned pointers. unsigning
35703575
# adds some >>> 0 things, while growth will replace a HEAP8 with a call to
35713576
# a method to get the heap, and that call would not be recognized by the
35723577
# unsigning pass
35733578
if settings.USE_PTHREADS and settings.ALLOW_MEMORY_GROWTH:
3574-
final_js = building.apply_wasm_memory_growth(final_js)
3579+
with ToolchainProfiler.profile_block('apply_wasm_memory_growth'):
3580+
final_js = building.apply_wasm_memory_growth(final_js)
35753581

35763582
if settings.USE_ASAN:
35773583
final_js = building.instrument_js_for_asan(final_js)
@@ -3583,26 +3589,30 @@ def phase_binaryen(target, options, wasm_target):
35833589
# minify the JS. Do not minify whitespace if Closure is used, so that
35843590
# Closure can print out readable error messages (Closure will then
35853591
# minify whitespace afterwards)
3586-
save_intermediate_with_wasm('preclean', wasm_target)
3587-
final_js = building.minify_wasm_js(js_file=final_js,
3588-
wasm_file=wasm_target,
3589-
expensive_optimizations=will_metadce(),
3590-
minify_whitespace=minify_whitespace() and not options.use_closure_compiler,
3591-
debug_info=intermediate_debug_info)
3592-
save_intermediate_with_wasm('postclean', wasm_target)
3592+
with ToolchainProfiler.profile_block('minify_wasm'):
3593+
save_intermediate_with_wasm('preclean', wasm_target)
3594+
final_js = building.minify_wasm_js(js_file=final_js,
3595+
wasm_file=wasm_target,
3596+
expensive_optimizations=will_metadce(),
3597+
minify_whitespace=minify_whitespace() and not options.use_closure_compiler,
3598+
debug_info=intermediate_debug_info)
3599+
save_intermediate_with_wasm('postclean', wasm_target)
35933600

35943601
if settings.ASYNCIFY_LAZY_LOAD_CODE:
3595-
building.asyncify_lazy_load_code(wasm_target, debug=intermediate_debug_info)
3602+
with ToolchainProfiler.profile_block('asyncify_lazy_load_code'):
3603+
building.asyncify_lazy_load_code(wasm_target, debug=intermediate_debug_info)
35963604

35973605
def preprocess_wasm2js_script():
35983606
return read_and_preprocess(utils.path_from_root('src/wasm2js.js'), expand_macros=True)
35993607

36003608
if final_js and (options.use_closure_compiler or settings.TRANSPILE_TO_ES5):
36013609
if options.use_closure_compiler:
3602-
final_js = building.closure_compiler(final_js, pretty=not minify_whitespace(),
3603-
extra_closure_args=options.closure_args)
3610+
with ToolchainProfiler.profile_block('closure_compile'):
3611+
final_js = building.closure_compiler(final_js, pretty=not minify_whitespace(),
3612+
extra_closure_args=options.closure_args)
36043613
else:
3605-
final_js = building.closure_transpile(final_js, pretty=not minify_whitespace())
3614+
with ToolchainProfiler.profile_block('closure_transpile'):
3615+
final_js = building.closure_transpile(final_js, pretty=not minify_whitespace())
36063616
save_intermediate_with_wasm('closure', wasm_target)
36073617

36083618
symbols_file = None
@@ -3650,8 +3660,9 @@ def preprocess_wasm2js_script():
36503660
if options.emit_symbol_map:
36513661
intermediate_debug_info -= 1
36523662
if os.path.exists(wasm_target):
3653-
building.handle_final_wasm_symbols(wasm_file=wasm_target, symbols_file=symbols_file, debug_info=intermediate_debug_info)
3654-
save_intermediate_with_wasm('symbolmap', wasm_target)
3663+
with ToolchainProfiler.profile_block('handle_final_symbols'):
3664+
building.handle_final_wasm_symbols(wasm_file=wasm_target, symbols_file=symbols_file, debug_info=intermediate_debug_info)
3665+
save_intermediate_with_wasm('symbolmap', wasm_target)
36553666

36563667
if settings.DEBUG_LEVEL >= 3 and settings.SEPARATE_DWARF and os.path.exists(wasm_target):
36573668
building.emit_debug_on_side(wasm_target)
@@ -3667,7 +3678,8 @@ def preprocess_wasm2js_script():
36673678
# strip debug info if it was not already stripped by the last command
36683679
if not debug_info and building.binaryen_kept_debug_info and \
36693680
building.os.path.exists(wasm_target):
3670-
building.run_wasm_opt(wasm_target, wasm_target)
3681+
with ToolchainProfiler.profile_block('strip_with_wasm_opt'):
3682+
building.run_wasm_opt(wasm_target, wasm_target)
36713683

36723684
# replace placeholder strings with correct subresource locations
36733685
if final_js and settings.SINGLE_FILE and not settings.WASM2JS:

0 commit comments

Comments
 (0)