diff options
author | bratell@opera.com <bratell@opera.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-24 18:26:36 +0000 |
---|---|---|
committer | bratell@opera.com <bratell@opera.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-24 18:26:36 +0000 |
commit | df6b3fbf686b552f699b44a2f951e131ef4c5771 (patch) | |
tree | 1294355aa24bfc0fbf7adb636d7b5b5f3e64e33b | |
parent | 9aba8f857fe286bb60d9e4b9d1eec659d55c7805 (diff) | |
download | chromium_src-df6b3fbf686b552f699b44a2f951e131ef4c5771.zip chromium_src-df6b3fbf686b552f699b44a2f951e131ef4c5771.tar.gz chromium_src-df6b3fbf686b552f699b44a2f951e131ef4c5771.tar.bz2 |
binary_size: Easier-to-read output
It's easy to have to have to click a few levels down (in my case down
into / -> home -> bratell -> src -> chromium -> src). Remove the part
that seems to be an unnecessary prefix by assuming that everything
above cwd is not interesting.
Review URL: https://codereview.chromium.org/303453003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279448 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | tools/binary_size/run_binary_size_analysis.py | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/tools/binary_size/run_binary_size_analysis.py b/tools/binary_size/run_binary_size_analysis.py index f06884f..21a5eef 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) |