Bug 1550828: String fixes and minor cleanup for power.py and Raptor's mach_commands.py. r=bc

Differential Revision: https://phabricator.services.mozilla.com/D30775

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Stephen Donner 2019-05-11 08:13:29 +00:00
Родитель c5d721dff7
Коммит 4a55597f03
2 изменённых файлов: 67 добавлений и 53 удалений

Просмотреть файл

@ -29,9 +29,9 @@ BENCHMARK_REVISION = '2720cdc790828952964524bb44ce8b4c14670e90'
class RaptorRunner(MozbuildObject): class RaptorRunner(MozbuildObject):
def run_test(self, raptor_args, kwargs): def run_test(self, raptor_args, kwargs):
""" """
We want to do couple of things before running raptor We want to do a few things before running Raptor:
1. Clone mozharness 1. Clone mozharness
2. Make config for raptor mozharness 2. Make the config for Raptor mozharness
3. Run mozharness 3. Run mozharness
""" """
@ -204,7 +204,7 @@ class MachRaptor(MachCommandBase):
adbhost = ADBHost(verbose=True) adbhost = ADBHost(verbose=True)
device_serial = "%s:5555" % device.get_ip_address() device_serial = "%s:5555" % device.get_ip_address()
device.command_output(["tcpip", "5555"]) device.command_output(["tcpip", "5555"])
raw_input("Please disconnect your device from USB then press ENTER...") raw_input("Please disconnect your device from USB then press Enter/return...")
adbhost.command_output(["connect", device_serial]) adbhost.command_output(["connect", device_serial])
while len(adbhost.devices()) > 1: while len(adbhost.devices()) > 1:
raw_input("You must disconnect your device from USB before continuing.") raw_input("You must disconnect your device from USB before continuing.")
@ -218,7 +218,7 @@ class MachRaptor(MachCommandBase):
finally: finally:
try: try:
if kwargs['app'] in firefox_android_browsers and kwargs['power_test']: if kwargs['app'] in firefox_android_browsers and kwargs['power_test']:
raw_input("Connect device via usb and press ENTER...") raw_input("Connect device via USB and press Enter/return...")
device = ADBAndroid(device=device_serial, verbose=True) device = ADBAndroid(device=device_serial, verbose=True)
device.command_output(["usb"]) device.command_output(["usb"])
adbhost.command_output(["disconnect", device_serial]) adbhost.command_output(["disconnect", device_serial])

Просмотреть файл

@ -1,6 +1,7 @@
# This Source Code Form is subject to the terms of the Mozilla Public # This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import from __future__ import absolute_import
import os import os
@ -8,21 +9,24 @@ import re
def init_android_power_test(raptor): def init_android_power_test(raptor):
upload_dir = os.getenv('MOZ_UPLOAD_DIR') upload_dir = os.getenv("MOZ_UPLOAD_DIR")
if not upload_dir: if not upload_dir:
raptor.log.critical("% power test ignored; MOZ_UPLOAD_DIR unset" % raptor.config['app']) raptor.log.critical(
"% power test ignored; MOZ_UPLOAD_DIR unset" % raptor.config["app"]
)
return return
# Set the screen off timeout to 2 hours since the device will be running # Set the screen-off timeout to two (2) hours, since the device will be running
# disconnected and would otherwise turn off the screen thereby halting # disconnected, and would otherwise turn off the screen, thereby halting
# execution of the test. Save the current value so we can restore it later # execution of the test. Save the current value so we can restore it later
# since it is a persistent change. # since it is a persistent change.
raptor.screen_off_timeout = raptor.device.shell_output( raptor.screen_off_timeout = raptor.device.shell_output(
"settings get system screen_off_timeout").strip() "settings get system screen_off_timeout"
).strip()
raptor.device.shell_output("settings put system screen_off_timeout 7200000") raptor.device.shell_output("settings put system screen_off_timeout 7200000")
raptor.device.shell_output("dumpsys batterystats --reset") raptor.device.shell_output("dumpsys batterystats --reset")
raptor.device.shell_output("dumpsys batterystats --enable full-wake-history") raptor.device.shell_output("dumpsys batterystats --enable full-wake-history")
filepath = os.path.join(upload_dir, 'battery-before.txt') filepath = os.path.join(upload_dir, "battery-before.txt")
with open(filepath, 'w') as output: with open(filepath, "w") as output:
output.write(raptor.device.shell_output("dumpsys battery")) output.write(raptor.device.shell_output("dumpsys battery"))
@ -49,42 +53,46 @@ def init_android_power_test(raptor):
# Bluetooth: 0.527 ( cpu=0.00319 bt=0.524 ) Including smearing: 0.574 ( proportional=... ) # Bluetooth: 0.527 ( cpu=0.00319 bt=0.524 ) Including smearing: 0.574 ( proportional=... )
# Wifi: 0.423 ( cpu=0.343 wifi=0.0800 ) Including smearing: 0.461 ( proportional=0.0375 ) # Wifi: 0.423 ( cpu=0.343 wifi=0.0800 ) Including smearing: 0.461 ( proportional=0.0375 )
# #
# For Android 8 the cpu, wifi, screen and proportional values from the # For Android 8, the cpu, wifi, screen, and proportional values are available from
# Uid line for the app. If the test does not run long enough it # the Uid line for the app. If the test does not run long enough, it
# appears that the screen value from the Uid will be missing but the # appears that the screen value from the Uid will be missing, but the
# standalone Screen value is available. # standalone Screen value is available.
# #
# For Android 7 only the cpu value is available from the Uid line. We # For Android 7, only the cpu value is available from the Uid line. We
# can use the Screen and Wifi values for Android 7 from the Screen # can use the Screen and Wifi values for Android 7 from the Screen
# and Wifi lines which may include contributions from the system or # and Wifi lines, which might include contributions from the system or
# other apps however it should be useful for spotting changes in power # other apps; however, it should still be useful for spotting changes in power
# usage. # usage.
# #
# If the energy values from Uid line for Android 8 are available they # If the energy values from the Uid line for Android 8 are available, they
# will be used. If for any reason that the screen or wifi power is # will be used. If for any reason either/both screen or wifi power is
# missing, the values from the Screen and Wifi lines will be used. # missing, the values from the Screen and Wifi lines will be used.
# #
# If only the cpu energy value is available, then it will be used # If only the cpu energy value is available, it will be used
# along with the values from the Screen and Wifi lines. # along with the values from the Screen and Wifi lines.
def finish_android_power_test(raptor, test_name): def finish_android_power_test(raptor, test_name):
upload_dir = os.getenv('MOZ_UPLOAD_DIR') upload_dir = os.getenv("MOZ_UPLOAD_DIR")
if not upload_dir: if not upload_dir:
raptor.log.critical("% power test ignored because MOZ_UPLOAD_DIR was not set" % test_name) raptor.log.critical(
"% power test ignored because MOZ_UPLOAD_DIR was not set" % test_name
)
return return
# Restore the screen off timeout. # Restore screen_off_timeout.
raptor.device.shell_output( raptor.device.shell_output(
"settings put system screen_off_timeout %s" % raptor.screen_off_timeout) "settings put system screen_off_timeout %s" % raptor.screen_off_timeout
filepath = os.path.join(upload_dir, 'battery-after.txt') )
with open(filepath, 'w') as output: filepath = os.path.join(upload_dir, "battery-after.txt")
with open(filepath, "w") as output:
output.write(raptor.device.shell_output("dumpsys battery")) output.write(raptor.device.shell_output("dumpsys battery"))
verbose = raptor.device._verbose verbose = raptor.device._verbose
raptor.device._verbose = False raptor.device._verbose = False
filepath = os.path.join(upload_dir, 'batterystats.csv') filepath = os.path.join(upload_dir, "batterystats.csv")
with open(filepath, 'w') as output: with open(filepath, "w") as output:
output.write(raptor.device.shell_output("dumpsys batterystats --checkin")) output.write(raptor.device.shell_output("dumpsys batterystats --checkin"))
filepath = os.path.join(upload_dir, 'batterystats.txt') filepath = os.path.join(upload_dir, "batterystats.txt")
with open(filepath, 'w') as output: with open(filepath, "w") as output:
batterystats = raptor.device.shell_output("dumpsys batterystats") batterystats = raptor.device.shell_output("dumpsys batterystats")
output.write(batterystats) output.write(batterystats)
raptor.device._verbose = verbose raptor.device._verbose = verbose
@ -93,24 +101,25 @@ def finish_android_power_test(raptor, test_name):
total = cpu = wifi = smearing = screen = proportional = 0 total = cpu = wifi = smearing = screen = proportional = 0
full_screen = 0 full_screen = 0
full_wifi = 0 full_wifi = 0
re_uid = re.compile(r'proc=([^:]+):"%s"' % raptor.config['binary']) re_uid = re.compile(r'proc=([^:]+):"%s"' % raptor.config["binary"])
re_estimated_power = re.compile(r'\s+Estimated power use [(]mAh[)]') re_estimated_power = re.compile(r"\s+Estimated power use [(]mAh[)]")
re_proportional = re.compile(r'proportional=([\d.]+)') re_proportional = re.compile(r"proportional=([\d.]+)")
re_screen = re.compile(r'screen=([\d.]+)') re_screen = re.compile(r"screen=([\d.]+)")
re_full_screen = re.compile(r'\s+Screen:\s+([\d.]+)') re_full_screen = re.compile(r"\s+Screen:\s+([\d.]+)")
re_full_wifi = re.compile(r'\s+Wifi:\s+([\d.]+)') re_full_wifi = re.compile(r"\s+Wifi:\s+([\d.]+)")
re_power = None re_power = None
batterystats = batterystats.split('\n') batterystats = batterystats.split("\n")
for line in batterystats: for line in batterystats:
if uid is None: if uid is None:
# The proc line containing the uid and app name appears # The proc line containing the Uid and app name appears
# before the Estimated power line. # before the Estimated power line.
match = re_uid.search(line) match = re_uid.search(line)
if match: if match:
uid = match.group(1) uid = match.group(1)
re_power = re.compile( re_power = re.compile(
r'\s+Uid %s:\s+([\d.]+) ([(] cpu=([\d.]+) wifi=([\d.]+) [)] ' r"\s+Uid %s:\s+([\d.]+) ([(] cpu=([\d.]+) wifi=([\d.]+) [)] "
r'Including smearing: ([\d.]+))?' % uid) r"Including smearing: ([\d.]+))?" % uid
)
continue continue
if not estimated_power: if not estimated_power:
# Do not attempt to parse data until we have seen # Do not attempt to parse data until we have seen
@ -135,7 +144,7 @@ def finish_android_power_test(raptor, test_name):
(total, android8, cpu, wifi, smearing) = match.groups() (total, android8, cpu, wifi, smearing) = match.groups()
if android8: if android8:
# android8 is not None only if the Uid line # android8 is not None only if the Uid line
# contained values for cpu and wifi which is # contained values for cpu and wifi, which is
# true only for Android 8+. # true only for Android 8+.
match = re_screen.search(line) match = re_screen.search(line)
if match: if match:
@ -151,20 +160,25 @@ def finish_android_power_test(raptor, test_name):
screen = full_screen if screen == 0 else screen screen = full_screen if screen == 0 else screen
wifi = full_wifi if wifi is None else wifi wifi = full_wifi if wifi is None else wifi
raptor.log.info('power data for uid: %s, cpu: %s, wifi: %s, screen: %s, proportional: %s' % raptor.log.info(
(uid, cpu, wifi, screen, proportional)) "power data for uid: %s, cpu: %s, wifi: %s, screen: %s, proportional: %s"
% (uid, cpu, wifi, screen, proportional)
)
# send power data directly to the control server results handler; # send power data directly to the control-server results handler,
# so it can be formatted and output for perfherder ingestion # so it can be formatted and out-put for perfherder ingestion
power_data = {'type': 'power', power_data = {
'test': test_name, "type": "power",
'unit': 'mAh', "test": test_name,
'values': { "unit": "mAh",
'cpu': float(cpu), "values": {
'wifi': float(wifi), "cpu": float(cpu),
'screen': float(screen), "wifi": float(wifi),
'proportional': float(proportional)}} "screen": float(screen),
"proportional": float(proportional),
},
}
raptor.log.info("submitting power data via control server directly") raptor.log.info("submitting power data via control server directly")
raptor.control_server.submit_supporting_data(power_data) raptor.control_server.submit_supporting_data(power_data)