def main(): parser = optparse.OptionParser( usage='usage: %prog [options] <binary> <orderfile>') parser.add_option('--target-arch', action='store', dest='arch', choices=['arm', 'arm64', 'x86', 'x86_64', 'x64', 'mips'], help='The target architecture for the binary.') parser.add_option( '--threshold', action='store', dest='threshold', default=20, type=int, 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 (binary_filename, orderfile_filename) = argv[1:] symbol_extractor.SetArchitecture(options.arch) symbol_infos = symbol_extractor.SymbolInfosFromBinary(binary_filename) if not _VerifySymbolOrder( [sym.strip() for sym in file(orderfile_filename)], symbol_infos, options.threshold): return 1
def main(): parser = optparse.OptionParser(usage= 'usage: %prog [options] <binary> <orderfile>') parser.add_option('--target-arch', action='store', dest='arch', choices=['arm', 'arm64', 'x86', 'x86_64', 'x64', 'mips'], help='The target architecture for the binary.') parser.add_option('--threshold', action='store', dest='threshold', default=1, 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 (binary_filename, orderfile_filename) = argv[1:] symbol_extractor.SetArchitecture(options.arch) obj_dir = cygprofile_utils.GetObjDir(binary_filename) symbol_to_sections_map = \ cyglog_to_orderfile.GetSymbolToSectionsMapFromObjectFiles(obj_dir) section_to_symbols_map = cygprofile_utils.InvertMapping( symbol_to_sections_map) symbols = patch_orderfile.GetSymbolsFromOrderfile(orderfile_filename, section_to_symbols_map) symbol_infos = symbol_extractor.SymbolInfosFromBinary(binary_filename) # Missing symbols is not an error since some of them can be eliminated through # inlining. (misordered_pairs_count, matched_symbols, _) = _CountMisorderedSymbols( symbols, symbol_infos) return (misordered_pairs_count > options.threshold) or (matched_symbols == 0)
def main(argv): parser = optparse.OptionParser(usage= 'usage: %prog [options] <unpatched_orderfile> <library>') parser.add_option('--target-arch', action='store', dest='arch', 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 orderfile_filename = argv[1] binary_filename = argv[2] symbol_extractor.SetArchitecture(options.arch) (offset_to_symbol_infos, name_to_symbol_infos) = _GroupSymbolInfosFromBinary( binary_filename) profiled_symbols = GetSymbolsFromOrderfile(orderfile_filename) expanded_symbols = _ExpandSymbols( profiled_symbols, name_to_symbol_infos, offset_to_symbol_infos) _PrintSymbolsWithPrefixes(expanded_symbols, sys.stdout) # The following is needed otherwise Gold only applies a partial sort. print '.text' # gets methods not in a section, such as assembly print '.text.*' # gets everything else return 0
def main(): parser = _CreateArgumentParser() args = parser.parse_args() if not args.target_arch: args.arch = cygprofile_utils.DetectArchitecture() symbol_extractor.SetArchitecture(args.target_arch) offsets = _ReadReachedOffsets(args.reached_offsets) assert offsets _WarnAboutDuplicates(offsets) processor = process_profiles.SymbolOffsetProcessor(args.native_library) ordered_symbols = processor.GetOrderedSymbols(offsets) if ordered_symbols is None: return 1 success = False temp_filename = None output_file = None try: (fd, temp_filename) = tempfile.mkstemp(dir=os.path.dirname(args.output)) output_file = os.fdopen(fd, 'w') output_file.write('\n'.join(ordered_symbols)) output_file.close() os.rename(temp_filename, args.output) temp_filename = None success = True finally: if output_file: output_file.close() if temp_filename: os.remove(temp_filename) return 0 if success else 1
def main(): parser = _CreateArgumentParser() options = parser.parse_args() if not options.target_arch: options.arch = cygprofile_utils.DetectArchitecture() symbol_extractor.SetArchitecture(options.target_arch) GeneratePatchedOrderfile(options.unpatched_orderfile, options.native_library, options.output_file) return 0
def main(argv): parser = optparse.OptionParser( usage='usage: %prog [options] <unpatched_orderfile> <library>') parser.add_option('--target-arch', action='store', dest='arch', 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 orderfile_filename = argv[1] binary_filename = argv[2] symbol_extractor.SetArchitecture(options.arch) (offset_to_symbol_infos, name_to_symbol_infos) = _GroupSymbolInfosFromBinary(binary_filename) obj_dir = cygprofile_utils.GetObjDir(binary_filename) raw_symbol_map = cyglog_to_orderfile.GetSymbolToSectionsMapFromObjectFiles( obj_dir) suffixed = _SectionsWithSuffixes(raw_symbol_map) symbol_to_sections_map = _CombineSectionListsByPrimaryName(raw_symbol_map) section_to_symbols_map = cygprofile_utils.InvertMapping( symbol_to_sections_map) profiled_sections = _StripSuffixes( GetSectionsFromOrderfile(orderfile_filename)) expanded_sections = _ExpandSections(profiled_sections, name_to_symbol_infos, offset_to_symbol_infos, section_to_symbols_map, symbol_to_sections_map, suffixed) # Make sure the anchor functions are located in the right place, here and # after everything else. # See the comment in //tools/cygprofile/lightweight_cyrprofile.cc. # The linker ignores sections it doesn't see, so this can stay for all builds. for prefix in _PREFIXES: print prefix + 'dummy_function_to_anchor_text' for section in expanded_sections: print section # The following is needed otherwise Gold only applies a partial sort. print '.text' # gets methods not in a section, such as assembly for prefix in _PREFIXES: print prefix + '*' # gets everything else for prefix in _PREFIXES: print prefix + 'dummy_function_at_the_end_of_text' return 0
def main(): parser = _CreateArgumentParser() args = parser.parse_args() assert bool(args.merged_cyglog) ^ bool(args.reached_offsets) if not args.target_arch: args.arch = cygprofile_utils.DetectArchitecture() symbol_extractor.SetArchitecture(args.target_arch) obj_dir = cygprofile_utils.GetObjDir(args.native_library) offsets = [] if args.merged_cyglog: log_file_lines = map(string.rstrip, open(args.merged_cyglog).readlines()) offsets = _ParseLogLines(log_file_lines) else: offsets = _ReadReachedOffsets(args.reached_offsets) assert offsets _WarnAboutDuplicates(offsets) generator = OffsetOrderfileGenerator( process_profiles.SymbolOffsetProcessor(args.native_library), ObjectFileProcessor(obj_dir)) ordered_sections = generator.GetOrderedSections(offsets) if ordered_sections is None: return 1 success = False temp_filename = None output_file = None try: (fd, temp_filename) = tempfile.mkstemp(dir=os.path.dirname(args.output)) output_file = os.fdopen(fd, 'w') output_file.write('\n'.join(ordered_sections)) output_file.close() os.rename(temp_filename, args.output) temp_filename = None success = True finally: if output_file: output_file.close() if temp_filename: os.remove(temp_filename) return 0 if success else 1
def main(): parser = optparse.OptionParser( usage= 'usage: %prog [options] <merged_cyglog> <library> <output_filename>') parser.add_option('--target-arch', action='store', dest='arch', 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 (log_filename, lib_filename, output_filename) = argv[1:] symbol_extractor.SetArchitecture(options.arch) obj_dir = os.path.abspath( os.path.join(os.path.dirname(lib_filename), '../obj')) log_file_lines = map(string.rstrip, open(log_filename).readlines()) offsets = _ParseLogLines(log_file_lines) _WarnAboutDuplicates(offsets) offset_to_symbol_infos = _GroupLibrarySymbolInfosByOffset(lib_filename) symbol_to_section_map = _GetSymbolToSectionMapFromObjectFiles(obj_dir) success = False temp_filename = None output_file = None try: (fd, temp_filename) = tempfile.mkstemp( dir=os.path.dirname(output_filename)) output_file = os.fdopen(fd, 'w') ok = _OutputOrderfile(offsets, offset_to_symbol_infos, symbol_to_section_map, output_file) output_file.close() os.rename(temp_filename, output_filename) temp_filename = None success = ok finally: if output_file: output_file.close() if temp_filename: os.remove(temp_filename) return 0 if success else 1
def main(): parser = CreateArgumentParser() args = parser.parse_args() assert bool(args.merged_cyglog) ^ bool(args.reached_offsets) if not args.target_arch: args.arch = cygprofile_utils.DetectArchitecture() symbol_extractor.SetArchitecture(args.target_arch) obj_dir = cygprofile_utils.GetObjDir(args.native_library) offsets = [] if args.merged_cyglog: log_file_lines = map(string.rstrip, open(args.merged_cyglog).readlines()) offsets = _ParseLogLines(log_file_lines) else: offsets = ReadReachedOffsets(args.reached_offsets) assert offsets _WarnAboutDuplicates(offsets) offset_to_symbol_infos = _GroupLibrarySymbolInfosByOffset( args.native_library) symbol_to_sections_map = GetSymbolToSectionsMapFromObjectFiles(obj_dir) success = False temp_filename = None output_file = None try: (fd, temp_filename) = tempfile.mkstemp(dir=os.path.dirname(args.output)) output_file = os.fdopen(fd, 'w') ok = _OutputOrderfile(offsets, offset_to_symbol_infos, symbol_to_sections_map, output_file) output_file.close() os.rename(temp_filename, args.output) temp_filename = None success = ok finally: if output_file: output_file.close() if temp_filename: os.remove(temp_filename) return 0 if success else 1
def CreateArgumentParser(): """Creates and returns the argument parser.""" parser = argparse.ArgumentParser() parser.add_argument( '--lightweight-instrumentation', action='store_true', default=False, help='Use the lightweight instrumentation path') parser.add_argument( '--buildbot', action='store_true', help='If true, the script expects to be run on a buildbot') parser.add_argument( '--verify', action='store_true', help='If true, the script only verifies the current orderfile') parser.add_argument('--target-arch', action='store', dest='arch', default=cygprofile_utils.DetectArchitecture(), choices=['arm', 'arm64', 'x86', 'x86_64', 'x64', 'mips'], help='The target architecture for which to build') parser.add_argument('--output-json', action='store', dest='json_file', help='Location to save stats in json format') parser.add_argument( '--skip-profile', action='store_false', dest='profile', default=True, help='Don\'t generate a profile on the device. Only patch from the ' 'existing profile.') parser.add_argument( '--skip-patch', action='store_false', dest='patch', default=True, help='Only generate the raw (unpatched) orderfile, don\'t patch it.') parser.add_argument( '--netrc', action='store', help='A custom .netrc file to use for git checkin. Only used on bots.') parser.add_argument( '--branch', action='store', default='master', help='When running on buildbot with a netrc, the branch orderfile ' 'hashes get checked into.') # Note: -j50 was causing issues on the bot. parser.add_argument( '-j', '--jobs', action='store', default=20, help='Number of jobs to use for compilation.') parser.add_argument( '-l', '--max-load', action='store', default=4, help='Max cpu load.') parser.add_argument('--goma-dir', help='GOMA directory.') parser.add_argument( '--use-goma', action='store_true', help='Enable GOMA.', default=False) parser.add_argument('--adb-path', help='Path to the adb binary.') profile_android_startup.AddProfileCollectionArguments(parser) return parser
def CreateArgumentParser(): """Creates and returns the argument parser.""" parser = argparse.ArgumentParser() parser.add_argument( '--buildbot', action='store_true', help='If true, the script expects to be run on a buildbot') parser.add_argument('--device', default=None, type=str, help='Device serial number on which to run profiling.') parser.add_argument( '--verify', action='store_true', help='If true, the script only verifies the current orderfile') parser.add_argument( '--target-arch', action='store', dest='arch', default=cygprofile_utils.DetectArchitecture(), choices=['arm', 'arm64', 'x86', 'x86_64', 'x64', 'mips'], help='The target architecture for which to build') parser.add_argument('--output-json', action='store', dest='json_file', help='Location to save stats in json format') parser.add_argument( '--skip-profile', action='store_false', dest='profile', default=True, help='Don\'t generate a profile on the device. Only patch from the ' 'existing profile.') parser.add_argument( '--skip-patch', action='store_false', dest='patch', default=True, help='Only generate the raw (unpatched) orderfile, don\'t patch it.') parser.add_argument( '--netrc', action='store', help='A custom .netrc file to use for git checkin. Only used on bots.') parser.add_argument( '--branch', action='store', default='master', help='When running on buildbot with a netrc, the branch orderfile ' 'hashes get checked into.') # Note: -j50 was causing issues on the bot. parser.add_argument('-j', '--jobs', action='store', default=20, help='Number of jobs to use for compilation.') parser.add_argument('-l', '--max-load', action='store', default=4, help='Max cpu load.') parser.add_argument('--goma-dir', help='GOMA directory.') parser.add_argument('--use-goma', action='store_true', help='Enable GOMA.', default=False) parser.add_argument('--adb-path', help='Path to the adb binary.') parser.add_argument( '--manual-symbol-offsets', default=None, type=str, help=('File of list of ordered symbol offsets generated ' 'by manual profiling. Must set other --manual* ' 'flags if this is used, and must --skip-profile.')) parser.add_argument('--manual-libname', default=None, type=str, help=('Library filename corresponding to ' '--manual-symbol-offsets.')) parser.add_argument('--manual-objdir', default=None, type=str, help=('Root of object file directory corresponding to ' '--manual-symbol-offsets.')) profile_android_startup.AddProfileCollectionArguments(parser) return parser