Bug 1630972 - [mozperftest] Put the cycles inside the browser layer r=sparky

Cycles belong to the browser layer

Differential Revision: https://phabricator.services.mozilla.com/D71335
This commit is contained in:
Tarek Ziadé 2020-04-17 15:08:25 +00:00
parent df5581830d
commit 11b953d576
6 changed files with 33 additions and 22 deletions

View File

@ -41,7 +41,6 @@ class Options:
"help": "Path to where data will be stored, defaults to a top-level "
"`artifacts` folder.",
},
"--cycles": {"type": int, "default": 1, "help": "Number of full cycles"},
"--hooks": {"type": str, "default": "", "help": "Python hooks"},
"--verbose": {"action": "store_true", "default": False, "help": "Verbose mode"},
}

View File

@ -66,6 +66,10 @@ host_fetches = {
class BrowsertimeRunner(NodeRunner):
name = "browsertime (%s)" % NodeRunner.name
arguments = {
"--cycles": {"type": int, "default": 1, "help": "Number of full cycles"}
}
def __init__(self, env, mach_cmd):
super(BrowsertimeRunner, self).__init__(env, mach_cmd)
self.topsrcdir = mach_cmd.topsrcdir
@ -417,6 +421,16 @@ class BrowsertimeRunner(NodeRunner):
return profile
def __call__(self, metadata):
cycles = self.get_arg("cycles", 1)
for cycle in range(1, cycles + 1):
metadata.run_hook("before_cycle", cycle=cycle)
try:
metadata = self._one_cycle(metadata)
finally:
metadata.run_hook("after_cycle", cycle=cycle)
return metadata
def _one_cycle(self, metadata):
# keep the object around
# see https://bugzilla.mozilla.org/show_bug.cgi?id=1625118
profile = self.get_profile(metadata)

View File

@ -29,17 +29,10 @@ class Perftest(MachCommandBase):
kwargs["test_objects"] = test_objects
kwargs["resolve_tests"] = resolve_tests
env = MachEnvironment(self, flavor, **kwargs)
env.run_hook("before_cycles")
cycles = env.get_arg("cycles", 1)
metadata = Metadata(self, env, flavor)
env.run_hook("before_runs")
try:
# XXX put the cycles inside the browser layer
for cycle in range(1, cycles + 1):
with env.frozen() as e:
e.run_hook("before_cycle", cycle=cycle)
try:
e.run(metadata)
finally:
e.run_hook("after_cycle", cycle=cycle)
with env.frozen() as e:
e.run(metadata)
finally:
env.run_hook("after_cycles")
env.run_hook("after_runs")

View File

@ -12,6 +12,11 @@ class Metadata:
self._output = None
self._env = env
def run_hook(self, name, **kw):
# this bypasses layer restrictions on args,
# which is fine since it's user script
return self._env.run_hook(name, **kw)
def set_output(self, output):
self._output = output

View File

@ -31,12 +31,12 @@ def host_platform():
raise ValueError("sys.platform is not yet supported: {}".format(sys.platform))
def add_option(metadata, name, value):
options = metadata.get_arg("extra_options", "")
def add_option(env, name, value):
options = env.get_arg("extra_options", "")
options += ",%s=%s" % (name, value)
metadata.set_arg("extra_options", options)
env.set_arg("extra_options", options)
def add_options(metadata, options):
def add_options(env, options):
for name, value in options:
add_option(metadata, name, value)
add_option(env, name, value)

View File

@ -31,11 +31,11 @@ options = [
]
def before_cycles(metadata, **kw):
metadata.set_arg("cycles", len(sites))
add_options(metadata, options)
def before_runs(env, **kw):
env.set_arg("cycles", len(sites))
add_options(env, options)
def before_cycle(metadata, **kw):
def before_cycle(env, **kw):
url = next(get_site)
add_option(metadata, "browsertime.url", url)
add_option(env, "browsertime.url", url)