Index: tools/binary_size/run_binary_size_analysis.py |
diff --git a/tools/binary_size/run_binary_size_analysis.py b/tools/binary_size/run_binary_size_analysis.py |
index f06884f8dafe1f7ba54c8586d18882c0e0ec5227..21a5eef1dc0f39b4fc998b40678cfd78aad49d94 100755 |
--- a/tools/binary_size/run_binary_size_analysis.py |
+++ b/tools/binary_size/run_binary_size_analysis.py |
@@ -161,25 +161,32 @@ def AddSymbolIntoFileNode(node, symbol_type, symbol_name, symbol_size): |
return 2 # Depth of the added subtree. |
-def MakeCompactTree(symbols): |
+def MakeCompactTree(symbols, symbol_path_origin_dir): |
result = {NODE_NAME_KEY: '/', |
NODE_CHILDREN_KEY: {}, |
NODE_TYPE_KEY: 'p', |
NODE_MAX_DEPTH_KEY: 0} |
seen_symbol_with_path = False |
+ cwd = os.path.abspath(os.getcwd()) |
for symbol_name, symbol_type, symbol_size, file_path in symbols: |
if 'vtable for ' in symbol_name: |
symbol_type = '@' # hack to categorize these separately |
# Take path like '/foo/bar/baz', convert to ['foo', 'bar', 'baz'] |
- if file_path: |
- file_path = os.path.normpath(file_path) |
+ if file_path and file_path != "??": |
+ file_path = os.path.abspath(os.path.join(symbol_path_origin_dir, |
+ file_path)) |
+ # Let the output structure be relative to $CWD if inside $CWD, |
+ # otherwise relative to the disk root. This is to avoid |
+ # unnecessary click-through levels in the output. |
+ if file_path.startswith(cwd + os.sep): |
+ file_path = file_path[len(cwd):] |
+ if file_path.startswith('/'): |
+ file_path = file_path[1:] |
seen_symbol_with_path = True |
else: |
file_path = NAME_NO_PATH_BUCKET |
- if file_path.startswith('/'): |
- file_path = file_path[1:] |
path_parts = file_path.split('/') |
# Find pre-existing node in tree, or update if it already exists |
@@ -346,11 +353,12 @@ def JsonifyTree(tree, name): |
'data': { '$area': tree['size'] }, |
'children': children } |
-def DumpCompactTree(symbols, outfile): |
- tree_root = MakeCompactTree(symbols) |
+def DumpCompactTree(symbols, symbol_path_origin_dir, outfile): |
+ tree_root = MakeCompactTree(symbols, symbol_path_origin_dir) |
with open(outfile, 'w') as out: |
- out.write('var tree_data = ') |
- json.dump(tree_root, out) |
+ out.write('var tree_data=') |
+ # Use separators without whitespace to get a smaller file. |
+ json.dump(tree_root, out, separators=(',', ':')) |
print('Writing %d bytes json' % os.path.getsize(outfile)) |
@@ -499,6 +507,9 @@ def RunElfSymbolizer(outfile, library, addr2line_binary, nm_binary, jobs): |
else: |
address_symbol[addr] = symbol |
+ progress_output() |
+ |
+ def progress_output(): |
progress_chunk = 100 |
if progress.count % progress_chunk == 0: |
time_now = time.time() |
@@ -556,6 +567,8 @@ def RunElfSymbolizer(outfile, library, addr2line_binary, nm_binary, jobs): |
print('Skipping the rest of the file mapping. ' |
'Output will not be fully classified.') |
+ symbol_path_origin_dir = os.path.dirname(os.path.abspath(library)) |
+ |
with open(outfile, 'w') as out: |
for line in nm_output_lines: |
match = sNmPattern.match(line) |
@@ -567,7 +580,8 @@ def RunElfSymbolizer(outfile, library, addr2line_binary, nm_binary, jobs): |
if symbol is not None: |
path = '??' |
if symbol.source_path is not None: |
- path = symbol.source_path |
+ path = os.path.abspath(os.path.join(symbol_path_origin_dir, |
+ symbol.source_path)) |
line_number = 0 |
if symbol.source_line is not None: |
line_number = symbol.source_line |
@@ -779,7 +793,13 @@ def main(): |
shutil.copy(os.path.join('tools', 'binary_size', 'legacy_template', |
'index.html'), opts.destdir) |
else: # modern report |
- DumpCompactTree(symbols, os.path.join(opts.destdir, 'data.js')) |
+ if opts.library: |
+ symbol_path_origin_dir = os.path.dirname(os.path.abspath(opts.library)) |
+ else: |
+ # Just a guess. Hopefully all paths in the input file are absolute. |
+ symbol_path_origin_dir = os.path.abspath(os.getcwd()) |
+ data_js_file_name = os.path.join(opts.destdir, 'data.js') |
+ DumpCompactTree(symbols, symbol_path_origin_dir, data_js_file_name) |
d3_out = os.path.join(opts.destdir, 'd3') |
if not os.path.exists(d3_out): |
os.makedirs(d3_out, 0755) |