Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Unified Diff: tools/run_perf.py

Issue 1681283004: [tools] add --pretty switch to run_perf.py Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: better error handling Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/run_perf.py
diff --git a/tools/run_perf.py b/tools/run_perf.py
index db4245f499fc07c3a32f435a78ec08d5f06f58a3..3fe23ce348e99069a4ba6b3755690bbc8d767794 100755
--- a/tools/run_perf.py
+++ b/tools/run_perf.py
@@ -208,12 +208,25 @@ class Measurement(object):
self.errors.append("Regexp \"%s\" didn't match for test %s."
% (self.stddev_regexp, self.name))
+ def GetDeviation(self):
+ if len(self.results) == 0:
+ return 0
+ mean = self.GetMean()
+ square_deviation = sum((float(x)-mean)**2 for x in self.results)
+ return (square_deviation / len(self.results)) ** 0.5
+
+ def GetMean(self):
+ if len(self.results) == 0:
+ return 0
+ return sum(float(x) for x in self.results) / len(self.results)
Michael Achenbach 2016/02/11 09:44:07 nit: sum(self.results) / float(len(self.results))
Camillo Bruni 2016/02/11 10:22:57 I think I got some strings in the results
+
def GetResults(self):
return Results([{
"graphs": self.graphs,
"units": self.units,
"results": self.results,
- "stddev": self.stddev,
+ "average": self.GetMean(),
+ "stddev": self.GetDeviation(),
Michael Achenbach 2016/02/11 09:44:07 There are benchmarks that provide their own stddev
Camillo Bruni 2016/02/11 10:22:56 ups... I wanted to return the existing value in Ge
}], self.errors)
@@ -405,7 +418,10 @@ class GraphConfig(Node):
# TODO(machenbach): Currently that makes only sense for the leaf level.
# Multiple place holders for multiple levels are not supported.
if parent.results_regexp:
- regexp_default = parent.results_regexp % re.escape(suite["name"])
+ try:
+ regexp_default = parent.results_regexp % re.escape(suite["name"])
+ except TypeError:
+ regexp_default = parent.results_regexp
else:
regexp_default = None
self.results_regexp = suite.get("results_regexp", regexp_default)
@@ -587,6 +603,9 @@ class Platform(object):
else:
return DesktopPlatform(options)
+ def GetPrettyFormatted(self, options):
+ return self
+
def _Run(self, runnable, count, no_patch=False):
raise NotImplementedError() # pragma: no cover
@@ -613,6 +632,9 @@ class DesktopPlatform(Platform):
def __init__(self, options):
super(DesktopPlatform, self).__init__(options)
+ def GetPrettyFormatted(self, options):
+ return PrettyFormattedDesktopPlatform(options)
+
def PreExecution(self):
pass
@@ -623,6 +645,10 @@ class DesktopPlatform(Platform):
if isinstance(node, RunnableConfig):
node.ChangeCWD(path)
+ def _PrintStdout(self, title, output):
+ print title % "Stdout"
+ print output.stdout
+
def _Run(self, runnable, count, no_patch=False):
suffix = ' - without patch' if no_patch else ''
shell_dir = self.shell_dir_no_patch if no_patch else self.shell_dir
@@ -636,8 +662,7 @@ class DesktopPlatform(Platform):
print title % "OSError"
print e
return ""
- print title % "Stdout"
- print output.stdout
+ self._PrintStdout(title, output)
if output.stderr: # pragma: no cover
# Print stderr for debugging.
print title % "Stderr"
@@ -654,6 +679,21 @@ class DesktopPlatform(Platform):
return output.stdout
+class PrettyFormattedDesktopPlatform(DesktopPlatform):
+
+ def _PrintStdout(self, title, output):
+ sys.stdout.write("\r")
+ if output.exit_code != 0:
+ print output.stdout
+ return
+ # Assume the time is on the last line
+ result_line = output.stdout.splitlines()[-1].strip()
+ sys.stdout.write(result_line)
+ # Fill with spaces up to 80 characters.
+ sys.stdout.write(' '*max(0, 80-len(result_line)))
+ sys.stdout.flush()
+
+
class AndroidPlatform(Platform): # pragma: no cover
DEVICE_DIR = "/data/local/tmp/v8/"
@@ -818,6 +858,9 @@ def Main(args):
default="out")
parser.add_option("--outdir-no-patch",
help="Base directory with compile output without patch")
+ parser.add_option("--pretty",
+ help="Print human readable output",
+ default=False, action="store_true")
parser.add_option("--binary-override-path",
help="JavaScript engine binary. By default, d8 under "
"architecture-specific build dir. "
@@ -873,6 +916,8 @@ def Main(args):
options.shell_dir_no_patch = None
platform = Platform.GetPlatform(options)
+ if options.pretty:
+ platform = platform.GetPrettyFormatted(options)
results = Results()
results_no_patch = Results()
@@ -914,6 +959,17 @@ def Main(args):
# Let runnable iterate over all runs and handle output.
result, result_no_patch = runnable.Run(
Runner, trybot=options.shell_dir_no_patch)
+ if options.pretty:
Michael Achenbach 2016/02/11 09:44:07 Maybe factor out this piece of code as printing is
Camillo Bruni 2016/02/11 10:22:57 Yes, I want to have direct feedback. I'll put it i
+ if result.errors:
+ print "\r:Errors:"
+ print "\n".join(set(result.errors))
+ else:
+ trace = result.traces[0]
+ average = trace['average']
+ stdev = trace['stddev']
+ stdev_percentage = 100 * stdev / average if average != 0 else 0
+ print "\r %s +/- %3.2f%% %s" % (average, stdev_percentage, trace['units'])
+ sys.stdout.flush()
results += result
results_no_patch += result_no_patch
platform.PostExecution()
@@ -921,12 +977,14 @@ def Main(args):
if options.json_test_results:
results.WriteToFile(options.json_test_results)
else: # pragma: no cover
- print results
+ if not options.pretty:
+ print results
if options.json_test_results_no_patch:
results_no_patch.WriteToFile(options.json_test_results_no_patch)
else: # pragma: no cover
- print results_no_patch
+ if not options.pretty:
+ print results_no_patch
return min(1, len(results.errors))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698