[LNT] r306570 - runs: Refactor generate_run_report; NFC

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 28 10:40:11 PDT 2017


Author: matze
Date: Wed Jun 28 10:40:11 2017
New Revision: 306570

URL: http://llvm.org/viewvc/llvm-project?rev=306570&view=rev
Log:
runs: Refactor generate_run_report; NFC

The existing generate_run_report() gathers data and then renders this
data into a text and html report (even when we usually only need one of
the two). Refactor this:

- Introduce generate_run_data() that just gathers the data.
- Switch views.py to just use generate_run_data() and do the html
  rendering in views.py.

Modified:
    lnt/trunk/lnt/lnttool/main.py
    lnt/trunk/lnt/server/reporting/runs.py
    lnt/trunk/lnt/server/ui/templates/reporting/runs.html
    lnt/trunk/lnt/server/ui/views.py
    lnt/trunk/lnt/util/NTEmailReport.py

Modified: lnt/trunk/lnt/lnttool/main.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/main.py?rev=306570&r1=306569&r2=306570&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/main.py (original)
+++ lnt/trunk/lnt/lnttool/main.py Wed Jun 28 10:40:11 2017
@@ -363,12 +363,18 @@ def action_send_run_comparison(instance_
             error("invalid run ID %r (not in database)" % (run_b_id,))
 
         # Generate the report.
-        reports = lnt.server.reporting.runs.generate_run_report(
-            run_b, baseurl=config.zorgURL, only_html_body=False, result=None,
-            compare_to=run_a, baseline=None,
-            aggregation_fn=min)
-        subject, text_report, html_report, _ = reports
+        data = lnt.server.reporting.runs.generate_run_data(
+            run_b, baseurl=config.zorgURL, result=None, compare_to=run_a,
+            baseline=None, aggregation_fn=min)
 
+        env = lnt.server.ui.app.create_jinja_environment()
+        text_template = env.get_template('reporting/runs.txt')
+        text_report = text_template.render(data)
+        data['only_html_body'] = False
+        html_template = env.get_template('reporting/runs.html')
+        html_report = html_template.render(data)
+
+        subject = data['subject']
         if subject_prefix is not None:
             subject = "%s %s" % (subject_prefix, subject)
 

Modified: lnt/trunk/lnt/server/reporting/runs.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/reporting/runs.py?rev=306570&r1=306569&r2=306570&view=diff
==============================================================================
--- lnt/trunk/lnt/server/reporting/runs.py (original)
+++ lnt/trunk/lnt/server/reporting/runs.py Wed Jun 28 10:40:11 2017
@@ -10,19 +10,15 @@ from lnt.testing.util.commands import vi
 
 
 
-def generate_run_report(run, baseurl, only_html_body=False,
-                        num_comparison_runs=0, result=None,
-                        compare_to=None, baseline=None,
-                        aggregation_fn=lnt.util.stats.safe_min, confidence_lv=.05,
-                        styles=dict(), classes=dict()):
+def generate_run_data(run, baseurl, num_comparison_runs=0, result=None,
+                      compare_to=None, baseline=None,
+                      aggregation_fn=lnt.util.stats.safe_min,
+                      confidence_lv=.05, styles=dict(), classes=dict()):
     """
-    generate_run_report(...) -> (str: subject, str: text_report,
-                                 str: html_report)
-
-    Generate a comprehensive report on the results of the given individual
-    run, suitable for emailing or presentation on a web page.
+    Generate raw data for a report on the results of the given individual
+    run. They are meant as inputs to jinja templates which could create
+    email reports or presentations on a web page.
     """
-
     assert num_comparison_runs >= 0
 
     start_time = time.time()
@@ -187,53 +183,29 @@ def generate_run_report(run, baseurl, on
     styles_.update(styles)
     classes_.update(classes)
 
-    # Create an environment for rendering the reports.
-    env = lnt.server.ui.app.create_jinja_environment()
-
-    # Generate reports.  The timing code here is a cludge and will
-    # give enough accuracy for approximate timing estimates. I am
-    # going to separate the text/html report in a later commit (so
-    # that we can have more output types [i.e. json] if we need to)
-    # and remove this. The time will then be generated separately and
-    # correctly for each different template.
-    text_template = env.get_template('reporting/runs.txt')
-    text_report_start_time = time.time()
-    text_report = text_template.render(
-        report_url=report_url,
-        machine=machine,
-        machine_parameters=machine_parameters,
-        run=run,
-        compare_to=compare_to,
-        baseline=baseline,
-        num_item_buckets=num_item_buckets,
-        num_total_tests=num_total_tests,
-        prioritized_buckets_run_over_run=prioritized_buckets_run_over_run,
-        prioritized_buckets_run_over_baseline=prioritized_buckets_run_over_baseline,
-        start_time=start_time)
-    text_report_delta = time.time() - text_report_start_time
-    start_time = start_time + text_report_delta
-
-    html_template = env.get_template('reporting/runs.html')
-    html_report = html_template.render(
-        ts=ts,
-        subject=subject,
-        only_html_body=only_html_body,
-        report_url=report_url,
-        ts_url=ts_url,
-        compare_to=compare_to,
-        run=run,
-        run_url=run_url,
-        baseline=baseline,
-        num_item_buckets=num_item_buckets,
-        num_total_tests=num_total_tests,
-        run_to_run_info=run_to_run_info,
-        prioritized_buckets_run_over_run=prioritized_buckets_run_over_run,
-        run_to_baseline_info=run_to_baseline_info,
-        prioritized_buckets_run_over_baseline=prioritized_buckets_run_over_baseline,
-        styles=styles_, classes=classes_,
-        start_time=start_time)
-
-    return subject, text_report, html_report, sri
+    data = {
+        'ts': ts,
+        'subject': subject,
+        'report_url': report_url,
+        'ts_url': ts_url,
+        'compare_to': compare_to,
+        'run': run,
+        'run_url': run_url,
+        'baseline': baseline,
+        'machine': machine,
+        'machine_parameters': machine_parameters,
+        'num_item_buckets': num_item_buckets,
+        'num_total_tests': num_total_tests,
+        'run_to_run_info': run_to_run_info,
+        'prioritized_buckets_run_over_run': prioritized_buckets_run_over_run,
+        'run_to_baseline_info': run_to_baseline_info,
+        'prioritized_buckets_run_over_baseline': prioritized_buckets_run_over_baseline,
+        'styles': styles_,
+        'classes': classes_,
+        'start_time': start_time,
+        'sri': sri,
+    }
+    return data
 
 
 def _get_changes_by_type(ts, run_a, run_b, metric_fields, test_names,

Modified: lnt/trunk/lnt/server/ui/templates/reporting/runs.html
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/templates/reporting/runs.html?rev=306570&r1=306569&r2=306570&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/templates/reporting/runs.html (original)
+++ lnt/trunk/lnt/server/ui/templates/reporting/runs.html Wed Jun 28 10:40:11 2017
@@ -88,7 +88,7 @@
       <th style="{{ styles['th'] }}">Order</th>
       <th style="{{ styles['th'] }}">Start Time</th>
       <th style="{{ styles['th'] }}">Duration</th>
-      {%- set show_producers = (run and run.parameters.producer) or(compare_to and compare_to.parameters.producer) or (baseline and baseline.parameters.producer) %}
+      {%- set show_producers = (run and 'producer' in run.parameters) or(compare_to and 'producer' in compare_to.parameters) or (baseline and 'producer' in baseline.parameters) %}
       {% if show_producers %}
         <th style="{{ styles['th'] }}">Produced by</th>
       {% endif %}

Modified: lnt/trunk/lnt/server/ui/views.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/views.py?rev=306570&r1=306569&r2=306570&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/views.py (original)
+++ lnt/trunk/lnt/server/ui/views.py Wed Jun 28 10:40:11 2017
@@ -283,7 +283,7 @@ def v4_machine(id):
         abort(404)
 
 class V4RequestInfo(object):
-    def __init__(self, run_id, only_html_body=True):
+    def __init__(self, run_id):
         self.db = request.get_db()
         self.ts = ts = request.get_testsuite()
         self.run = run = ts.query(ts.Run).filter_by(id=run_id).first()
@@ -363,26 +363,26 @@ class V4RequestInfo(object):
             'table': 'table table-striped table-condensed table-hover'
         }
 
-        reports = lnt.server.reporting.runs.generate_run_report(
+        self.data = lnt.server.reporting.runs.generate_run_data(
             self.run, baseurl=db_url_for('index', _external=True),
-            only_html_body=only_html_body, result=None,
-            compare_to=self.compare_to, baseline=self.baseline,
+            result=None, compare_to=self.compare_to, baseline=self.baseline,
             num_comparison_runs=self.num_comparison_runs,
             aggregation_fn=self.aggregation_fn, confidence_lv=confidence_lv,
             styles=styles, classes=classes)
-        _, self.text_report, self.html_report, self.sri = reports
+        self.sri = self.data['sri']
 
 @v4_route("/<int:id>/report")
 def v4_report(id):
-    info = V4RequestInfo(id, only_html_body=False)
-
-    return make_response(info.html_report)
+    info = V4RequestInfo(id)
+    return render_template('reporting/runs.html', only_html_body=False,
+                           **info.data)
 
 @v4_route("/<int:id>/text_report")
 def v4_text_report(id):
-    info = V4RequestInfo(id, only_html_body=False)
+    info = V4RequestInfo(id)
 
-    response = make_response(info.text_report)
+    text_report = render_template('reporting/runs.txt', **info.data)
+    response = make_response(text_report)
     response.mimetype = "text/plain"
     return response
 
@@ -489,6 +489,8 @@ def v4_run(id):
     urls = {
         'search': v4_url_for('v4_search')
     }
+    info.html_report = render_template('reporting/runs.html',
+                                       only_html_body=True, **info.data)
     return render_template(
         "v4_run.html", ts=ts, options=options,
         metric_fields=list(ts.Sample.get_metric_fields()),

Modified: lnt/trunk/lnt/util/NTEmailReport.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/util/NTEmailReport.py?rev=306570&r1=306569&r2=306570&view=diff
==============================================================================
--- lnt/trunk/lnt/util/NTEmailReport.py (original)
+++ lnt/trunk/lnt/util/NTEmailReport.py Wed Jun 28 10:40:11 2017
@@ -44,11 +44,16 @@ def emailReport(result, db, run, baseurl
     s.quit()
 
 def getReport(result, db, run, baseurl, was_added, will_commit,
-              only_html_body = False, compare_to = None):
+              compare_to=None):
     assert isinstance(db, lnt.server.db.v4db.V4DB)
-    report = StringIO.StringIO()
 
-    reports = lnt.server.reporting.runs.generate_run_report(
-        run, baseurl=baseurl, only_html_body=only_html_body,
+    data = lnt.server.reporting.runs.generate_run_data(run, baseurl=baseurl,
         result=result, compare_to=compare_to, num_comparison_runs=10)
-    return reports[:3]
+
+    env = lnt.server.ui.app.create_jinja_environment()
+    text_template = env.get_template('reporting/runs.txt')
+    text_report = text_template.render(data)
+    data['only_html_body'] = False
+    html_template = env.get_template('reporting/runs.html')
+    html_report = html_template.render(data)
+    return data['subject'], text_report, html_report




More information about the llvm-commits mailing list