#!/usr/bin/env python # 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 file, # You can obtain one at http://mozilla.org/MPL/2.0/.
import copy import glob import json import os import posixpath import subprocess import sys import time
# load modules from parent dir
sys.path.insert(1, os.path.dirname(sys.path[0]))
from mozharness.base.script import BaseScript, PreScriptAction from mozharness.mozilla.automation import EXIT_STATUS_DICT, TBPL_RETRY from mozharness.mozilla.mozbase import MozbaseMixin from mozharness.mozilla.testing.android import AndroidMixin from mozharness.mozilla.testing.testbase import TestingMixin, testing_config_options
class AndroidProfileRun(TestingMixin, BaseScript, MozbaseMixin, AndroidMixin): """
Mozharness script to generate an android PGO profile using the emulator """
# these are necessary since self.config is read only
c = self.config
self.installer_path = c.get("installer_path")
self.device_serial = "emulator-5554"
def install(self): """
Install APKs on the device. """ assert (
self.installer_path isnotNone
), "Either add installer_path to the config or use --installer-path."
self.install_android_app(self.installer_path)
self.info("Finished installing apps for %s" % self.device_serial)
def run_tests(self): """
Generate the PGO profile data """ from marionette_driver.marionette import Marionette from mozdevice import ADBDeviceFactory, ADBTimeoutError from mozhttpd import MozHttpd from mozprofile import Preferences from six import string_types
path_mappings = {
k: os.path.join(topsrcdir, v) for k, v in PATH_MAPPINGS.items()
}
httpd = MozHttpd(
port=PORT,
docroot=os.path.join(topsrcdir, "build", "pgo"),
path_mappings=path_mappings,
)
httpd.start(block=False)
profile_data_dir = os.path.join(topsrcdir, "testing", "profiles") with open(os.path.join(profile_data_dir, "profiles.json"), "r") as fh:
base_profiles = json.load(fh)["profileserver"]
prefpaths = [
os.path.join(profile_data_dir, profile, "user.js") for profile in base_profiles
]
prefs = {} for path in prefpaths:
prefs.update(Preferences.read_prefs(path))
interpolation = {"server": "%s:%d" % httpd.httpd.server_address, "OOP": "false"} for k, v in prefs.items(): if isinstance(v, string_types):
v = v.format(**interpolation)
prefs[k] = Preferences.cast(v)
try: # Run Fennec a first time to initialize its profile
driver = Marionette(
app="fennec",
package_name=app,
adb_path=adb,
bin="geckoview-androidTest.apk",
prefs=prefs,
connect_to_running_emulator=True,
startup_timeout=1000,
env=env,
symbols_path=self.symbols_path,
)
driver.start_session()
# Now generate the profile and wait for it to complete for page in PAGES:
driver.navigate("http://%s:%d/%s" % (IP, PORT, page))
timeout = 2 if"Speedometer"in page: # The Speedometer[23] test actually runs many tests internally in # javascript, so it needs extra time to run through them. The # emulator doesn't get very far through the whole suite, but # this extra time at least lets some of them process.
timeout = 360
time.sleep(timeout)
driver.quit(in_app=True)
# Pull all the profraw files and en-US.log
adbdevice.pull(outputdir, "/builds/worker/workspace/") except ADBTimeoutError:
self.fatal( "INFRA-ERROR: Failed with an ADBTimeoutError",
EXIT_STATUS_DICT[TBPL_RETRY],
)
profraw_files = glob.glob("/builds/worker/workspace/*.profraw") ifnot profraw_files:
self.fatal("Could not find any profraw files in /builds/worker/workspace") elif len(profraw_files) == 1:
self.fatal( "Only found 1 profraw file. Did child processes terminate early?"
)
merge_cmd = [
os.path.join(os.environ["MOZ_FETCHES_DIR"], "clang/bin/llvm-profdata"), "merge", "-o", "/builds/worker/workspace/merged.profdata",
] + profraw_files
rc = subprocess.call(merge_cmd) if rc != 0:
self.fatal( "INFRA-ERROR: Failed to merge profile data. Corrupt profile?",
EXIT_STATUS_DICT[TBPL_RETRY],
)
# tarfile doesn't support xz in this version of Python
tar_cmd = [ "tar", "-acvf", "/builds/worker/artifacts/profdata.tar.xz", "-C", "/builds/worker/workspace", "merged.profdata", "en-US.log",
]
subprocess.check_call(tar_cmd)
httpd.stop()
if __name__ == "__main__":
test = AndroidProfileRun()
test.run_and_exit()
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.