def main(): parser = argparse.ArgumentParser() parser.add_argument('filename') args = parser.parse_args() devil_chromium.Initialize() if os.path.splitext(args.filename)[1] in ('.zip', '.apk', '.jar'): sizes, total_size = ExtractSizesFromZip(args.filename) else: single_set_of_sizes, total_size = _ExtractSizesFromDexFile(args.filename) sizes = {"": single_set_of_sizes} file_basename = os.path.basename(args.filename) for classes_dex_file, classes_dex_sizes in sizes.iteritems(): for dex_header_name, readable_name in CONTRIBUTORS_TO_DEX_CACHE.iteritems(): if dex_header_name in classes_dex_sizes: perf_tests_results_helper.PrintPerfResult( '%s_%s_%s' % (file_basename, classes_dex_file, readable_name), 'total', [classes_dex_sizes[dex_header_name]], readable_name) perf_tests_results_helper.PrintPerfResult( '%s_DexCache_size' % (file_basename), 'total', [total_size], 'bytes of permanent dirty memory') return 0
def main(): parser = argparse.ArgumentParser() parser.add_argument('filename') args = parser.parse_args() if os.path.splitext(args.filename)[1] in ('.zip', '.apk', '.jar'): sizes, total_size, num_unique_methods = ExtractSizesFromZip( args.filename) else: with open(args.filename) as f: dexfile = dex_parser.DexFile(bytearray(f.read())) single_set_of_sizes, total_size = _ExtractSizesFromDexFile(dexfile) sizes = {"": single_set_of_sizes} num_unique_methods = single_set_of_sizes['methods'] file_basename = os.path.basename(args.filename) for classes_dex_file, classes_dex_sizes in sizes.iteritems(): for readable_name in _CONTRIBUTORS_TO_DEX_CACHE.itervalues(): if readable_name in classes_dex_sizes: perf_tests_results_helper.PrintPerfResult( '%s_%s_%s' % (file_basename, classes_dex_file, readable_name), 'total', [classes_dex_sizes[readable_name]], readable_name) perf_tests_results_helper.PrintPerfResult( '%s_unique_methods' % file_basename, 'total', [num_unique_methods], 'unique methods') perf_tests_results_helper.PrintPerfResult( '%s_DexCache_size' % (file_basename), 'total', [total_size], 'bytes of permanent dirty memory') return 0
def main(): parser = argparse.ArgumentParser() parser.add_argument( '--apk-name', help='Name of the APK to which the dexfile corresponds.') parser.add_argument('dexfile') args = parser.parse_args() devil_chromium.Initialize() if not args.apk_name: dirname, basename = os.path.split(args.dexfile) while basename: if 'apk' in basename: args.apk_name = basename break dirname, basename = os.path.split(dirname) else: parser.error('Unable to determine apk name from %s, ' 'and --apk-name was not provided.' % args.dexfile) method_count = MethodCount(args.dexfile) perf_tests_results_helper.PrintPerfResult('%s_methods' % args.apk_name, 'total', [method_count], 'methods') return 0
def ReportPerfResult(chart_data, graph_title, trace_title, value, units, improvement_direction='down', important=True): """Outputs test results in correct format. If chart_data is None, it outputs data in old format. If chart_data is a dictionary, formats in chartjson format. If any other format defaults to old format. """ if chart_data and isinstance(chart_data, dict): chart_data['charts'].setdefault(graph_title, {}) chart_data['charts'][graph_title][trace_title] = { 'type': 'scalar', 'value': value, 'units': units, 'improvement_direction': improvement_direction, 'important': important } else: perf_tests_results_helper.PrintPerfResult(graph_title, trace_title, [value], units)
def TearDownPerfMonitoring(self, test): """Cleans up performance monitoring if the specified test required it. Args: test: The name of the test that was just run. Raises: Exception: if there's anything wrong with the perf data. """ if not self._IsPerfTest(test): return raw_test_name = test.split('#')[1] # Wait and grab annotation data so we can figure out which traces to parse regex = self.device.old_interface.WaitForLogMatch( re.compile('\*\*PERFANNOTATION\(' + raw_test_name + '\)\:(.*)'), None) # If the test is set to run on a specific device type only (IE: only # tablet or phone) and it is being run on the wrong device, the test # just quits and does not do anything. The java test harness will still # print the appropriate annotation for us, but will add --NORUN-- for # us so we know to ignore the results. # The --NORUN-- tag is managed by MainActivityTestBase.java if regex.group(1) != '--NORUN--': # Obtain the relevant perf data. The data is dumped to a # JSON formatted file. json_string = self.device.ReadFile( '/data/data/com.google.android.apps.chrome/files/PerfTestData.txt', as_root=True) if json_string: json_string = '\n'.join(json_string) else: raise Exception('Perf file does not exist or is empty') if self.options.save_perf_json: json_local_file = '/tmp/chromium-android-perf-json-' + raw_test_name with open(json_local_file, 'w') as f: f.write(json_string) logging.info('Saving Perf UI JSON from test ' + test + ' to ' + json_local_file) raw_perf_data = regex.group(1).split(';') for raw_perf_set in raw_perf_data: if raw_perf_set: perf_set = raw_perf_set.split(',') if len(perf_set) != 3: raise Exception( 'Unexpected number of tokens in perf annotation ' 'string: ' + raw_perf_set) # Process the performance data result = json_perf_parser.GetAverageRunInfoFromJSONString( json_string, perf_set[0]) perf_tests_results_helper.PrintPerfResult( perf_set[1], perf_set[2], [result['average']], result['units'])
def main(): parser = optparse.OptionParser() parser.add_option('', '--out-dir', help='Directory where the device path is stored', default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) parser.add_option( '--no-provisioning-check', action='store_true', help='Will not check if devices are provisioned properly.') parser.add_option('--device-status-dashboard', action='store_true', help='Output device status data for dashboard.') parser.add_option('--restart-usb', action='store_true', help='Restart USB ports before running device check.') parser.add_option('--json-output', help='Output JSON information into a specified file.') parser.add_option('-v', '--verbose', action='count', default=1, help='Log more information.') options, args = parser.parse_args() if args: parser.error('Unknown options %s' % args) run_tests_helper.SetLogLevel(options.verbose) # Remove the last build's "bad devices" before checking device statuses. device_blacklist.ResetBlacklist() try: expected_devices = device_list.GetPersistentDeviceList( os.path.join(options.out_dir, device_list.LAST_DEVICES_FILENAME)) except IOError: expected_devices = [] devices = device_utils.DeviceUtils.HealthyDevices() device_serials = [d.adb.GetDeviceSerial() for d in devices] # Only restart usb if devices are missing. if set(expected_devices) != set(device_serials): logging.warning('expected_devices: %s', expected_devices) logging.warning('devices: %s', device_serials) KillAllAdb() retries = 5 usb_restarted = True if options.restart_usb: if not RestartUsb(): usb_restarted = False bb_annotations.PrintWarning() logging.error('USB reset stage failed, ' 'wait for any device to come back.') while retries: logging.info('retry adb devices...') time.sleep(1) devices = device_utils.DeviceUtils.HealthyDevices() device_serials = [d.adb.GetDeviceSerial() for d in devices] if set(expected_devices) == set(device_serials): # All devices are online, keep going. break if not usb_restarted and devices: # The USB wasn't restarted, but there's at least one device online. # No point in trying to wait for all devices. break retries -= 1 types, builds, batteries, errors, devices_ok, json_data = ([], [], [], [], [], []) if devices: types, builds, batteries, errors, devices_ok, json_data = (zip( *[DeviceInfo(dev, options) for dev in devices])) # Write device info to file for buildbot info display. if os.path.exists('/home/chrome-bot'): with open('/home/chrome-bot/.adb_device_info', 'w') as f: for device in json_data: try: f.write('%s %s %s %.1fC %s%%\n' % (device['serial'], device['type'], device['build'], float(device['battery']['temperature']) / 10, device['battery']['level'])) except Exception: pass err_msg = CheckForMissingDevices(options, devices) or [] unique_types = list(set(types)) unique_builds = list(set(builds)) bb_annotations.PrintMsg('Online devices: %d. Device types %s, builds %s' % (len(devices), unique_types, unique_builds)) for j in json_data: logging.info('Device %s (%s)', j.get('serial'), j.get('type')) logging.info(' Build: %s (%s)', j.get('build'), j.get('build_detail')) logging.info(' Current Battery Service state:') for k, v in j.get('battery', {}).iteritems(): logging.info(' %s: %s', k, v) logging.info(' IMEI slice: %s', j.get('imei_slice')) logging.info(' WiFi IP: %s', j.get('wifi_ip')) for dev, dev_errors in zip(devices, errors): if dev_errors: err_msg += ['%s errors:' % str(dev)] err_msg += [' %s' % error for error in dev_errors] if err_msg: bb_annotations.PrintWarning() for e in err_msg: logging.error(e) from_address = '*****@*****.**' to_addresses = ['*****@*****.**'] bot_name = os.environ.get('BUILDBOT_BUILDERNAME') slave_name = os.environ.get('BUILDBOT_SLAVENAME') subject = 'Device status check errors on %s, %s.' % (slave_name, bot_name) SendEmail(from_address, to_addresses, [], subject, '\n'.join(err_msg)) if options.device_status_dashboard: offline_devices = [ device_utils.DeviceUtils(a) for a in adb_wrapper.AdbWrapper.Devices(is_ready=False) if a.GetState() == 'offline' ] perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices', [len(devices)], 'devices') perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', [len(offline_devices)], 'devices', 'unimportant') for dev, battery in zip(devices, batteries): perf_tests_results_helper.PrintPerfResult('DeviceBattery', str(dev), [battery], '%', 'unimportant') if options.json_output: with open(options.json_output, 'wb') as f: f.write(json.dumps(json_data, indent=4)) num_failed_devs = 0 for device_ok, device in zip(devices_ok, devices): if not device_ok: logging.warning('Blacklisting %s', str(device)) device_blacklist.ExtendBlacklist([str(device)]) num_failed_devs += 1 if num_failed_devs == len(devices): return 2 if not devices: return 1
def main(): parser = optparse.OptionParser() parser.add_option('', '--out-dir', help='Directory where the device path is stored', default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) parser.add_option( '--no-provisioning-check', action='store_true', help='Will not check if devices are provisioned properly.') parser.add_option('--device-status-dashboard', action='store_true', help='Output device status data for dashboard.') parser.add_option('--restart-usb', action='store_true', help='Restart USB ports before running device check.') parser.add_option('--json-output', help='Output JSON information into a specified file.') options, args = parser.parse_args() if args: parser.error('Unknown options %s' % args) # Remove the last build's "bad devices" before checking device statuses. device_blacklist.ResetBlacklist() try: expected_devices = device_list.GetPersistentDeviceList( os.path.join(options.out_dir, device_list.LAST_DEVICES_FILENAME)) except IOError: expected_devices = [] devices = android_commands.GetAttachedDevices() # Only restart usb if devices are missing. if set(expected_devices) != set(devices): print 'expected_devices: %s, devices: %s' % (expected_devices, devices) KillAllAdb() retries = 5 usb_restarted = True if options.restart_usb: if not RestartUsb(): usb_restarted = False bb_annotations.PrintWarning() print 'USB reset stage failed, wait for any device to come back.' while retries: print 'retry adb devices...' time.sleep(1) devices = android_commands.GetAttachedDevices() if set(expected_devices) == set(devices): # All devices are online, keep going. break if not usb_restarted and devices: # The USB wasn't restarted, but there's at least one device online. # No point in trying to wait for all devices. break retries -= 1 # TODO(navabi): Test to make sure this fails and then fix call offline_devices = android_commands.GetAttachedDevices(hardware=False, emulator=False, offline=True) types, builds, batteries, reports, errors = [], [], [], [], [] fail_step_lst = [] if devices: types, builds, batteries, reports, errors, fail_step_lst = (zip( *[DeviceInfo(dev, options) for dev in devices])) err_msg = CheckForMissingDevices(options, devices) or [] unique_types = list(set(types)) unique_builds = list(set(builds)) bb_annotations.PrintMsg('Online devices: %d. Device types %s, builds %s' % (len(devices), unique_types, unique_builds)) print '\n'.join(reports) for serial, dev_errors in zip(devices, errors): if dev_errors: err_msg += ['%s errors:' % serial] err_msg += [' %s' % error for error in dev_errors] if err_msg: bb_annotations.PrintWarning() msg = '\n'.join(err_msg) print msg from_address = '*****@*****.**' to_addresses = ['*****@*****.**'] bot_name = os.environ.get('BUILDBOT_BUILDERNAME') slave_name = os.environ.get('BUILDBOT_SLAVENAME') subject = 'Device status check errors on %s, %s.' % (slave_name, bot_name) SendEmail(from_address, to_addresses, [], subject, msg) if options.device_status_dashboard: perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices', [len(devices)], 'devices') perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', [len(offline_devices)], 'devices', 'unimportant') for serial, battery in zip(devices, batteries): perf_tests_results_helper.PrintPerfResult('DeviceBattery', serial, [battery], '%', 'unimportant') if options.json_output: with open(options.json_output, 'wb') as f: f.write( json.dumps({ 'online_devices': devices, 'offline_devices': offline_devices, 'expected_devices': expected_devices, 'unique_types': unique_types, 'unique_builds': unique_builds, })) if False in fail_step_lst: # TODO(navabi): Build fails on device status check step if there exists any # devices with critically low battery. Remove those devices from testing, # allowing build to continue with good devices. return 2 if not devices: return 1
def print_result(name, value_key): perf_tests_results_helper.PrintPerfResult( '%s_%s' % (args.apk_name, name), 'total', [sizes[value_key]], name)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--out-dir', help='Directory where the device path is stored', default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) parser.add_argument('--no-provisioning-check', action='store_true', help='Will not check if devices are provisioned ' 'properly.') parser.add_argument('--device-status-dashboard', action='store_true', help='Output device status data for dashboard.') parser.add_argument('--restart-usb', action='store_true', help='DEPRECATED. ' 'This script now always tries to reset USB.') parser.add_argument('--json-output', help='Output JSON information into a specified file.') parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') parser.add_argument('-v', '--verbose', action='count', default=1, help='Log more information.') args = parser.parse_args() run_tests_helper.SetLogLevel(args.verbose) if args.blacklist_file: blacklist = device_blacklist.Blacklist(args.blacklist_file) else: # TODO(jbudorick): Remove this once bots pass the blacklist file. blacklist = device_blacklist.Blacklist(device_blacklist.BLACKLIST_JSON) devices = RecoverDevices(blacklist, args.out_dir) types, builds, batteries, errors, devices_ok, json_data = ([], [], [], [], [], []) if devices: types, builds, batteries, errors, devices_ok, json_data = (zip( *[DeviceInfo(dev, args) for dev in devices])) # Write device info to file for buildbot info display. if os.path.exists('/home/chrome-bot'): with open('/home/chrome-bot/.adb_device_info', 'w') as f: for device in json_data: try: f.write('%s %s %s %.1fC %s%%\n' % (device['serial'], device['type'], device['build'], float(device['battery']['temperature']) / 10, device['battery']['level'])) except Exception: pass err_msg = CheckForMissingDevices(args, devices) or [] unique_types = list(set(types)) unique_builds = list(set(builds)) bb_annotations.PrintMsg('Online devices: %d. Device types %s, builds %s' % (len(devices), unique_types, unique_builds)) for j in json_data: logging.info('Device %s (%s)', j.get('serial'), j.get('type')) logging.info(' Build: %s (%s)', j.get('build'), j.get('build_detail')) logging.info(' Current Battery Service state:') for k, v in j.get('battery', {}).iteritems(): logging.info(' %s: %s', k, v) logging.info(' IMEI slice: %s', j.get('imei_slice')) logging.info(' WiFi IP: %s', j.get('wifi_ip')) for dev, dev_errors in zip(devices, errors): if dev_errors: err_msg += ['%s errors:' % str(dev)] err_msg += [' %s' % error for error in dev_errors] if err_msg: bb_annotations.PrintWarning() for e in err_msg: logging.error(e) from_address = '*****@*****.**' to_addresses = ['*****@*****.**'] bot_name = os.environ.get('BUILDBOT_BUILDERNAME') slave_name = os.environ.get('BUILDBOT_SLAVENAME') subject = 'Device status check errors on %s, %s.' % (slave_name, bot_name) SendEmail(from_address, to_addresses, [], subject, '\n'.join(err_msg)) if args.device_status_dashboard: offline_devices = [ device_utils.DeviceUtils(a) for a in adb_wrapper.AdbWrapper.Devices(desired_state=None) if a.GetState() == 'offline' ] perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices', [len(devices)], 'devices') perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', [len(offline_devices)], 'devices', 'unimportant') for dev, battery in zip(devices, batteries): perf_tests_results_helper.PrintPerfResult('DeviceBattery', str(dev), [battery], '%', 'unimportant') if args.json_output: with open(args.json_output, 'wb') as f: f.write(json.dumps(json_data, indent=4)) num_failed_devs = 0 for device_ok, device in zip(devices_ok, devices): if not device_ok: logging.warning('Blacklisting %s', str(device)) blacklist.Extend([str(device)]) num_failed_devs += 1 if num_failed_devs == len(devices): return 2 if not devices: return 1
def print_result(name, value_key, description=None): perf_tests_results_helper.PrintPerfResult( '%s_%s' % (args.apk_name, name), 'total', [sizes[value_key]], description or name)
def main(): parser = optparse.OptionParser() parser.add_option('', '--out-dir', help='Directory where the device path is stored', default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) parser.add_option( '--no-provisioning-check', action='store_true', help='Will not check if devices are provisioned properly.') parser.add_option('--device-status-dashboard', action='store_true', help='Output device status data for dashboard.') parser.add_option('--restart-usb', action='store_true', help='Restart USB ports before running device check.') options, args = parser.parse_args() if args: parser.error('Unknown options %s' % args) # Remove the last build's "bad devices" before checking device statuses. device_blacklist.ResetBlacklist() if options.restart_usb: expected_devices = GetLastDevices(os.path.abspath(options.out_dir)) devices = android_commands.GetAttachedDevices() # Only restart usb if devices are missing. if set(expected_devices) != set(devices): KillAllAdb() retries = 5 usb_restarted = True if not RestartUsb(): usb_restarted = False bb_annotations.PrintWarning() print 'USB reset stage failed, wait for any device to come back.' while retries: time.sleep(1) devices = android_commands.GetAttachedDevices() if set(expected_devices) == set(devices): # All devices are online, keep going. break if not usb_restarted and devices: # The USB wasn't restarted, but there's at least one device online. # No point in trying to wait for all devices. break retries -= 1 devices = android_commands.GetAttachedDevices() # TODO(navabi): Test to make sure this fails and then fix call offline_devices = android_commands.GetAttachedDevices(hardware=False, emulator=False, offline=True) types, builds, batteries, reports, errors = [], [], [], [], [] fail_step_lst = [] if devices: types, builds, batteries, reports, errors, fail_step_lst = (zip( *[DeviceInfo(dev, options) for dev in devices])) err_msg = CheckForMissingDevices(options, devices) or [] unique_types = list(set(types)) unique_builds = list(set(builds)) bb_annotations.PrintMsg('Online devices: %d. Device types %s, builds %s' % (len(devices), unique_types, unique_builds)) print '\n'.join(reports) for serial, dev_errors in zip(devices, errors): if dev_errors: err_msg += ['%s errors:' % serial] err_msg += [' %s' % error for error in dev_errors] if err_msg: bb_annotations.PrintWarning() msg = '\n'.join(err_msg) print msg SendDeviceStatusAlert(msg) if options.device_status_dashboard: perf_tests_results_helper.PrintPerfResult('BotDevices', 'OnlineDevices', [len(devices)], 'devices') perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', [len(offline_devices)], 'devices', 'unimportant') for serial, battery in zip(devices, batteries): perf_tests_results_helper.PrintPerfResult('DeviceBattery', serial, [battery], '%', 'unimportant') if False in fail_step_lst: # TODO(navabi): Build fails on device status check step if there exists any # devices with critically low battery. Remove those devices from testing, # allowing build to continue with good devices. return 1 if not devices: return 1