Skip to content

Commit d94e837

Browse files
authored
When profiling functions just use the function name. NFC (#16012)
1 parent 39fb93e commit d94e837

File tree

7 files changed

+29
-15
lines changed

7 files changed

+29
-15
lines changed

emcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3916,7 +3916,7 @@ def is_int(s):
39163916
return False
39173917

39183918

3919-
@ToolchainProfiler.profile_block('main')
3919+
@ToolchainProfiler.profile()
39203920
def main(args):
39213921
start_time = time.time()
39223922
ret = run(args)

emscripten.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ def remove_trailing_zeros(memfile):
391391
utils.write_binary(memfile, mem_data[:end])
392392

393393

394+
@ToolchainProfiler.profile()
394395
def get_metadata_binaryen(infile, outfile, modify_wasm, args):
395396
stdout = building.run_binaryen_command('wasm-emscripten-finalize',
396397
infile=infile,
@@ -401,6 +402,7 @@ def get_metadata_binaryen(infile, outfile, modify_wasm, args):
401402
return metadata
402403

403404

405+
@ToolchainProfiler.profile()
404406
def get_metadata_python(infile, outfile, modify_wasm, args):
405407
metadata = extract_metadata.extract_metadata(infile)
406408
if modify_wasm:
@@ -911,7 +913,7 @@ def generate_struct_info():
911913
if settings.BOOTSTRAPPING_STRUCT_INFO:
912914
return
913915

914-
@ToolchainProfiler.profile_block('gen_struct_info')
916+
@ToolchainProfiler.profile()
915917
def generate_struct_info(out):
916918
gen_struct_info.main(['-q', '-o', out])
917919

tools/building.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def make_paths_absolute(f):
178178
# Runs llvm-nm for the given list of files.
179179
# The results are populated in nm_cache, and also returned as an array with order corresponding with the input files.
180180
# If a given file cannot be processed, None will be present in its place.
181-
@ToolchainProfiler.profile_block('llvm_nm_multiple')
181+
@ToolchainProfiler.profile()
182182
def llvm_nm_multiple(files):
183183
if len(files) == 0:
184184
return []
@@ -202,7 +202,7 @@ def llvm_nm(file):
202202
return llvm_nm_multiple([file])[0]
203203

204204

205-
@ToolchainProfiler.profile_block('read_link_inputs')
205+
@ToolchainProfiler.profile()
206206
def read_link_inputs(files):
207207
# Before performing the link, we need to look at each input file to determine which symbols
208208
# each of them provides. Do this in multiple parallel processes.
@@ -259,7 +259,7 @@ def llvm_backend_args():
259259
return args
260260

261261

262-
@ToolchainProfiler.profile_block('linking to object file')
262+
@ToolchainProfiler.profile()
263263
def link_to_object(args, target):
264264
# link using lld unless LTO is requested (lld can't output LTO/bitcode object files).
265265
if not settings.LTO:
@@ -741,7 +741,7 @@ def add_to_path(dirname):
741741
return closure_cmd, env
742742

743743

744-
@ToolchainProfiler.profile_block('closure_transpile')
744+
@ToolchainProfiler.profile()
745745
def closure_transpile(filename, pretty):
746746
user_args = []
747747
closure_cmd, env = get_closure_compiler_and_env(user_args)
@@ -750,7 +750,7 @@ def closure_transpile(filename, pretty):
750750
return run_closure_cmd(closure_cmd, filename, env, pretty)
751751

752752

753-
@ToolchainProfiler.profile_block('closure_compiler')
753+
@ToolchainProfiler.profile()
754754
def closure_compiler(filename, pretty, advanced=True, extra_closure_args=None):
755755
user_args = []
756756
env_args = os.environ.get('EMCC_CLOSURE_ARGS')

tools/js_optimizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def serialize(self):
122122

123123
# Given a set of functions of form (ident, text), and a preferred chunk size,
124124
# generates a set of chunks for parallel processing and caching.
125-
@ToolchainProfiler.profile_block('chunkify')
125+
@ToolchainProfiler.profile()
126126
def chunkify(funcs, chunk_size):
127127
chunks = []
128128
# initialize reasonably, the rest of the funcs we need to split out

tools/shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def perform_sanity_checks():
361361
exit_with_error('Cannot find %s, check the paths in %s', cmd, config.EM_CONFIG)
362362

363363

364-
@ToolchainProfiler.profile_block('sanity')
364+
@ToolchainProfiler.profile()
365365
def check_sanity(force=False):
366366
"""Check that basic stuff we need (a JS engine to compile, Node.js, and Clang
367367
and LLVM) exists.

tools/system_libs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,6 @@ def install_system_headers(stamp):
18661866
return stamp
18671867

18681868

1869-
@ToolchainProfiler.profile_block('ensure_sysroot')
1869+
@ToolchainProfiler.profile()
18701870
def ensure_sysroot():
18711871
shared.Cache.get('sysroot_install.stamp', install_system_headers, what='system headers')

tools/toolchain_profiler.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class Logger(ContextDecorator):
2525
def __init__(self, name):
2626
self.name = name
2727

28+
def __call__(self, func):
29+
if self.name is None:
30+
self.name = func.__name__
31+
return super().__call__(func)
32+
2833
def __enter__(self):
2934
if EMPROFILE == 2:
3035
indentation = ' ' * Logger.depth
@@ -37,9 +42,9 @@ def __exit__(self, exc_type, value, traceback):
3742
now = time.time()
3843
duration = now - self.start
3944
if exc_type:
40-
msg = 'block "%s" raised an exception after %.2f seconds'
45+
msg = 'block "%s" raised an exception after %.3f seconds'
4146
else:
42-
msg = 'block "%s" took %.2f seconds'
47+
msg = 'block "%s" took %.3f seconds'
4348
if EMPROFILE == 2:
4449
Logger.depth -= 1
4550
indentation = ' ' * Logger.depth
@@ -232,18 +237,22 @@ def exit_all_blocks():
232237
class ProfileBlock(Logger):
233238
def __init__(self, block_name):
234239
super().__init__(block_name)
235-
self.block_name = block_name
240+
self.name = block_name
236241

237242
def __enter__(self):
238-
ToolchainProfiler.enter_block(self.block_name)
243+
ToolchainProfiler.enter_block(self.name)
239244

240245
def __exit__(self, type, value, traceback):
241-
ToolchainProfiler.exit_block(self.block_name)
246+
ToolchainProfiler.exit_block(self.name)
242247

243248
@staticmethod
244249
def profile_block(block_name):
245250
return ToolchainProfiler.ProfileBlock(ToolchainProfiler.escape_string(block_name))
246251

252+
@staticmethod
253+
def profile():
254+
return ToolchainProfiler.ProfileBlock(None)
255+
247256
@staticmethod
248257
def imaginary_pid():
249258
ToolchainProfiler.imaginary_pid_ -= 1
@@ -263,3 +272,6 @@ def exit_block(block_name):
263272
@staticmethod
264273
def profile_block(block_name):
265274
return Logger(block_name)
275+
276+
def profile():
277+
return Logger(None)

0 commit comments

Comments
 (0)