From 2368b41ea869a6904ae8320ad69f1b8b9a9a3714 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Thu, 25 Aug 2016 11:29:09 -0700 Subject: crosperf: Make results_report more general. The goal of this patch is to allow us to use results_report to generate non-ChromeOS-specific results reports. It's meant to be a nop for regular crosperf runs (except that, in HTML report generation, whitespace in the HTML itself will look a bit different.) Moreover, results_report used to shuffle Experiments around, each of which, unsurprisingly, contained *tons* of data about an experiment. So, part of this patch was reducing results_report's reliance on Experiments, in favor of a new type, BenchmarkResult. Some parts of results_report still rely on Experiments, but only to provide *extra* data. The minimum amount of data needed to make a results report is contained in a BenchmarkResult, and there's a convenient API we can use to make a BenchmarkResult out of an Experiment. This patch also does a massive refactor of results_report, because lots of the code was mildly more icky than it is with this patch applied. The refactor-for-prettiness and refactor-for-BenchmarkResults kind of go hand-in-hand, so it's really hard to split them out. The only part that's not so difficult to split out is the refactor to results_report_templates, but the value of splitting that out is questionable (to me). Speaking of which, all HTML magicks that were in results_report is now in results_report_templates, and now use *actual* Templates. It -- and HTMLReportGenerator -- are hopefully more readable as a result. Next, this makes JSONRsultsReport's GetReport() return a string containing JSON data, rather than calling a callback to write that string to a file. Finally, this includes a change to perf_table. Namely, its removal. It was otherwise unused, and I couldn't get it to even work, so I cleaned it up, made a perf report parser (because I couldn't get the cros_utils one to work, either...), and made sure it functions. If we're able to produce perf reports that cros_utils can parse, I'm happy to back my new parser out; I was primarily using it so I could be sure I didn't break HTML report generation. BUG=chromium:641098 TEST=./run_tests.sh passes Change-Id: I437de9eb39e00c9dd5c223ecd27feaaab544a6fd Reviewed-on: https://chrome-internal-review.googlesource.com/282217 Commit-Ready: George Burgess Tested-by: George Burgess Reviewed-by: Caroline Tice --- crosperf/results_report_templates.py | 196 +++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 crosperf/results_report_templates.py (limited to 'crosperf/results_report_templates.py') diff --git a/crosperf/results_report_templates.py b/crosperf/results_report_templates.py new file mode 100644 index 00000000..827649fd --- /dev/null +++ b/crosperf/results_report_templates.py @@ -0,0 +1,196 @@ +# Copyright 2016 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +"""Text templates used by various parts of results_report.""" +from __future__ import print_function + +import cgi +from string import Template + +_TabMenuTemplate = Template(""" +
+ HTML + Text + TSV +
""") + +def _GetTabMenuHTML(table_name): + # N.B. cgi.escape does some very basic HTML escaping. Nothing more. + escaped = cgi.escape(table_name, quote=True) + return _TabMenuTemplate.substitute(table_name=escaped) + + +_ExperimentFileHTML = """ +
+
Experiment File
+
+
%s
+
+""" + +def _GetExperimentFileHTML(experiment_file_text): + if not experiment_file_text: + return '' + return _ExperimentFileHTML % (cgi.escape(experiment_file_text), ) + + +_ResultsSectionHTML = Template(""" +
+
$sect_name
+
+
$html_table
+
$text_table
+
$tsv_table
+
+ $tab_menu +
+""") + +def _GetResultsSectionHTML(print_table, table_name, data): + first_word = table_name.strip().split()[0] + short_name = first_word.lower() + return _ResultsSectionHTML.substitute(sect_name=table_name, + html_table=print_table(data, 'HTML'), + text_table=print_table(data, 'PLAIN'), + tsv_table=print_table(data, 'TSV'), + tab_menu=_GetTabMenuHTML(short_name), + short_name=short_name) + + + +_MainHTML = Template(""" + + + + + + + + + $summary_table + $perf_html +
+
Charts
+
$chart_divs
+
+ $full_table + $experiment_file + + +""") + +# It's a bit ugly that we take some HTML things, and some non-HTML things, but I +# need to balance prettiness with time spent making things pretty. +def GenerateHTMLPage(perf_table, chart_js, summary_table, print_table, + chart_divs, full_table, experiment_file): + """Generates a crosperf HTML page from the given arguments. + + print_table is a two-arg function called like: print_table(t, f) + t is one of [summary_table, print_table, full_table]; it's the table we want + to format. + f is one of ['TSV', 'HTML', 'PLAIN']; it's the type of format we want. + """ + summary_table_html = _GetResultsSectionHTML(print_table, 'Summary Table', + summary_table) + if perf_table: + perf_html = _GetResultsSectionHTML(print_table, 'Perf Table', perf_table) + perf_init = "switchTab('perf', 'html')" + else: + perf_html = '' + perf_init = '' + + full_table_html = _GetResultsSectionHTML(print_table, 'Full Table', + full_table) + experiment_file_html = _GetExperimentFileHTML(experiment_file) + return _MainHTML.substitute(perf_init=perf_init, chart_js=chart_js, + summary_table=summary_table_html, + perf_html=perf_html, chart_divs=chart_divs, + full_table=full_table_html, + experiment_file=experiment_file_html) -- cgit v1.2.3