def FlushSystemCacheForDirectory(self, directory, ignoring=None): assert directory and os.path.exists(directory), \ 'Target directory %s must exist' % directory flush_command = util.FindSupportBinary(self.GetFlushUtilityName()) assert flush_command, \ 'You must build %s first' % self.GetFlushUtilityName() args = [] directory_contents = os.listdir(directory) for item in directory_contents: if not ignoring or item not in ignoring: args.append(os.path.join(directory, item)) if not args: return # According to msdn: # http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx # there's a maximum allowable command line of 32,768 characters on windows. while args: # Small note about [:256] and [256:] # [:N] will return a list with the first N elements, ie. # with [1,2,3,4,5], [:2] -> [1,2], and [2:] -> [3,4,5] # with [1,2,3,4,5], [:5] -> [1,2,3,4,5] and [5:] -> [] p = subprocess.Popen([flush_command, '--recurse'] + args[:256]) p.wait() assert p.returncode == 0, 'Failed to flush system cache' args = args[256:]
def SetupPrebuiltTools(adb): # TODO(bulach): build the host tools for mac, and the targets for x86/mips. # Prebuilt tools from r226197. prebuilt_tools = [ 'bitmaptools', 'file_poller', 'forwarder_dist/device_forwarder', 'host_forwarder', 'md5sum_dist/md5sum_bin', 'md5sum_bin_host', 'purge_ashmem', ] has_prebuilt = ( sys.platform.startswith('linux') and adb.system_properties['ro.product.cpu.abi'].startswith('armeabi')) if not has_prebuilt: return all([util.FindSupportBinary(t) for t in prebuilt_tools]) build_type = None for t in prebuilt_tools: src = os.path.basename(t) android_prebuilt_profiler_helper.GetIfChanged(src) bin_path = util.FindSupportBinary(t) if not build_type: build_type = GetBuildTypeOfPath(bin_path) or 'Release' constants.SetBuildType(build_type) dest = os.path.join(constants.GetOutDirectory(), t) if not bin_path: logging.warning('Setting up prebuilt %s', dest) if not os.path.exists(os.path.dirname(dest)): os.makedirs(os.path.dirname(dest)) prebuilt_path = android_prebuilt_profiler_helper.GetHostPath(src) if not os.path.exists(prebuilt_path): raise NotImplementedError(""" %s must be checked into cloud storage. Instructions: http://www.chromium.org/developers/telemetry/upload_to_cloud_storage """ % t) shutil.copyfile(prebuilt_path, dest) os.chmod(dest, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) return True
def GetStackTrace(self): stackwalk = util.FindSupportBinary('minidump_stackwalk') if not stackwalk: logging.warning( 'minidump_stackwalk binary not found. Must build it to ' 'symbolize crash dumps. Returning browser stdout.') return self.GetStandardOutput() dumps = glob.glob(os.path.join(self._tmp_minidump_dir, '*.dmp')) if not dumps: logging.warning('No crash dump found. Returning browser stdout.') return self.GetStandardOutput() most_recent_dump = heapq.nlargest(1, dumps, os.path.getmtime)[0] if os.path.getmtime(most_recent_dump) < (time.time() - (5 * 60)): logging.warn( 'Crash dump is older than 5 minutes. May not be correct.') minidump = most_recent_dump + '.stripped' with open(most_recent_dump, 'rb') as infile: with open(minidump, 'wb') as outfile: outfile.write(''.join(infile.read().partition('MDMP')[1:])) symbols = glob.glob( os.path.join(os.path.dirname(stackwalk), '*.breakpad*')) if not symbols: logging.warning( 'No breakpad symbols found. Returning browser stdout.') return self.GetStandardOutput() symbols_path = os.path.join(self._tmp_minidump_dir, 'symbols') for symbol in sorted(symbols, key=os.path.getmtime, reverse=True): if not os.path.isfile(symbol): continue with open(symbol, 'r') as f: fields = f.readline().split() if not fields: continue sha = fields[3] binary = ' '.join(fields[4:]) symbol_path = os.path.join(symbols_path, binary, sha) if os.path.exists(symbol_path): continue os.makedirs(symbol_path) shutil.copyfile(symbol, os.path.join(symbol_path, binary + '.sym')) error = tempfile.NamedTemporaryFile('w', 0) return subprocess.Popen([stackwalk, minidump, symbols_path], stdout=subprocess.PIPE, stderr=error).communicate()[0]
def __init__(self, dimensions, pixels): suffix = '.exe' if sys.platform == 'win32' else '' binary = util.FindSupportBinary('bitmaptools' + suffix) assert binary, 'You must build bitmaptools first!' self._popen = subprocess.Popen([binary], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # dimensions are: bpp, width, height, boxleft, boxtop, boxwidth, boxheight packed_dims = struct.pack('iiiiiii', *dimensions) self._popen.stdin.write(packed_dims) # If we got a list of ints, we need to convert it into a byte buffer. if type(pixels) is not bytearray: pixels = bytearray(pixels) self._popen.stdin.write(pixels)
def InstallOnDevice(adb, profiler_binary): host_binary_path = util.FindSupportBinary(profiler_binary) if not host_binary_path: has_prebuilt = ( sys.platform.startswith('linux') and adb.system_properties['ro.product.cpu.abi'].startswith('armeabi')) if has_prebuilt: GetIfChanged(profiler_binary) host_binary_path = GetHostPath(profiler_binary) else: logging.error('Profiler binary "%s" not found. Could not be installed', profiler_binary) return False device_binary_path = GetDevicePath(profiler_binary) adb.PushIfNeeded(host_binary_path, device_binary_path) adb.RunShellCommand('chmod 777 ' + device_binary_path) return True
def __init__(self, browser_backend, platform_backend, output_path, state): super(OOMKillerProfiler, self).__init__(browser_backend, platform_backend, output_path, state) if not 'mem_consumer_launched' in state: state['mem_consumer_launched'] = True mem_consumer_path = util.FindSupportBinary(os.path.join( 'apks', 'MemConsumer.apk'), executable=False) assert mem_consumer_path, ( 'Could not find memconsumer app. Please build ' 'memconsumer target.') self._browser_backend.adb.Install(mem_consumer_path) self._browser_backend.adb.GoHome() self._platform_backend.LaunchApplication( 'org.chromium.memconsumer/.MemConsumer', '--ei memory 20') # Bring the browser to the foreground after launching the mem consumer self._browser_backend.adb.StartActivity(browser_backend.package, browser_backend.activity, True)