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

Unified Diff: tools/telemetry/telemetry/benchmark_runner.py

Issue 1138933003: [Telemetry] Enable benchmark runner to list most closely matched input benchmark names. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only print matched benchmarks if there is any Created 5 years, 7 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 | tools/telemetry/telemetry/benchmark_runner_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/benchmark_runner.py
diff --git a/tools/telemetry/telemetry/benchmark_runner.py b/tools/telemetry/telemetry/benchmark_runner.py
index 2ed7573164d19b9114a053445b44d1f36d608940..b9fac19887835cdaf9dfe4ec6b71fa0a96afb743 100644
--- a/tools/telemetry/telemetry/benchmark_runner.py
+++ b/tools/telemetry/telemetry/benchmark_runner.py
@@ -7,6 +7,7 @@
Handles benchmark configuration, but all the logic for
actually running the benchmark is in Benchmark and PageRunner."""
+import difflib
import hashlib
import inspect
import json
@@ -66,6 +67,32 @@ def PrintBenchmarkList(benchmarks, possible_browser, output_pipe=sys.stdout):
print >> output_pipe
+def GetMostLikelyMatchedBenchmarks(all_benchmarks, input_benchmark_name):
+ """ Returns the list of benchmarks whose name most likely matched with
+ |input_benchmark_name|.
+
+ Args:
+ all_benchmarks: the list of benchmark classes.
+ input_benchmark_name: a string to be matched against the names of benchmarks
+ in |all_benchmarks|.
+
+ Returns:
+ A list of benchmark classes whose name likely matched
+ |input_benchmark_name|. Benchmark classes are arranged in descending order
+ of similarity between their names to |input_benchmark_name|.
+ """
+ def MatchedWithBenchmarkInputNameScore(benchmark_class):
+ return difflib.SequenceMatcher(
+ isjunk=None,
+ a=benchmark_class.Name(), b=input_benchmark_name).ratio()
+ benchmarks_with_similar_names = [
+ b for b in all_benchmarks if
+ MatchedWithBenchmarkInputNameScore(b) > 0.4]
+ ordered_list = sorted(benchmarks_with_similar_names,
+ key=MatchedWithBenchmarkInputNameScore,
+ reverse=True)
+ return ordered_list
+
class Environment(object):
"""Contains information about the benchmark runtime environment.
@@ -200,10 +227,11 @@ class Run(command_line.OptparseCommand):
@classmethod
def ProcessCommandLineArgs(cls, parser, args, environment):
+ all_benchmarks = _Benchmarks(environment)
if not args.positional_args:
possible_browser = (
browser_finder.FindBrowser(args) if args.browser_type else None)
- PrintBenchmarkList(_Benchmarks(environment), possible_browser)
+ PrintBenchmarkList(all_benchmarks, possible_browser)
sys.exit(-1)
input_benchmark_name = args.positional_args[0]
@@ -211,7 +239,11 @@ class Run(command_line.OptparseCommand):
if not matching_benchmarks:
print >> sys.stderr, 'No benchmark named "%s".' % input_benchmark_name
print >> sys.stderr
- PrintBenchmarkList(_Benchmarks(environment), None, sys.stderr)
+ most_likely_matched_benchmarks = GetMostLikelyMatchedBenchmarks(
+ all_benchmarks, input_benchmark_name)
+ if most_likely_matched_benchmarks:
+ print >> sys.stderr, 'Do you mean any of those benchmarks below?'
+ PrintBenchmarkList(most_likely_matched_benchmarks, None, sys.stderr)
sys.exit(-1)
if len(matching_benchmarks) > 1:
« no previous file with comments | « no previous file | tools/telemetry/telemetry/benchmark_runner_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698