2014-09-02 09:17:26 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Performance runner for d8.
|
|
|
|
|
|
|
|
Call e.g. with tools/run-perf.py --arch ia32 some_suite.json
|
|
|
|
|
|
|
|
The suite json format is expected to be:
|
|
|
|
{
|
|
|
|
"path": <relative path chunks to perf resources and main file>,
|
2018-05-11 16:12:21 +00:00
|
|
|
"owners": [<list of email addresses of benchmark owners (required)>],
|
2014-09-02 09:17:26 +00:00
|
|
|
"name": <optional suite name, file name is default>,
|
|
|
|
"archs": [<architecture name for which this suite is run>, ...],
|
|
|
|
"binary": <name of binary to run, default "d8">,
|
|
|
|
"flags": [<flag to d8>, ...],
|
2014-11-28 10:34:28 +00:00
|
|
|
"test_flags": [<flag to the test file>, ...],
|
2014-09-02 09:17:26 +00:00
|
|
|
"run_count": <how often will this suite run (optional)>,
|
|
|
|
"run_count_XXX": <how often will this suite run for arch XXX (optional)>,
|
2014-11-28 11:35:37 +00:00
|
|
|
"resources": [<js file to be moved to android device>, ...]
|
2014-09-02 09:17:26 +00:00
|
|
|
"main": <main js perf runner file>,
|
|
|
|
"results_regexp": <optional regexp>,
|
|
|
|
"results_processor": <optional python results processor script>,
|
|
|
|
"units": <the unit specification for the performance dashboard>,
|
2017-07-17 15:08:54 +00:00
|
|
|
"process_size": <flag - collect maximum memory used by the process>,
|
2014-09-02 09:17:26 +00:00
|
|
|
"tests": [
|
|
|
|
{
|
|
|
|
"name": <name of the trace>,
|
|
|
|
"results_regexp": <optional more specific regexp>,
|
|
|
|
"results_processor": <optional python results processor script>,
|
|
|
|
"units": <the unit specification for the performance dashboard>,
|
2017-07-17 15:08:54 +00:00
|
|
|
"process_size": <flag - collect maximum memory used by the process>,
|
2014-09-02 09:17:26 +00:00
|
|
|
}, ...
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
The tests field can also nest other suites in arbitrary depth. A suite
|
|
|
|
with a "main" file is a leaf suite that can contain one more level of
|
|
|
|
tests.
|
|
|
|
|
|
|
|
A suite's results_regexp is expected to have one string place holder
|
|
|
|
"%s" for the trace name. A trace's results_regexp overwrites suite
|
|
|
|
defaults.
|
|
|
|
|
|
|
|
A suite's results_processor may point to an optional python script. If
|
2017-02-16 13:48:31 +00:00
|
|
|
specified, it is called after running the tests (with a path relative to the
|
|
|
|
suite level's path). It is expected to read the measurement's output text
|
|
|
|
on stdin and print the processed output to stdout.
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2017-02-16 13:48:31 +00:00
|
|
|
The results_regexp will be applied to the processed output.
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
A suite without "tests" is considered a performance test itself.
|
|
|
|
|
|
|
|
Full example (suite with one runner):
|
|
|
|
{
|
|
|
|
"path": ["."],
|
2018-07-25 11:20:08 +00:00
|
|
|
"owners": ["username@chromium.org"],
|
2014-09-02 09:17:26 +00:00
|
|
|
"flags": ["--expose-gc"],
|
2014-11-28 10:34:28 +00:00
|
|
|
"test_flags": ["5"],
|
2014-09-02 09:17:26 +00:00
|
|
|
"archs": ["ia32", "x64"],
|
|
|
|
"run_count": 5,
|
|
|
|
"run_count_ia32": 3,
|
|
|
|
"main": "run.js",
|
|
|
|
"results_regexp": "^%s: (.+)$",
|
|
|
|
"units": "score",
|
|
|
|
"tests": [
|
|
|
|
{"name": "Richards"},
|
|
|
|
{"name": "DeltaBlue"},
|
|
|
|
{"name": "NavierStokes",
|
|
|
|
"results_regexp": "^NavierStokes: (.+)$"}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
Full example (suite with several runners):
|
|
|
|
{
|
|
|
|
"path": ["."],
|
2018-07-25 11:20:08 +00:00
|
|
|
"owners": ["username@chromium.org", "otherowner@google.com"],
|
2014-09-02 09:17:26 +00:00
|
|
|
"flags": ["--expose-gc"],
|
|
|
|
"archs": ["ia32", "x64"],
|
|
|
|
"run_count": 5,
|
|
|
|
"units": "score",
|
|
|
|
"tests": [
|
|
|
|
{"name": "Richards",
|
|
|
|
"path": ["richards"],
|
|
|
|
"main": "run.js",
|
|
|
|
"run_count": 3,
|
|
|
|
"results_regexp": "^Richards: (.+)$"},
|
|
|
|
{"name": "NavierStokes",
|
|
|
|
"path": ["navier_stokes"],
|
|
|
|
"main": "run.js",
|
|
|
|
"results_regexp": "^NavierStokes: (.+)$"}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
Path pieces are concatenated. D8 is always run with the suite's path as cwd.
|
2014-11-28 10:34:28 +00:00
|
|
|
|
|
|
|
The test flags are passed to the js test file after '--'.
|
2014-09-02 09:17:26 +00:00
|
|
|
"""
|
|
|
|
|
2014-10-10 07:12:38 +00:00
|
|
|
from collections import OrderedDict
|
2014-09-02 09:17:26 +00:00
|
|
|
import json
|
2014-12-02 14:23:51 +00:00
|
|
|
import logging
|
2014-09-02 09:17:26 +00:00
|
|
|
import math
|
|
|
|
import optparse
|
|
|
|
import os
|
|
|
|
import re
|
2015-09-14 23:14:20 +00:00
|
|
|
import subprocess
|
2014-09-02 09:17:26 +00:00
|
|
|
import sys
|
2018-10-09 15:45:35 +00:00
|
|
|
import traceback
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2018-08-06 12:37:39 +00:00
|
|
|
from testrunner.local import android
|
2017-11-30 12:57:45 +00:00
|
|
|
from testrunner.local import command
|
2014-09-02 09:17:26 +00:00
|
|
|
from testrunner.local import utils
|
|
|
|
|
|
|
|
ARCH_GUESS = utils.DefaultArch()
|
2015-06-29 15:07:15 +00:00
|
|
|
SUPPORTED_ARCHS = ["arm",
|
2014-09-02 09:17:26 +00:00
|
|
|
"ia32",
|
|
|
|
"mips",
|
|
|
|
"mipsel",
|
|
|
|
"x64",
|
|
|
|
"arm64"]
|
|
|
|
|
2014-10-10 07:12:38 +00:00
|
|
|
GENERIC_RESULTS_RE = re.compile(r"^RESULT ([^:]+): ([^=]+)= ([^ ]+) ([^ ]*)$")
|
|
|
|
RESULT_STDDEV_RE = re.compile(r"^\{([^\}]+)\}$")
|
|
|
|
RESULT_LIST_RE = re.compile(r"^\[([^\]]+)\]$")
|
2015-09-15 08:15:54 +00:00
|
|
|
TOOLS_BASE = os.path.abspath(os.path.dirname(__file__))
|
2018-10-09 15:45:35 +00:00
|
|
|
INFRA_FAILURE_RETCODE = 87
|
2016-07-08 17:30:11 +00:00
|
|
|
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
def GeometricMean(values):
|
|
|
|
"""Returns the geometric mean of a list of values.
|
|
|
|
|
|
|
|
The mean is calculated using log to avoid overflow.
|
|
|
|
"""
|
|
|
|
values = map(float, values)
|
|
|
|
return str(math.exp(sum(map(math.log, values)) / len(values)))
|
|
|
|
|
|
|
|
|
2018-10-30 14:23:38 +00:00
|
|
|
class TestFailedError(Exception):
|
|
|
|
"""Error raised when a test has failed due to a non-infra issue."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2014-09-02 09:17:26 +00:00
|
|
|
class Results(object):
|
|
|
|
"""Place holder for result traces."""
|
|
|
|
def __init__(self, traces=None, errors=None):
|
|
|
|
self.traces = traces or []
|
|
|
|
self.errors = errors or []
|
|
|
|
|
|
|
|
def ToDict(self):
|
|
|
|
return {"traces": self.traces, "errors": self.errors}
|
|
|
|
|
|
|
|
def WriteToFile(self, file_name):
|
|
|
|
with open(file_name, "w") as f:
|
|
|
|
f.write(json.dumps(self.ToDict()))
|
|
|
|
|
|
|
|
def __add__(self, other):
|
|
|
|
self.traces += other.traces
|
|
|
|
self.errors += other.errors
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __str__(self): # pragma: no cover
|
|
|
|
return str(self.ToDict())
|
|
|
|
|
|
|
|
|
2015-07-08 12:31:29 +00:00
|
|
|
class Measurement(object):
|
|
|
|
"""Represents a series of results of one trace.
|
|
|
|
|
|
|
|
The results are from repetitive runs of the same executable. They are
|
|
|
|
gathered by repeated calls to ConsumeOutput.
|
|
|
|
"""
|
|
|
|
def __init__(self, graphs, units, results_regexp, stddev_regexp):
|
2017-01-04 23:36:06 +00:00
|
|
|
self.name = '/'.join(graphs)
|
2015-07-08 12:31:29 +00:00
|
|
|
self.graphs = graphs
|
|
|
|
self.units = units
|
|
|
|
self.results_regexp = results_regexp
|
|
|
|
self.stddev_regexp = stddev_regexp
|
|
|
|
self.results = []
|
|
|
|
self.errors = []
|
|
|
|
self.stddev = ""
|
2017-07-17 15:08:54 +00:00
|
|
|
self.process_size = False
|
2015-07-08 12:31:29 +00:00
|
|
|
|
|
|
|
def ConsumeOutput(self, stdout):
|
|
|
|
try:
|
|
|
|
result = re.search(self.results_regexp, stdout, re.M).group(1)
|
|
|
|
self.results.append(str(float(result)))
|
|
|
|
except ValueError:
|
|
|
|
self.errors.append("Regexp \"%s\" returned a non-numeric for test %s."
|
|
|
|
% (self.results_regexp, self.name))
|
|
|
|
except:
|
|
|
|
self.errors.append("Regexp \"%s\" didn't match for test %s."
|
|
|
|
% (self.results_regexp, self.name))
|
|
|
|
|
|
|
|
try:
|
|
|
|
if self.stddev_regexp and self.stddev:
|
|
|
|
self.errors.append("Test %s should only run once since a stddev "
|
|
|
|
"is provided by the test." % self.name)
|
|
|
|
if self.stddev_regexp:
|
|
|
|
self.stddev = re.search(self.stddev_regexp, stdout, re.M).group(1)
|
|
|
|
except:
|
|
|
|
self.errors.append("Regexp \"%s\" didn't match for test %s."
|
|
|
|
% (self.stddev_regexp, self.name))
|
|
|
|
|
|
|
|
def GetResults(self):
|
|
|
|
return Results([{
|
|
|
|
"graphs": self.graphs,
|
|
|
|
"units": self.units,
|
|
|
|
"results": self.results,
|
|
|
|
"stddev": self.stddev,
|
|
|
|
}], self.errors)
|
|
|
|
|
|
|
|
|
2015-07-10 13:02:09 +00:00
|
|
|
class NullMeasurement(object):
|
2017-11-21 16:10:50 +00:00
|
|
|
"""Null object to avoid having extra logic for configurations that don't
|
|
|
|
require secondary run, e.g. CI bots.
|
2015-07-10 13:02:09 +00:00
|
|
|
"""
|
|
|
|
def ConsumeOutput(self, stdout):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def GetResults(self):
|
|
|
|
return Results()
|
|
|
|
|
|
|
|
|
|
|
|
def Unzip(iterable):
|
|
|
|
left = []
|
|
|
|
right = []
|
|
|
|
for l, r in iterable:
|
|
|
|
left.append(l)
|
|
|
|
right.append(r)
|
|
|
|
return lambda: iter(left), lambda: iter(right)
|
|
|
|
|
|
|
|
|
2017-02-16 13:48:31 +00:00
|
|
|
def RunResultsProcessor(results_processor, stdout, count):
|
|
|
|
# Dummy pass through for null-runs.
|
|
|
|
if stdout is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
# We assume the results processor is relative to the suite.
|
|
|
|
assert os.path.exists(results_processor)
|
|
|
|
p = subprocess.Popen(
|
|
|
|
[sys.executable, results_processor],
|
|
|
|
stdin=subprocess.PIPE,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
)
|
|
|
|
result, _ = p.communicate(input=stdout)
|
2018-08-01 23:10:11 +00:00
|
|
|
logging.info(">>> Processed stdout (#%d):\n%s", count, result)
|
2017-02-16 13:48:31 +00:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
2015-07-10 13:02:09 +00:00
|
|
|
def AccumulateResults(
|
2017-11-21 16:10:50 +00:00
|
|
|
graph_names, trace_configs, iter_output, perform_measurement, calc_total):
|
2015-07-08 12:31:29 +00:00
|
|
|
"""Iterates over the output of multiple benchmark reruns and accumulates
|
|
|
|
results for a configured list of traces.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
graph_names: List of names that configure the base path of the traces. E.g.
|
|
|
|
['v8', 'Octane'].
|
|
|
|
trace_configs: List of "TraceConfig" instances. Each trace config defines
|
|
|
|
how to perform a measurement.
|
|
|
|
iter_output: Iterator over the standard output of each test run.
|
2017-11-21 16:10:50 +00:00
|
|
|
perform_measurement: Whether to actually run tests and perform measurements.
|
|
|
|
This is needed so that we reuse this script for both CI
|
|
|
|
and trybot, but want to ignore second run on CI without
|
|
|
|
having to spread this logic throughout the script.
|
2015-07-08 12:31:29 +00:00
|
|
|
calc_total: Boolean flag to speficy the calculation of a summary trace.
|
|
|
|
Returns: A "Results" object.
|
|
|
|
"""
|
2015-07-10 13:02:09 +00:00
|
|
|
measurements = [
|
2017-11-21 16:10:50 +00:00
|
|
|
trace.CreateMeasurement(perform_measurement) for trace in trace_configs]
|
2015-07-08 12:31:29 +00:00
|
|
|
for stdout in iter_output():
|
|
|
|
for measurement in measurements:
|
|
|
|
measurement.ConsumeOutput(stdout)
|
|
|
|
|
|
|
|
res = reduce(lambda r, m: r + m.GetResults(), measurements, Results())
|
|
|
|
|
|
|
|
if not res.traces or not calc_total:
|
|
|
|
return res
|
|
|
|
|
|
|
|
# Assume all traces have the same structure.
|
|
|
|
if len(set(map(lambda t: len(t["results"]), res.traces))) != 1:
|
|
|
|
res.errors.append("Not all traces have the same number of results.")
|
|
|
|
return res
|
|
|
|
|
|
|
|
# Calculate the geometric means for all traces. Above we made sure that
|
|
|
|
# there is at least one trace and that the number of results is the same
|
|
|
|
# for each trace.
|
|
|
|
n_results = len(res.traces[0]["results"])
|
|
|
|
total_results = [GeometricMean(t["results"][i] for t in res.traces)
|
|
|
|
for i in range(0, n_results)]
|
|
|
|
res.traces.append({
|
|
|
|
"graphs": graph_names + ["Total"],
|
|
|
|
"units": res.traces[0]["units"],
|
|
|
|
"results": total_results,
|
|
|
|
"stddev": "",
|
|
|
|
})
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
def AccumulateGenericResults(graph_names, suite_units, iter_output):
|
|
|
|
"""Iterates over the output of multiple benchmark reruns and accumulates
|
|
|
|
generic results.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
graph_names: List of names that configure the base path of the traces. E.g.
|
|
|
|
['v8', 'Octane'].
|
|
|
|
suite_units: Measurement default units as defined by the benchmark suite.
|
|
|
|
iter_output: Iterator over the standard output of each test run.
|
|
|
|
Returns: A "Results" object.
|
|
|
|
"""
|
|
|
|
traces = OrderedDict()
|
|
|
|
for stdout in iter_output():
|
2015-07-10 13:02:09 +00:00
|
|
|
if stdout is None:
|
|
|
|
# The None value is used as a null object to simplify logic.
|
|
|
|
continue
|
2015-07-08 12:31:29 +00:00
|
|
|
for line in stdout.strip().splitlines():
|
|
|
|
match = GENERIC_RESULTS_RE.match(line)
|
|
|
|
if match:
|
|
|
|
stddev = ""
|
|
|
|
graph = match.group(1)
|
|
|
|
trace = match.group(2)
|
|
|
|
body = match.group(3)
|
|
|
|
units = match.group(4)
|
|
|
|
match_stddev = RESULT_STDDEV_RE.match(body)
|
|
|
|
match_list = RESULT_LIST_RE.match(body)
|
|
|
|
errors = []
|
|
|
|
if match_stddev:
|
|
|
|
result, stddev = map(str.strip, match_stddev.group(1).split(","))
|
|
|
|
results = [result]
|
|
|
|
elif match_list:
|
|
|
|
results = map(str.strip, match_list.group(1).split(","))
|
|
|
|
else:
|
|
|
|
results = [body.strip()]
|
|
|
|
|
|
|
|
try:
|
|
|
|
results = map(lambda r: str(float(r)), results)
|
|
|
|
except ValueError:
|
|
|
|
results = []
|
|
|
|
errors = ["Found non-numeric in %s" %
|
|
|
|
"/".join(graph_names + [graph, trace])]
|
|
|
|
|
|
|
|
trace_result = traces.setdefault(trace, Results([{
|
|
|
|
"graphs": graph_names + [graph, trace],
|
|
|
|
"units": (units or suite_units).strip(),
|
|
|
|
"results": [],
|
|
|
|
"stddev": "",
|
|
|
|
}], errors))
|
|
|
|
trace_result.traces[0]["results"].extend(results)
|
|
|
|
trace_result.traces[0]["stddev"] = stddev
|
|
|
|
|
|
|
|
return reduce(lambda r, t: r + t, traces.itervalues(), Results())
|
|
|
|
|
|
|
|
|
2014-09-02 09:17:26 +00:00
|
|
|
class Node(object):
|
|
|
|
"""Represents a node in the suite tree structure."""
|
|
|
|
def __init__(self, *args):
|
|
|
|
self._children = []
|
|
|
|
|
|
|
|
def AppendChild(self, child):
|
|
|
|
self._children.append(child)
|
|
|
|
|
|
|
|
|
|
|
|
class DefaultSentinel(Node):
|
|
|
|
"""Fake parent node with all default values."""
|
2016-02-01 20:27:23 +00:00
|
|
|
def __init__(self, binary = "d8"):
|
2014-09-02 09:17:26 +00:00
|
|
|
super(DefaultSentinel, self).__init__()
|
2016-02-01 20:27:23 +00:00
|
|
|
self.binary = binary
|
2014-09-02 09:17:26 +00:00
|
|
|
self.run_count = 10
|
2014-09-15 13:00:32 +00:00
|
|
|
self.timeout = 60
|
2014-09-02 09:17:26 +00:00
|
|
|
self.path = []
|
|
|
|
self.graphs = []
|
|
|
|
self.flags = []
|
2014-11-28 10:34:28 +00:00
|
|
|
self.test_flags = []
|
2017-07-17 15:08:54 +00:00
|
|
|
self.process_size = False
|
2014-09-02 09:17:26 +00:00
|
|
|
self.resources = []
|
2017-02-16 13:48:31 +00:00
|
|
|
self.results_processor = None
|
2014-09-02 09:17:26 +00:00
|
|
|
self.results_regexp = None
|
|
|
|
self.stddev_regexp = None
|
|
|
|
self.units = "score"
|
|
|
|
self.total = False
|
2018-05-14 09:53:47 +00:00
|
|
|
self.owners = []
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
|
2015-07-08 12:31:29 +00:00
|
|
|
class GraphConfig(Node):
|
2014-09-02 09:17:26 +00:00
|
|
|
"""Represents a suite definition.
|
|
|
|
|
|
|
|
Can either be a leaf or an inner node that provides default values.
|
|
|
|
"""
|
|
|
|
def __init__(self, suite, parent, arch):
|
2015-07-08 12:31:29 +00:00
|
|
|
super(GraphConfig, self).__init__()
|
2014-09-02 09:17:26 +00:00
|
|
|
self._suite = suite
|
|
|
|
|
|
|
|
assert isinstance(suite.get("path", []), list)
|
2018-05-11 16:12:21 +00:00
|
|
|
assert isinstance(suite.get("owners", []), list)
|
2014-09-02 09:17:26 +00:00
|
|
|
assert isinstance(suite["name"], basestring)
|
|
|
|
assert isinstance(suite.get("flags", []), list)
|
2014-11-28 10:34:28 +00:00
|
|
|
assert isinstance(suite.get("test_flags", []), list)
|
2014-09-02 09:17:26 +00:00
|
|
|
assert isinstance(suite.get("resources", []), list)
|
|
|
|
|
|
|
|
# Accumulated values.
|
|
|
|
self.path = parent.path[:] + suite.get("path", [])
|
|
|
|
self.graphs = parent.graphs[:] + [suite["name"]]
|
|
|
|
self.flags = parent.flags[:] + suite.get("flags", [])
|
2014-11-28 10:34:28 +00:00
|
|
|
self.test_flags = parent.test_flags[:] + suite.get("test_flags", [])
|
2018-05-11 16:12:21 +00:00
|
|
|
self.owners = parent.owners[:] + suite.get("owners", [])
|
2014-12-04 10:37:36 +00:00
|
|
|
|
|
|
|
# Values independent of parent node.
|
|
|
|
self.resources = suite.get("resources", [])
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
# Descrete values (with parent defaults).
|
|
|
|
self.binary = suite.get("binary", parent.binary)
|
|
|
|
self.run_count = suite.get("run_count", parent.run_count)
|
|
|
|
self.run_count = suite.get("run_count_%s" % arch, self.run_count)
|
2014-09-15 13:00:32 +00:00
|
|
|
self.timeout = suite.get("timeout", parent.timeout)
|
2014-12-02 14:23:51 +00:00
|
|
|
self.timeout = suite.get("timeout_%s" % arch, self.timeout)
|
2014-09-02 09:17:26 +00:00
|
|
|
self.units = suite.get("units", parent.units)
|
|
|
|
self.total = suite.get("total", parent.total)
|
2017-02-16 13:48:31 +00:00
|
|
|
self.results_processor = suite.get(
|
|
|
|
"results_processor", parent.results_processor)
|
2017-07-17 15:08:54 +00:00
|
|
|
self.process_size = suite.get("process_size", parent.process_size)
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
# A regular expression for results. If the parent graph provides a
|
|
|
|
# regexp and the current suite has none, a string place holder for the
|
|
|
|
# suite name is expected.
|
|
|
|
# TODO(machenbach): Currently that makes only sense for the leaf level.
|
|
|
|
# Multiple place holders for multiple levels are not supported.
|
|
|
|
if parent.results_regexp:
|
2016-02-16 12:56:21 +00:00
|
|
|
regexp_default = parent.results_regexp % re.escape(suite["name"])
|
2014-09-02 09:17:26 +00:00
|
|
|
else:
|
|
|
|
regexp_default = None
|
|
|
|
self.results_regexp = suite.get("results_regexp", regexp_default)
|
|
|
|
|
|
|
|
# A similar regular expression for the standard deviation (optional).
|
|
|
|
if parent.stddev_regexp:
|
|
|
|
stddev_default = parent.stddev_regexp % re.escape(suite["name"])
|
|
|
|
else:
|
|
|
|
stddev_default = None
|
|
|
|
self.stddev_regexp = suite.get("stddev_regexp", stddev_default)
|
|
|
|
|
|
|
|
|
2015-07-08 12:31:29 +00:00
|
|
|
class TraceConfig(GraphConfig):
|
|
|
|
"""Represents a leaf in the suite tree structure."""
|
2014-09-02 09:17:26 +00:00
|
|
|
def __init__(self, suite, parent, arch):
|
2015-07-08 12:31:29 +00:00
|
|
|
super(TraceConfig, self).__init__(suite, parent, arch)
|
2014-09-02 09:17:26 +00:00
|
|
|
assert self.results_regexp
|
2018-05-11 16:12:21 +00:00
|
|
|
assert self.owners
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2017-11-21 16:10:50 +00:00
|
|
|
def CreateMeasurement(self, perform_measurement):
|
|
|
|
if not perform_measurement:
|
2015-07-10 13:02:09 +00:00
|
|
|
return NullMeasurement()
|
|
|
|
|
2015-07-08 12:31:29 +00:00
|
|
|
return Measurement(
|
|
|
|
self.graphs,
|
|
|
|
self.units,
|
|
|
|
self.results_regexp,
|
|
|
|
self.stddev_regexp,
|
|
|
|
)
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
|
2015-07-08 12:31:29 +00:00
|
|
|
class RunnableConfig(GraphConfig):
|
2014-09-02 09:17:26 +00:00
|
|
|
"""Represents a runnable suite definition (i.e. has a main file).
|
|
|
|
"""
|
|
|
|
@property
|
|
|
|
def main(self):
|
|
|
|
return self._suite.get("main", "")
|
|
|
|
|
2017-02-16 13:48:31 +00:00
|
|
|
def PostProcess(self, stdouts_iter):
|
|
|
|
if self.results_processor:
|
|
|
|
def it():
|
|
|
|
for i, stdout in enumerate(stdouts_iter()):
|
|
|
|
yield RunResultsProcessor(self.results_processor, stdout, i + 1)
|
|
|
|
return it
|
|
|
|
else:
|
|
|
|
return stdouts_iter
|
|
|
|
|
2014-09-02 09:17:26 +00:00
|
|
|
def ChangeCWD(self, suite_path):
|
|
|
|
"""Changes the cwd to to path defined in the current graph.
|
|
|
|
|
|
|
|
The tests are supposed to be relative to the suite configuration.
|
|
|
|
"""
|
|
|
|
suite_dir = os.path.abspath(os.path.dirname(suite_path))
|
|
|
|
bench_dir = os.path.normpath(os.path.join(*self.path))
|
|
|
|
os.chdir(os.path.join(suite_dir, bench_dir))
|
|
|
|
|
2015-05-13 10:00:43 +00:00
|
|
|
def GetCommandFlags(self, extra_flags=None):
|
2014-12-02 14:23:51 +00:00
|
|
|
suffix = ["--"] + self.test_flags if self.test_flags else []
|
2015-05-13 10:00:43 +00:00
|
|
|
return self.flags + (extra_flags or []) + [self.main] + suffix
|
2014-12-02 14:23:51 +00:00
|
|
|
|
2017-11-30 12:57:45 +00:00
|
|
|
def GetCommand(self, cmd_prefix, shell_dir, extra_flags=None):
|
2014-09-02 09:17:26 +00:00
|
|
|
# TODO(machenbach): This requires +.exe if run on windows.
|
2015-09-14 23:14:20 +00:00
|
|
|
extra_flags = extra_flags or []
|
2015-09-15 08:15:54 +00:00
|
|
|
if self.binary != 'd8' and '--prof' in extra_flags:
|
2018-08-01 23:10:11 +00:00
|
|
|
logging.info("Profiler supported only on a benchmark run with d8")
|
2017-11-30 12:57:45 +00:00
|
|
|
|
|
|
|
if self.process_size:
|
|
|
|
cmd_prefix = ["/usr/bin/time", "--format=MaxMemory: %MKB"] + cmd_prefix
|
|
|
|
if self.binary.endswith('.py'):
|
|
|
|
# Copy cmd_prefix instead of update (+=).
|
|
|
|
cmd_prefix = cmd_prefix + [sys.executable]
|
|
|
|
|
|
|
|
return command.Command(
|
|
|
|
cmd_prefix=cmd_prefix,
|
|
|
|
shell=os.path.join(shell_dir, self.binary),
|
|
|
|
args=self.GetCommandFlags(extra_flags=extra_flags),
|
|
|
|
timeout=self.timeout or 60)
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2015-07-10 13:02:09 +00:00
|
|
|
def Run(self, runner, trybot):
|
2014-09-02 09:17:26 +00:00
|
|
|
"""Iterates over several runs and handles the output for all traces."""
|
2017-11-21 16:10:50 +00:00
|
|
|
stdout, stdout_secondary = Unzip(runner())
|
2015-07-10 13:02:09 +00:00
|
|
|
return (
|
|
|
|
AccumulateResults(
|
|
|
|
self.graphs,
|
|
|
|
self._children,
|
2017-11-21 16:10:50 +00:00
|
|
|
iter_output=self.PostProcess(stdout),
|
|
|
|
perform_measurement=True,
|
2015-07-10 13:02:09 +00:00
|
|
|
calc_total=self.total,
|
|
|
|
),
|
|
|
|
AccumulateResults(
|
|
|
|
self.graphs,
|
|
|
|
self._children,
|
2017-11-21 16:10:50 +00:00
|
|
|
iter_output=self.PostProcess(stdout_secondary),
|
|
|
|
perform_measurement=trybot, # only run second time on trybots
|
2015-07-10 13:02:09 +00:00
|
|
|
calc_total=self.total,
|
|
|
|
),
|
|
|
|
)
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2015-07-08 12:31:29 +00:00
|
|
|
|
|
|
|
class RunnableTraceConfig(TraceConfig, RunnableConfig):
|
2014-09-02 09:17:26 +00:00
|
|
|
"""Represents a runnable suite definition that is a leaf."""
|
|
|
|
def __init__(self, suite, parent, arch):
|
2015-07-08 12:31:29 +00:00
|
|
|
super(RunnableTraceConfig, self).__init__(suite, parent, arch)
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2015-07-10 13:02:09 +00:00
|
|
|
def Run(self, runner, trybot):
|
2014-09-02 09:17:26 +00:00
|
|
|
"""Iterates over several runs and handles the output."""
|
2017-11-21 16:10:50 +00:00
|
|
|
measurement = self.CreateMeasurement(perform_measurement=True)
|
|
|
|
measurement_secondary = self.CreateMeasurement(perform_measurement=trybot)
|
|
|
|
for stdout, stdout_secondary in runner():
|
|
|
|
measurement.ConsumeOutput(stdout)
|
|
|
|
measurement_secondary.ConsumeOutput(stdout_secondary)
|
2015-07-10 13:02:09 +00:00
|
|
|
return (
|
2017-11-21 16:10:50 +00:00
|
|
|
measurement.GetResults(),
|
|
|
|
measurement_secondary.GetResults(),
|
2015-07-10 13:02:09 +00:00
|
|
|
)
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
|
2015-07-08 12:31:29 +00:00
|
|
|
class RunnableGenericConfig(RunnableConfig):
|
2014-09-02 09:17:26 +00:00
|
|
|
"""Represents a runnable suite definition with generic traces."""
|
|
|
|
def __init__(self, suite, parent, arch):
|
2015-07-08 12:31:29 +00:00
|
|
|
super(RunnableGenericConfig, self).__init__(suite, parent, arch)
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2015-07-10 13:02:09 +00:00
|
|
|
def Run(self, runner, trybot):
|
2017-11-21 16:10:50 +00:00
|
|
|
stdout, stdout_secondary = Unzip(runner())
|
2015-07-10 13:02:09 +00:00
|
|
|
return (
|
2017-11-21 16:10:50 +00:00
|
|
|
AccumulateGenericResults(self.graphs, self.units, stdout),
|
|
|
|
AccumulateGenericResults(self.graphs, self.units, stdout_secondary),
|
2015-07-10 13:02:09 +00:00
|
|
|
)
|
2015-07-08 12:31:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def MakeGraphConfig(suite, arch, parent):
|
|
|
|
"""Factory method for making graph configuration objects."""
|
|
|
|
if isinstance(parent, RunnableConfig):
|
2014-09-02 09:17:26 +00:00
|
|
|
# Below a runnable can only be traces.
|
2015-07-08 12:31:29 +00:00
|
|
|
return TraceConfig(suite, parent, arch)
|
2015-04-10 09:48:54 +00:00
|
|
|
elif suite.get("main") is not None:
|
|
|
|
# A main file makes this graph runnable. Empty strings are accepted.
|
2014-09-02 09:17:26 +00:00
|
|
|
if suite.get("tests"):
|
|
|
|
# This graph has subgraphs (traces).
|
2015-07-08 12:31:29 +00:00
|
|
|
return RunnableConfig(suite, parent, arch)
|
2014-09-02 09:17:26 +00:00
|
|
|
else:
|
|
|
|
# This graph has no subgraphs, it's a leaf.
|
2015-07-08 12:31:29 +00:00
|
|
|
return RunnableTraceConfig(suite, parent, arch)
|
2014-09-02 09:17:26 +00:00
|
|
|
elif suite.get("generic"):
|
|
|
|
# This is a generic suite definition. It is either a runnable executable
|
|
|
|
# or has a main js file.
|
2015-07-08 12:31:29 +00:00
|
|
|
return RunnableGenericConfig(suite, parent, arch)
|
2014-09-02 09:17:26 +00:00
|
|
|
elif suite.get("tests"):
|
|
|
|
# This is neither a leaf nor a runnable.
|
2015-07-08 12:31:29 +00:00
|
|
|
return GraphConfig(suite, parent, arch)
|
2014-09-02 09:17:26 +00:00
|
|
|
else: # pragma: no cover
|
|
|
|
raise Exception("Invalid suite configuration.")
|
|
|
|
|
|
|
|
|
2016-02-01 20:27:23 +00:00
|
|
|
def BuildGraphConfigs(suite, arch, parent):
|
2014-09-02 09:17:26 +00:00
|
|
|
"""Builds a tree structure of graph objects that corresponds to the suite
|
|
|
|
configuration.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# TODO(machenbach): Implement notion of cpu type?
|
2014-12-02 14:23:51 +00:00
|
|
|
if arch not in suite.get("archs", SUPPORTED_ARCHS):
|
2014-09-02 09:17:26 +00:00
|
|
|
return None
|
|
|
|
|
2015-07-08 12:31:29 +00:00
|
|
|
graph = MakeGraphConfig(suite, arch, parent)
|
2014-09-02 09:17:26 +00:00
|
|
|
for subsuite in suite.get("tests", []):
|
2015-07-08 12:31:29 +00:00
|
|
|
BuildGraphConfigs(subsuite, arch, graph)
|
2014-09-02 09:17:26 +00:00
|
|
|
parent.AppendChild(graph)
|
|
|
|
return graph
|
|
|
|
|
|
|
|
|
2014-12-03 15:34:53 +00:00
|
|
|
def FlattenRunnables(node, node_cb):
|
2014-09-02 09:17:26 +00:00
|
|
|
"""Generator that traverses the tree structure and iterates over all
|
|
|
|
runnables.
|
|
|
|
"""
|
2014-12-03 15:34:53 +00:00
|
|
|
node_cb(node)
|
2015-07-08 12:31:29 +00:00
|
|
|
if isinstance(node, RunnableConfig):
|
2014-09-02 09:17:26 +00:00
|
|
|
yield node
|
|
|
|
elif isinstance(node, Node):
|
|
|
|
for child in node._children:
|
2014-12-03 15:34:53 +00:00
|
|
|
for result in FlattenRunnables(child, node_cb):
|
2014-09-02 09:17:26 +00:00
|
|
|
yield result
|
|
|
|
else: # pragma: no cover
|
|
|
|
raise Exception("Invalid suite configuration.")
|
|
|
|
|
|
|
|
|
2014-11-28 18:39:41 +00:00
|
|
|
class Platform(object):
|
2015-05-18 15:11:05 +00:00
|
|
|
def __init__(self, options):
|
|
|
|
self.shell_dir = options.shell_dir
|
2017-11-21 16:10:50 +00:00
|
|
|
self.shell_dir_secondary = options.shell_dir_secondary
|
2015-05-18 15:11:05 +00:00
|
|
|
self.extra_flags = options.extra_flags.split()
|
2018-08-11 09:02:00 +00:00
|
|
|
self.options = options
|
2015-05-18 15:11:05 +00:00
|
|
|
|
2018-07-25 11:20:08 +00:00
|
|
|
@staticmethod
|
|
|
|
def ReadBuildConfig(options):
|
|
|
|
config_path = os.path.join(options.shell_dir, 'v8_build_config.json')
|
|
|
|
if not os.path.isfile(config_path):
|
|
|
|
return {}
|
|
|
|
with open(config_path) as f:
|
|
|
|
return json.load(f)
|
|
|
|
|
2014-11-28 18:39:41 +00:00
|
|
|
@staticmethod
|
|
|
|
def GetPlatform(options):
|
2018-07-25 11:20:08 +00:00
|
|
|
if Platform.ReadBuildConfig(options).get('is_android', False):
|
2014-11-28 18:39:41 +00:00
|
|
|
return AndroidPlatform(options)
|
|
|
|
else:
|
|
|
|
return DesktopPlatform(options)
|
|
|
|
|
2017-11-21 16:10:50 +00:00
|
|
|
def _Run(self, runnable, count, secondary=False):
|
2015-07-10 13:02:09 +00:00
|
|
|
raise NotImplementedError() # pragma: no cover
|
|
|
|
|
|
|
|
def Run(self, runnable, count):
|
|
|
|
"""Execute the benchmark's main file.
|
|
|
|
|
2017-11-21 16:10:50 +00:00
|
|
|
If options.shell_dir_secondary is specified, the benchmark is run twice,
|
|
|
|
e.g. with and without patch.
|
2015-07-10 13:02:09 +00:00
|
|
|
Args:
|
|
|
|
runnable: A Runnable benchmark instance.
|
|
|
|
count: The number of this (repeated) run.
|
2017-11-21 16:10:50 +00:00
|
|
|
Returns: A tuple with the two benchmark outputs. The latter will be None if
|
|
|
|
options.shell_dir_secondary was not specified.
|
2015-07-10 13:02:09 +00:00
|
|
|
"""
|
2017-11-21 16:10:50 +00:00
|
|
|
stdout = self._Run(runnable, count, secondary=False)
|
|
|
|
if self.shell_dir_secondary:
|
|
|
|
return stdout, self._Run(runnable, count, secondary=True)
|
2015-07-10 13:02:09 +00:00
|
|
|
else:
|
|
|
|
return stdout, None
|
|
|
|
|
2014-11-28 18:39:41 +00:00
|
|
|
|
|
|
|
class DesktopPlatform(Platform):
|
|
|
|
def __init__(self, options):
|
2015-05-18 15:11:05 +00:00
|
|
|
super(DesktopPlatform, self).__init__(options)
|
2016-04-29 15:51:05 +00:00
|
|
|
self.command_prefix = []
|
|
|
|
|
2018-08-10 17:09:34 +00:00
|
|
|
# Setup command class to OS specific version.
|
|
|
|
command.setup(utils.GuessOS())
|
|
|
|
|
2016-04-29 15:51:05 +00:00
|
|
|
if options.prioritize or options.affinitize != None:
|
|
|
|
self.command_prefix = ["schedtool"]
|
|
|
|
if options.prioritize:
|
|
|
|
self.command_prefix += ["-n", "-20"]
|
|
|
|
if options.affinitize != None:
|
|
|
|
# schedtool expects a bit pattern when setting affinity, where each
|
|
|
|
# bit set to '1' corresponds to a core where the process may run on.
|
|
|
|
# First bit corresponds to CPU 0. Since the 'affinitize' parameter is
|
|
|
|
# a core number, we need to map to said bit pattern.
|
|
|
|
cpu = int(options.affinitize)
|
|
|
|
core = 1 << cpu
|
|
|
|
self.command_prefix += ["-a", ("0x%x" % core)]
|
|
|
|
self.command_prefix += ["-e"]
|
2014-11-28 18:39:41 +00:00
|
|
|
|
2016-02-16 12:56:21 +00:00
|
|
|
def PreExecution(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def PostExecution(self):
|
|
|
|
pass
|
2014-11-28 18:39:41 +00:00
|
|
|
|
2014-12-03 15:34:53 +00:00
|
|
|
def PreTests(self, node, path):
|
2015-07-08 12:31:29 +00:00
|
|
|
if isinstance(node, RunnableConfig):
|
2014-12-03 15:34:53 +00:00
|
|
|
node.ChangeCWD(path)
|
2014-11-28 18:39:41 +00:00
|
|
|
|
2017-11-21 16:10:50 +00:00
|
|
|
def _Run(self, runnable, count, secondary=False):
|
|
|
|
suffix = ' - secondary' if secondary else ''
|
|
|
|
shell_dir = self.shell_dir_secondary if secondary else self.shell_dir
|
2015-07-10 13:02:09 +00:00
|
|
|
title = ">>> %%s (#%d)%s:" % ((count + 1), suffix)
|
2017-11-30 12:57:45 +00:00
|
|
|
cmd = runnable.GetCommand(self.command_prefix, shell_dir, self.extra_flags)
|
2015-04-10 12:01:20 +00:00
|
|
|
try:
|
2017-11-30 12:57:45 +00:00
|
|
|
output = cmd.execute()
|
2018-08-01 23:10:11 +00:00
|
|
|
except OSError: # pragma: no cover
|
|
|
|
logging.exception(title % "OSError")
|
2018-10-30 14:23:38 +00:00
|
|
|
raise
|
2016-04-29 15:51:05 +00:00
|
|
|
|
2018-08-01 23:10:11 +00:00
|
|
|
logging.info(title % "Stdout" + "\n%s", output.stdout)
|
2014-11-28 18:39:41 +00:00
|
|
|
if output.stderr: # pragma: no cover
|
|
|
|
# Print stderr for debugging.
|
2018-08-01 23:10:11 +00:00
|
|
|
logging.info(title % "Stderr" + "\n%s", output.stderr)
|
2014-11-28 18:39:41 +00:00
|
|
|
if output.timed_out:
|
2018-08-01 23:10:11 +00:00
|
|
|
logging.warning(">>> Test timed out after %ss.", runnable.timeout)
|
2018-10-30 14:23:38 +00:00
|
|
|
raise TestFailedError()
|
|
|
|
if output.exit_code != 0:
|
|
|
|
logging.warning(">>> Test crashed.")
|
|
|
|
raise TestFailedError()
|
2015-09-14 23:14:20 +00:00
|
|
|
if '--prof' in self.extra_flags:
|
2015-09-15 08:15:54 +00:00
|
|
|
os_prefix = {"linux": "linux", "macos": "mac"}.get(utils.GuessOS())
|
|
|
|
if os_prefix:
|
|
|
|
tick_tools = os.path.join(TOOLS_BASE, "%s-tick-processor" % os_prefix)
|
|
|
|
subprocess.check_call(tick_tools + " --only-summary", shell=True)
|
|
|
|
else: # pragma: no cover
|
2018-08-01 23:10:11 +00:00
|
|
|
logging.warning(
|
|
|
|
"Profiler option currently supported on Linux and Mac OS.")
|
2017-07-17 15:08:54 +00:00
|
|
|
|
|
|
|
# time outputs to stderr
|
|
|
|
if runnable.process_size:
|
|
|
|
return output.stdout + output.stderr
|
2014-11-28 18:39:41 +00:00
|
|
|
return output.stdout
|
|
|
|
|
|
|
|
|
2014-12-02 14:23:51 +00:00
|
|
|
class AndroidPlatform(Platform): # pragma: no cover
|
|
|
|
|
2014-11-28 18:39:41 +00:00
|
|
|
def __init__(self, options):
|
2015-05-18 15:11:05 +00:00
|
|
|
super(AndroidPlatform, self).__init__(options)
|
2018-08-06 12:37:39 +00:00
|
|
|
self.driver = android.android_driver(options.device)
|
2014-12-02 14:23:51 +00:00
|
|
|
|
|
|
|
def PreExecution(self):
|
2018-08-06 12:37:39 +00:00
|
|
|
self.driver.set_high_perf_mode()
|
2014-12-03 15:34:53 +00:00
|
|
|
|
2014-12-02 14:23:51 +00:00
|
|
|
def PostExecution(self):
|
2018-08-06 12:37:39 +00:00
|
|
|
self.driver.set_default_perf_mode()
|
|
|
|
self.driver.tear_down()
|
2015-02-24 14:07:15 +00:00
|
|
|
|
2015-07-10 13:02:09 +00:00
|
|
|
def PreTests(self, node, path):
|
2017-02-17 13:09:14 +00:00
|
|
|
if isinstance(node, RunnableConfig):
|
|
|
|
node.ChangeCWD(path)
|
2015-07-10 13:02:09 +00:00
|
|
|
suite_dir = os.path.abspath(os.path.dirname(path))
|
|
|
|
if node.path:
|
|
|
|
bench_rel = os.path.normpath(os.path.join(*node.path))
|
|
|
|
bench_abs = os.path.join(suite_dir, bench_rel)
|
|
|
|
else:
|
|
|
|
bench_rel = "."
|
|
|
|
bench_abs = suite_dir
|
|
|
|
|
2018-08-06 12:37:39 +00:00
|
|
|
self.driver.push_executable(self.shell_dir, "bin", node.binary)
|
2017-11-21 16:10:50 +00:00
|
|
|
if self.shell_dir_secondary:
|
2018-08-06 12:37:39 +00:00
|
|
|
self.driver.push_executable(
|
2017-11-21 16:10:50 +00:00
|
|
|
self.shell_dir_secondary, "bin_secondary", node.binary)
|
2015-07-10 13:02:09 +00:00
|
|
|
|
2015-07-08 12:31:29 +00:00
|
|
|
if isinstance(node, RunnableConfig):
|
2018-12-21 10:13:34 +00:00
|
|
|
self.driver.push_file(bench_abs, node.main, bench_rel)
|
|
|
|
for resource in node.resources:
|
|
|
|
self.driver.push_file(bench_abs, resource, bench_rel)
|
2014-12-02 14:23:51 +00:00
|
|
|
|
2017-11-21 16:10:50 +00:00
|
|
|
def _Run(self, runnable, count, secondary=False):
|
|
|
|
suffix = ' - secondary' if secondary else ''
|
|
|
|
target_dir = "bin_secondary" if secondary else "bin"
|
2015-07-10 13:02:09 +00:00
|
|
|
title = ">>> %%s (#%d)%s:" % ((count + 1), suffix)
|
2018-08-06 12:37:39 +00:00
|
|
|
self.driver.drop_ram_caches()
|
2014-12-04 10:37:36 +00:00
|
|
|
|
|
|
|
# Relative path to benchmark directory.
|
|
|
|
if runnable.path:
|
|
|
|
bench_rel = os.path.normpath(os.path.join(*runnable.path))
|
|
|
|
else:
|
|
|
|
bench_rel = "."
|
|
|
|
|
2018-08-11 09:02:00 +00:00
|
|
|
logcat_file = None
|
|
|
|
if self.options.dump_logcats_to:
|
|
|
|
runnable_name = '-'.join(runnable.graphs)
|
|
|
|
logcat_file = os.path.join(
|
|
|
|
self.options.dump_logcats_to, 'logcat-%s-#%d%s.log' % (
|
|
|
|
runnable_name, count + 1, '-secondary' if secondary else ''))
|
|
|
|
logging.debug('Dumping logcat into %s', logcat_file)
|
|
|
|
|
2014-12-02 14:23:51 +00:00
|
|
|
try:
|
2018-08-06 12:37:39 +00:00
|
|
|
stdout = self.driver.run(
|
|
|
|
target_dir=target_dir,
|
|
|
|
binary=runnable.binary,
|
|
|
|
args=runnable.GetCommandFlags(self.extra_flags),
|
|
|
|
rel_path=bench_rel,
|
2014-12-02 14:23:51 +00:00
|
|
|
timeout=runnable.timeout,
|
2018-08-11 09:02:00 +00:00
|
|
|
logcat_file=logcat_file,
|
2014-12-02 14:23:51 +00:00
|
|
|
)
|
2018-08-01 23:10:11 +00:00
|
|
|
logging.info(title % "Stdout" + "\n%s", stdout)
|
2018-08-09 06:54:56 +00:00
|
|
|
except android.CommandFailedException as e:
|
|
|
|
logging.info(title % "Stdout" + "\n%s", e.output)
|
2018-10-30 14:23:38 +00:00
|
|
|
logging.warning('>>> Test crashed.')
|
|
|
|
raise TestFailedError()
|
2018-09-12 14:57:46 +00:00
|
|
|
except android.TimeoutException as e:
|
2018-10-16 14:04:31 +00:00
|
|
|
if e.output is not None:
|
2018-09-12 14:57:46 +00:00
|
|
|
logging.info(title % "Stdout" + "\n%s", e.output)
|
2018-08-01 23:10:11 +00:00
|
|
|
logging.warning(">>> Test timed out after %ss.", runnable.timeout)
|
2018-10-30 14:23:38 +00:00
|
|
|
raise TestFailedError()
|
2017-07-17 15:08:54 +00:00
|
|
|
if runnable.process_size:
|
|
|
|
return stdout + "MaxMemory: Unsupported"
|
2014-12-02 14:23:51 +00:00
|
|
|
return stdout
|
2014-11-28 18:39:41 +00:00
|
|
|
|
2016-04-29 15:51:05 +00:00
|
|
|
class CustomMachineConfiguration:
|
|
|
|
def __init__(self, disable_aslr = False, governor = None):
|
|
|
|
self.aslr_backup = None
|
|
|
|
self.governor_backup = None
|
|
|
|
self.disable_aslr = disable_aslr
|
|
|
|
self.governor = governor
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
if self.disable_aslr:
|
|
|
|
self.aslr_backup = CustomMachineConfiguration.GetASLR()
|
|
|
|
CustomMachineConfiguration.SetASLR(0)
|
|
|
|
if self.governor != None:
|
|
|
|
self.governor_backup = CustomMachineConfiguration.GetCPUGovernor()
|
|
|
|
CustomMachineConfiguration.SetCPUGovernor(self.governor)
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, type, value, traceback):
|
|
|
|
if self.aslr_backup != None:
|
|
|
|
CustomMachineConfiguration.SetASLR(self.aslr_backup)
|
|
|
|
if self.governor_backup != None:
|
|
|
|
CustomMachineConfiguration.SetCPUGovernor(self.governor_backup)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def GetASLR():
|
|
|
|
try:
|
|
|
|
with open("/proc/sys/kernel/randomize_va_space", "r") as f:
|
|
|
|
return int(f.readline().strip())
|
2018-08-01 23:10:11 +00:00
|
|
|
except Exception:
|
|
|
|
logging.exception("Failed to get current ASLR settings.")
|
|
|
|
raise
|
2016-04-29 15:51:05 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def SetASLR(value):
|
|
|
|
try:
|
|
|
|
with open("/proc/sys/kernel/randomize_va_space", "w") as f:
|
|
|
|
f.write(str(value))
|
2018-08-01 23:10:11 +00:00
|
|
|
except Exception:
|
|
|
|
logging.exception(
|
|
|
|
"Failed to update ASLR to %s. Are we running under sudo?", value)
|
|
|
|
raise
|
2016-04-29 15:51:05 +00:00
|
|
|
|
|
|
|
new_value = CustomMachineConfiguration.GetASLR()
|
|
|
|
if value != new_value:
|
|
|
|
raise Exception("Present value is %s" % new_value)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def GetCPUCoresRange():
|
|
|
|
try:
|
|
|
|
with open("/sys/devices/system/cpu/present", "r") as f:
|
|
|
|
indexes = f.readline()
|
2016-05-20 09:07:28 +00:00
|
|
|
r = map(int, indexes.split("-"))
|
|
|
|
if len(r) == 1:
|
|
|
|
return range(r[0], r[0] + 1)
|
|
|
|
return range(r[0], r[1] + 1)
|
2018-08-01 23:10:11 +00:00
|
|
|
except Exception:
|
|
|
|
logging.exception("Failed to retrieve number of CPUs.")
|
|
|
|
raise
|
2016-04-29 15:51:05 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def GetCPUPathForId(cpu_index):
|
|
|
|
ret = "/sys/devices/system/cpu/cpu"
|
|
|
|
ret += str(cpu_index)
|
|
|
|
ret += "/cpufreq/scaling_governor"
|
|
|
|
return ret
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def GetCPUGovernor():
|
|
|
|
try:
|
|
|
|
cpu_indices = CustomMachineConfiguration.GetCPUCoresRange()
|
|
|
|
ret = None
|
|
|
|
for cpu_index in cpu_indices:
|
|
|
|
cpu_device = CustomMachineConfiguration.GetCPUPathForId(cpu_index)
|
|
|
|
with open(cpu_device, "r") as f:
|
|
|
|
# We assume the governors of all CPUs are set to the same value
|
|
|
|
val = f.readline().strip()
|
|
|
|
if ret == None:
|
|
|
|
ret = val
|
|
|
|
elif ret != val:
|
|
|
|
raise Exception("CPU cores have differing governor settings")
|
|
|
|
return ret
|
2018-08-01 23:10:11 +00:00
|
|
|
except Exception:
|
|
|
|
logging.exception("Failed to get the current CPU governor. Is the CPU "
|
|
|
|
"governor disabled? Check BIOS.")
|
|
|
|
raise
|
2016-04-29 15:51:05 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def SetCPUGovernor(value):
|
|
|
|
try:
|
|
|
|
cpu_indices = CustomMachineConfiguration.GetCPUCoresRange()
|
|
|
|
for cpu_index in cpu_indices:
|
|
|
|
cpu_device = CustomMachineConfiguration.GetCPUPathForId(cpu_index)
|
|
|
|
with open(cpu_device, "w") as f:
|
|
|
|
f.write(value)
|
|
|
|
|
2018-08-01 23:10:11 +00:00
|
|
|
except Exception:
|
|
|
|
logging.exception("Failed to change CPU governor to %s. Are we "
|
|
|
|
"running under sudo?", value)
|
|
|
|
raise
|
2016-04-29 15:51:05 +00:00
|
|
|
|
|
|
|
cur_value = CustomMachineConfiguration.GetCPUGovernor()
|
|
|
|
if cur_value != value:
|
|
|
|
raise Exception("Could not set CPU governor. Present value is %s"
|
|
|
|
% cur_value )
|
2014-11-28 18:39:41 +00:00
|
|
|
|
2014-09-02 09:17:26 +00:00
|
|
|
def Main(args):
|
|
|
|
parser = optparse.OptionParser()
|
2018-07-25 11:20:08 +00:00
|
|
|
parser.add_option("--android-build-tools", help="Deprecated.")
|
2014-09-02 09:17:26 +00:00
|
|
|
parser.add_option("--arch",
|
|
|
|
help=("The architecture to run tests for, "
|
|
|
|
"'auto' or 'native' for auto-detect"),
|
|
|
|
default="x64")
|
|
|
|
parser.add_option("--buildbot",
|
2018-08-01 23:10:11 +00:00
|
|
|
help="Adapt to path structure used on buildbots and adds "
|
|
|
|
"timestamps/level to all logged status messages",
|
2014-09-02 09:17:26 +00:00
|
|
|
default=False, action="store_true")
|
2014-11-28 18:39:41 +00:00
|
|
|
parser.add_option("--device",
|
|
|
|
help="The device ID to run Android tests on. If not given "
|
|
|
|
"it will be autodetected.")
|
2015-05-13 10:00:43 +00:00
|
|
|
parser.add_option("--extra-flags",
|
|
|
|
help="Additional flags to pass to the test executable",
|
|
|
|
default="")
|
2014-09-02 09:17:26 +00:00
|
|
|
parser.add_option("--json-test-results",
|
|
|
|
help="Path to a file for storing json results.")
|
2017-11-21 16:10:50 +00:00
|
|
|
parser.add_option("--json-test-results-secondary",
|
|
|
|
"--json-test-results-no-patch", # TODO(sergiyb): Deprecate.
|
2015-07-10 13:02:09 +00:00
|
|
|
help="Path to a file for storing json results from run "
|
2017-11-21 16:10:50 +00:00
|
|
|
"without patch or for reference build run.")
|
2014-09-02 09:17:26 +00:00
|
|
|
parser.add_option("--outdir", help="Base directory with compile output",
|
|
|
|
default="out")
|
2017-11-21 16:10:50 +00:00
|
|
|
parser.add_option("--outdir-secondary",
|
|
|
|
"--outdir-no-patch", # TODO(sergiyb): Deprecate.
|
|
|
|
help="Base directory with compile output without patch or "
|
|
|
|
"for reference build")
|
2016-02-01 20:27:23 +00:00
|
|
|
parser.add_option("--binary-override-path",
|
|
|
|
help="JavaScript engine binary. By default, d8 under "
|
|
|
|
"architecture-specific build dir. "
|
2017-11-21 16:10:50 +00:00
|
|
|
"Not supported in conjunction with outdir-secondary.")
|
2016-04-29 15:51:05 +00:00
|
|
|
parser.add_option("--prioritize",
|
|
|
|
help="Raise the priority to nice -20 for the benchmarking "
|
|
|
|
"process.Requires Linux, schedtool, and sudo privileges.",
|
|
|
|
default=False, action="store_true")
|
|
|
|
parser.add_option("--affinitize",
|
|
|
|
help="Run benchmarking process on the specified core. "
|
|
|
|
"For example: "
|
|
|
|
"--affinitize=0 will run the benchmark process on core 0. "
|
|
|
|
"--affinitize=3 will run the benchmark process on core 3. "
|
|
|
|
"Requires Linux, schedtool, and sudo privileges.",
|
|
|
|
default=None)
|
|
|
|
parser.add_option("--noaslr",
|
|
|
|
help="Disable ASLR for the duration of the benchmarked "
|
|
|
|
"process. Requires Linux and sudo privileges.",
|
|
|
|
default=False, action="store_true")
|
|
|
|
parser.add_option("--cpu-governor",
|
|
|
|
help="Set cpu governor to specified policy for the "
|
|
|
|
"duration of the benchmarked process. Typical options: "
|
|
|
|
"'powersave' for more stable results, or 'performance' "
|
|
|
|
"for shorter completion time of suite, with potentially "
|
|
|
|
"more noise in results.")
|
2017-04-27 07:57:11 +00:00
|
|
|
parser.add_option("--filter",
|
|
|
|
help="Only run the benchmarks beginning with this string. "
|
|
|
|
"For example: "
|
|
|
|
"--filter=JSTests/TypedArrays/ will run only TypedArray "
|
|
|
|
"benchmarks from the JSTests suite.",
|
|
|
|
default="")
|
2018-08-09 07:46:35 +00:00
|
|
|
parser.add_option("--run-count-multiplier", default=1, type="int",
|
|
|
|
help="Multipled used to increase number of times each test "
|
|
|
|
"is retried.")
|
2018-08-11 09:02:00 +00:00
|
|
|
parser.add_option("--dump-logcats-to",
|
|
|
|
help="Writes logcat output from each test into specified "
|
|
|
|
"directory. Only supported for android targets.")
|
2016-02-01 20:27:23 +00:00
|
|
|
|
2014-09-02 09:17:26 +00:00
|
|
|
(options, args) = parser.parse_args(args)
|
|
|
|
|
2018-10-19 15:01:51 +00:00
|
|
|
logging.basicConfig(level=logging.INFO, format="%(levelname)-8s %(message)s")
|
2018-08-01 23:10:11 +00:00
|
|
|
|
2014-09-02 09:17:26 +00:00
|
|
|
if len(args) == 0: # pragma: no cover
|
|
|
|
parser.print_help()
|
2018-10-09 15:45:35 +00:00
|
|
|
return INFRA_FAILURE_RETCODE
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
if options.arch in ["auto", "native"]: # pragma: no cover
|
|
|
|
options.arch = ARCH_GUESS
|
|
|
|
|
|
|
|
if not options.arch in SUPPORTED_ARCHS: # pragma: no cover
|
2018-08-01 23:10:11 +00:00
|
|
|
logging.error("Unknown architecture %s", options.arch)
|
2018-10-09 15:45:35 +00:00
|
|
|
return INFRA_FAILURE_RETCODE
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2017-11-21 16:10:50 +00:00
|
|
|
if (options.json_test_results_secondary and
|
|
|
|
not options.outdir_secondary): # pragma: no cover
|
2018-08-01 23:10:11 +00:00
|
|
|
logging.error("For writing secondary json test results, a secondary outdir "
|
|
|
|
"patch must be specified.")
|
2018-10-09 15:45:35 +00:00
|
|
|
return INFRA_FAILURE_RETCODE
|
2015-07-10 13:02:09 +00:00
|
|
|
|
2014-12-02 14:23:51 +00:00
|
|
|
workspace = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
|
|
|
|
if options.buildbot:
|
2015-07-10 13:02:09 +00:00
|
|
|
build_config = "Release"
|
2014-12-02 14:23:51 +00:00
|
|
|
else:
|
2015-07-10 13:02:09 +00:00
|
|
|
build_config = "%s.release" % options.arch
|
|
|
|
|
2016-02-01 20:27:23 +00:00
|
|
|
if options.binary_override_path == None:
|
|
|
|
options.shell_dir = os.path.join(workspace, options.outdir, build_config)
|
|
|
|
default_binary_name = "d8"
|
|
|
|
else:
|
|
|
|
if not os.path.isfile(options.binary_override_path):
|
2018-08-01 23:10:11 +00:00
|
|
|
logging.error("binary-override-path must be a file name")
|
2018-10-09 15:45:35 +00:00
|
|
|
return INFRA_FAILURE_RETCODE
|
2017-11-21 16:10:50 +00:00
|
|
|
if options.outdir_secondary:
|
2018-08-01 23:10:11 +00:00
|
|
|
logging.error("specify either binary-override-path or outdir-secondary")
|
2018-10-09 15:45:35 +00:00
|
|
|
return INFRA_FAILURE_RETCODE
|
2017-03-21 00:04:51 +00:00
|
|
|
options.shell_dir = os.path.abspath(
|
|
|
|
os.path.dirname(options.binary_override_path))
|
2016-02-01 20:27:23 +00:00
|
|
|
default_binary_name = os.path.basename(options.binary_override_path)
|
2015-07-10 13:02:09 +00:00
|
|
|
|
2017-11-21 16:10:50 +00:00
|
|
|
if options.outdir_secondary:
|
|
|
|
options.shell_dir_secondary = os.path.join(
|
|
|
|
workspace, options.outdir_secondary, build_config)
|
2015-07-10 13:02:09 +00:00
|
|
|
else:
|
2017-11-21 16:10:50 +00:00
|
|
|
options.shell_dir_secondary = None
|
2014-12-02 14:23:51 +00:00
|
|
|
|
2017-03-21 00:04:51 +00:00
|
|
|
if options.json_test_results:
|
|
|
|
options.json_test_results = os.path.abspath(options.json_test_results)
|
|
|
|
|
2017-11-21 16:10:50 +00:00
|
|
|
if options.json_test_results_secondary:
|
|
|
|
options.json_test_results_secondary = os.path.abspath(
|
|
|
|
options.json_test_results_secondary)
|
2017-03-21 00:04:51 +00:00
|
|
|
|
|
|
|
# Ensure all arguments have absolute path before we start changing current
|
|
|
|
# directory.
|
|
|
|
args = map(os.path.abspath, args)
|
|
|
|
|
2016-04-29 15:51:05 +00:00
|
|
|
prev_aslr = None
|
|
|
|
prev_cpu_gov = None
|
2014-11-28 18:39:41 +00:00
|
|
|
platform = Platform.GetPlatform(options)
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
results = Results()
|
2017-11-21 16:10:50 +00:00
|
|
|
results_secondary = Results()
|
2018-10-30 14:23:38 +00:00
|
|
|
# We use list here to allow modification in nested function below.
|
|
|
|
have_failed_tests = [False]
|
2016-04-29 15:51:05 +00:00
|
|
|
with CustomMachineConfiguration(governor = options.cpu_governor,
|
|
|
|
disable_aslr = options.noaslr) as conf:
|
|
|
|
for path in args:
|
|
|
|
if not os.path.exists(path): # pragma: no cover
|
|
|
|
results.errors.append("Configuration file %s does not exist." % path)
|
|
|
|
continue
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2016-04-29 15:51:05 +00:00
|
|
|
with open(path) as f:
|
|
|
|
suite = json.loads(f.read())
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2016-04-29 15:51:05 +00:00
|
|
|
# If no name is given, default to the file name without .json.
|
|
|
|
suite.setdefault("name", os.path.splitext(os.path.basename(path))[0])
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2016-04-29 15:51:05 +00:00
|
|
|
# Setup things common to one test suite.
|
|
|
|
platform.PreExecution()
|
2014-12-03 15:34:53 +00:00
|
|
|
|
2016-04-29 15:51:05 +00:00
|
|
|
# Build the graph/trace tree structure.
|
|
|
|
default_parent = DefaultSentinel(default_binary_name)
|
|
|
|
root = BuildGraphConfigs(suite, options.arch, default_parent)
|
2014-12-03 15:34:53 +00:00
|
|
|
|
2016-04-29 15:51:05 +00:00
|
|
|
# Callback to be called on each node on traversal.
|
|
|
|
def NodeCB(node):
|
|
|
|
platform.PreTests(node, path)
|
2014-12-03 15:34:53 +00:00
|
|
|
|
2017-04-27 07:57:11 +00:00
|
|
|
# Traverse graph/trace tree and iterate over all runnables.
|
2016-04-29 15:51:05 +00:00
|
|
|
for runnable in FlattenRunnables(root, NodeCB):
|
2017-04-27 07:57:11 +00:00
|
|
|
runnable_name = "/".join(runnable.graphs)
|
2018-02-05 15:53:36 +00:00
|
|
|
if (not runnable_name.startswith(options.filter) and
|
|
|
|
runnable_name + "/" != options.filter):
|
2017-04-27 07:57:11 +00:00
|
|
|
continue
|
2018-08-01 23:10:11 +00:00
|
|
|
logging.info(">>> Running suite: %s", runnable_name)
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2016-04-29 15:51:05 +00:00
|
|
|
def Runner():
|
|
|
|
"""Output generator that reruns several times."""
|
2018-08-09 07:46:35 +00:00
|
|
|
total_runs = runnable.run_count * options.run_count_multiplier
|
|
|
|
for i in xrange(0, max(1, total_runs)):
|
2016-04-29 15:51:05 +00:00
|
|
|
# TODO(machenbach): Allow timeout per arch like with run_count per
|
|
|
|
# arch.
|
2018-10-30 14:23:38 +00:00
|
|
|
try:
|
|
|
|
yield platform.Run(runnable, i)
|
|
|
|
except TestFailedError:
|
|
|
|
have_failed_tests[0] = True
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2016-04-29 15:51:05 +00:00
|
|
|
# Let runnable iterate over all runs and handle output.
|
2017-11-21 16:10:50 +00:00
|
|
|
result, result_secondary = runnable.Run(
|
|
|
|
Runner, trybot=options.shell_dir_secondary)
|
2016-04-29 15:51:05 +00:00
|
|
|
results += result
|
2017-11-21 16:10:50 +00:00
|
|
|
results_secondary += result_secondary
|
2016-04-29 15:51:05 +00:00
|
|
|
platform.PostExecution()
|
|
|
|
|
|
|
|
if options.json_test_results:
|
|
|
|
results.WriteToFile(options.json_test_results)
|
|
|
|
else: # pragma: no cover
|
|
|
|
print results
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2017-11-21 16:10:50 +00:00
|
|
|
if options.json_test_results_secondary:
|
|
|
|
results_secondary.WriteToFile(options.json_test_results_secondary)
|
2015-07-10 13:02:09 +00:00
|
|
|
else: # pragma: no cover
|
2017-11-21 16:10:50 +00:00
|
|
|
print results_secondary
|
2015-07-10 13:02:09 +00:00
|
|
|
|
2018-10-30 14:23:38 +00:00
|
|
|
if results.errors or have_failed_tests[0]:
|
2018-10-09 15:45:35 +00:00
|
|
|
return 1
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
def MainWrapper():
|
|
|
|
try:
|
|
|
|
return Main(sys.argv[1:])
|
|
|
|
except:
|
|
|
|
# Log uncaptured exceptions and report infra failure to the caller.
|
|
|
|
traceback.print_exc()
|
|
|
|
return INFRA_FAILURE_RETCODE
|
|
|
|
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__": # pragma: no cover
|
2018-10-09 15:45:35 +00:00
|
|
|
sys.exit(MainWrapper())
|