diff options
author | azarchs <azarchs@chromium.org> | 2015-04-20 07:15:07 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-20 14:15:18 +0000 |
commit | d0e47edfd7d4ed8dbd6ac2845a34005c7d6df778 (patch) | |
tree | d56c1111f9fbc195ea3adf6edd766d0513d9a584 /tools/cygprofile | |
parent | bd0499db39fd01fff985ad3d39b1919d9c64b6e6 (diff) | |
download | chromium_src-d0e47edfd7d4ed8dbd6ac2845a34005c7d6df778.zip chromium_src-d0e47edfd7d4ed8dbd6ac2845a34005c7d6df778.tar.gz chromium_src-d0e47edfd7d4ed8dbd6ac2845a34005c7d6df778.tar.bz2 |
Cygprofile scripts can detect target_arch from GYP_DEFINES.
Also create file for shared code.
Review URL: https://codereview.chromium.org/1092783005
Cr-Commit-Position: refs/heads/master@{#325840}
Diffstat (limited to 'tools/cygprofile')
-rwxr-xr-x | tools/cygprofile/check_orderfile.py | 4 | ||||
-rwxr-xr-x | tools/cygprofile/cyglog_to_orderfile.py | 27 | ||||
-rwxr-xr-x | tools/cygprofile/cygprofile_utils.py | 42 | ||||
-rwxr-xr-x | tools/cygprofile/patch_orderfile.py | 4 | ||||
-rwxr-xr-x | tools/cygprofile/symbol_extractor.py | 18 |
5 files changed, 62 insertions, 33 deletions
diff --git a/tools/cygprofile/check_orderfile.py b/tools/cygprofile/check_orderfile.py index 5dc68ed..4202f7f 100755 --- a/tools/cygprofile/check_orderfile.py +++ b/tools/cygprofile/check_orderfile.py @@ -10,6 +10,7 @@ import logging import optparse import sys +import cygprofile_utils import patch_orderfile import symbol_extractor @@ -63,12 +64,13 @@ def main(): parser = optparse.OptionParser(usage= 'usage: %prog [options] <binary> <orderfile>') parser.add_option('--target-arch', action='store', dest='arch', - default='arm', choices=['arm', 'arm64', 'x86', 'x86_64', 'x64', 'mips'], help='The target architecture for the binary.') parser.add_option('--threshold', action='store', dest='threshold', default=0, help='The maximum allowed number of out-of-order symbols.') options, argv = parser.parse_args(sys.argv) + if not options.arch: + options.arch = cygprofile_utils.DetectArchitecture() if len(argv) != 3: parser.print_help() return 1 diff --git a/tools/cygprofile/cyglog_to_orderfile.py b/tools/cygprofile/cyglog_to_orderfile.py index e81dac1..f64c077 100755 --- a/tools/cygprofile/cyglog_to_orderfile.py +++ b/tools/cygprofile/cyglog_to_orderfile.py @@ -16,6 +16,7 @@ import tempfile import string import sys +import cygprofile_utils import symbol_extractor @@ -101,23 +102,6 @@ def _FindSymbolInfosAtOffset(offset_to_symbol_infos, offset): raise SymbolNotFoundException(offset) -class WarningCollector(object): - """Collect warnings, but limit the number printed to a set value.""" - def __init__(self, max_warnings): - self._warnings = 0 - self._max_warnings = max_warnings - - def Write(self, message): - if self._warnings < self._max_warnings: - logging.warning(message) - self._warnings += 1 - - def WriteEnd(self, message): - if self._warnings > self._max_warnings: - logging.warning('%d more warnings for: %s' % ( - self._warnings - self._max_warnings, message)) - - def _GetObjectFileNames(obj_dir): """Returns the list of object files in a directory.""" obj_files = [] @@ -147,7 +131,7 @@ def _GetSymbolToSectionMapFromObjectFiles(obj_dir): """ object_files = _GetObjectFileNames(obj_dir) symbol_to_section_map = {} - symbol_warnings = WarningCollector(300) + symbol_warnings = cygprofile_utils.WarningCollector(300) symbol_infos = _AllSymbolInfos(object_files) for symbol_info in symbol_infos: symbol = symbol_info.name @@ -199,8 +183,8 @@ def _OutputOrderfile(offsets, offset_to_symbol_infos, symbol_to_section_map, output_file: file-like object to write the results to """ success = True - unknown_symbol_warnings = WarningCollector(300) - symbol_not_found_warnings = WarningCollector(300) + unknown_symbol_warnings = cygprofile_utils.WarningCollector(300) + symbol_not_found_warnings = cygprofile_utils.WarningCollector(300) output_sections = set() for offset in offsets: try: @@ -227,10 +211,11 @@ def main(): parser = optparse.OptionParser(usage= 'usage: %prog [options] <merged_cyglog> <library> <output_filename>') parser.add_option('--target-arch', action='store', dest='arch', - default='arm', choices=['arm', 'arm64', 'x86', 'x86_64', 'x64', 'mips'], help='The target architecture for libchrome.so') options, argv = parser.parse_args(sys.argv) + if not options.arch: + options.arch = cygprofile_utils.DetectArchitecture() if len(argv) != 4: parser.print_help() return 1 diff --git a/tools/cygprofile/cygprofile_utils.py b/tools/cygprofile/cygprofile_utils.py new file mode 100755 index 0000000..866b352 --- /dev/null +++ b/tools/cygprofile/cygprofile_utils.py @@ -0,0 +1,42 @@ +#!/usr/bin/python +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Common utilites used by cygprofile scripts. +""" + +import logging +import os +import re + +class WarningCollector(object): + """Collects warnings, but limits the number printed to a set value.""" + def __init__(self, max_warnings): + self._warnings = 0 + self._max_warnings = max_warnings + + def Write(self, message): + """Print a warning if fewer than max_warnings have already been printed.""" + if self._warnings < self._max_warnings: + logging.warning(message) + self._warnings += 1 + + def WriteEnd(self, message): + """Once all warnings have been printed, use this to print the number of + elided warnings.""" + if self._warnings > self._max_warnings: + logging.warning('%d more warnings for: %s' % ( + self._warnings - self._max_warnings, message)) + + +def DetectArchitecture(default='arm'): + """Detects the architecture by looking for target_arch in GYP_DEFINES. + If not not found, returns default. + """ + gyp_defines = os.environ.get('GYP_DEFINES', '') + match = re.match('target_arch=(\S+)', gyp_defines) + if match and len(match.groups()) == 1: + return match.group(1) + else: + return default diff --git a/tools/cygprofile/patch_orderfile.py b/tools/cygprofile/patch_orderfile.py index 88abc62..7906804 100755 --- a/tools/cygprofile/patch_orderfile.py +++ b/tools/cygprofile/patch_orderfile.py @@ -29,6 +29,7 @@ import logging import optparse import sys +import cygprofile_utils import symbol_extractor # Prefixes for the symbols. We strip them from the incoming symbols, and add @@ -208,10 +209,11 @@ def main(argv): parser = optparse.OptionParser(usage= 'usage: %prog [options] <unpatched_orderfile> <library>') parser.add_option('--target-arch', action='store', dest='arch', - default='arm', choices=['arm', 'arm64', 'x86', 'x86_64', 'x64', 'mips'], help='The target architecture for the library.') options, argv = parser.parse_args(argv) + if not options.arch: + options.arch = cygprofile_utils.DetectArchitecture() if len(argv) != 3: parser.print_help() return 1 diff --git a/tools/cygprofile/symbol_extractor.py b/tools/cygprofile/symbol_extractor.py index dbd625b..f28efd0 100755 --- a/tools/cygprofile/symbol_extractor.py +++ b/tools/cygprofile/symbol_extractor.py @@ -12,6 +12,8 @@ import re import subprocess import sys +import cygprofile_utils + sys.path.insert( 0, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'third_party', 'android_platform', 'development', @@ -137,18 +139,14 @@ def CreateNameToSymbolInfo(symbol_infos): """ #TODO(azarchs): move the functionality in this method into check_orderfile. symbol_infos_by_name = {} - collision_count = 0 + warnings = cygprofile_utils.WarningCollector(_MAX_WARNINGS_TO_PRINT) for infos in GroupSymbolInfosByName(symbol_infos).itervalues(): first_symbol_info = min(infos, key=lambda x:x.offset) symbol_infos_by_name[first_symbol_info.name] = first_symbol_info if len(infos) > 1: - collision_count += 1 - if collision_count <= _MAX_WARNINGS_TO_PRINT: - logging.warning('Symbol %s appears at %d offsets: %s' % - (first_symbol_info.name, - len(infos), - ','.join([hex(x.offset) for x in infos]))) - if collision_count > _MAX_WARNINGS_TO_PRINT: - logging.warning('%d symbols at multiple offsets. First %d shown.' % - (collision_count, _MAX_WARNINGS_TO_PRINT)) + warnings.Write('Symbol %s appears at %d offsets: %s' % + (first_symbol_info.name, + len(infos), + ','.join([hex(x.offset) for x in infos]))) + warnings.WriteEnd('symbols at multiple offsets.') return symbol_infos_by_name |