def _CollectLegacyProfile(self): files = [] try: files = self._profiler.CollectProfile( self._compiler.chrome_apk, constants.PACKAGE_INFO['chrome']) self._MaybeSaveProfile(files) self._step_recorder.BeginStep('Process profile') assert os.path.exists(self._compiler.lib_chrome_so) offsets = process_profiles.GetReachedOffsetsFromDumpFiles( files, self._compiler.lib_chrome_so) if not offsets: raise Exception('No profiler offsets found in {}'.format( '\n'.join(files))) processor = process_profiles.SymbolOffsetProcessor( self._compiler.lib_chrome_so) ordered_symbols = processor.GetOrderedSymbols(offsets) if not ordered_symbols: raise Exception('No symbol names from offsets found in {}'.format( '\n'.join(files))) with open(self._GetUnpatchedOrderfileFilename(), 'w') as orderfile: orderfile.write('\n'.join(ordered_symbols)) except Exception: for f in files: self._SaveForDebugging(f) raise finally: self._profiler.Cleanup()
def _GenerateAndProcessProfile(self): """Invokes a script to merge the per-thread traces into one file.""" self._step_recorder.BeginStep('Generate Profile Data') files = [] try: logging.getLogger().setLevel(logging.DEBUG) files = self._profiler.CollectProfile( self._compiler.chrome_apk, constants.PACKAGE_INFO['chrome']) self._step_recorder.BeginStep('Process cyglog') if self._options.lightweight_instrumentation: assert os.path.exists(self._compiler.lib_chrome_so) offsets = process_profiles.GetReachedOffsetsFromDumpFiles( files, self._compiler.lib_chrome_so) if not offsets: raise Exception('No profiler offsets found in {}'.format( '\n'.join(files))) with open(self._MERGED_CYGLOG_FILENAME, 'w') as f: f.write('\n'.join(map(str, offsets))) else: with open(self._MERGED_CYGLOG_FILENAME, 'w') as merged_cyglog: self._step_recorder.RunCommand( [self._MERGE_TRACES_SCRIPT] + files, constants.DIR_SOURCE_ROOT, stdout=merged_cyglog) except Exception: for f in files: self._SaveForDebugging(f) raise finally: self._profiler.Cleanup() logging.getLogger().setLevel(logging.INFO) try: command_args = [ '--target-arch=' + self._options.arch, '--native-library=' + self._compiler.lib_chrome_so, '--output=' + self._GetUnpatchedOrderfileFilename() ] if self._options.lightweight_instrumentation: command_args.append('--reached-offsets=' + self._MERGED_CYGLOG_FILENAME) else: command_args.append('--merged-cyglog=' + self._MERGED_CYGLOG_FILENAME) self._step_recorder.RunCommand([self._CYGLOG_TO_ORDERFILE_SCRIPT] + command_args) except CommandError: self._SaveForDebugging(self._MERGED_CYGLOG_FILENAME) self._SaveForDebuggingWithOverwrite(self._compiler.lib_chrome_so) raise