[LNT] r312059 - Do not store index with SampleField object; NFC

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 29 15:59:27 PDT 2017


Author: matze
Date: Tue Aug 29 15:59:27 2017
New Revision: 312059

URL: http://llvm.org/viewvc/llvm-project?rev=312059&view=rev
Log:
Do not store index with SampleField object; NFC

The index field cannot be computed in the constructor of the SampleField
object; it was only initialized when the TestSuite object was created.
The problem with this approach is that when querying SampleFields from
the database, the index field will only be populated when the sqlalchemy
cache hits the objects where we previously initialized it. When using
multiple/shorter lived sqlalchemy sessions the cache won't unique the
instances.

This removes the index member from SampleField and instead provide the
TestSuiteDB.get_field_index() method that computes the index for a given
SampleField object. This helps improving LNTs sqlalchemy-session usage
in the future.

Modified:
    lnt/trunk/lnt/server/db/testsuite.py
    lnt/trunk/lnt/server/db/testsuitedb.py
    lnt/trunk/lnt/server/reporting/analysis.py
    lnt/trunk/lnt/server/reporting/summaryreport.py
    lnt/trunk/lnt/server/ui/templates/reporting/runs.html
    lnt/trunk/lnt/server/ui/templates/v4_global_status.html
    lnt/trunk/lnt/server/ui/templates/v4_new_regressions.html
    lnt/trunk/lnt/server/ui/templates/v4_regression_detail.html
    lnt/trunk/lnt/server/ui/templates/v4_run.html

Modified: lnt/trunk/lnt/server/db/testsuite.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/testsuite.py?rev=312059&r1=312058&r2=312059&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/testsuite.py (original)
+++ lnt/trunk/lnt/server/db/testsuite.py Tue Aug 29 15:59:27 2017
@@ -294,9 +294,6 @@ class SampleField(FieldMixin, Base):
         self.status_field = status_field
         self.bigger_is_better = bigger_is_better
 
-        # Index of this column.
-        self.index = None
-
         # Column instance for fields which have been bound (non-DB
         # parameter). This is provided for convenience in querying.
         self.column = None

Modified: lnt/trunk/lnt/server/db/testsuitedb.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/testsuitedb.py?rev=312059&r1=312058&r2=312059&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/testsuitedb.py (original)
+++ lnt/trunk/lnt/server/db/testsuitedb.py Tue Aug 29 15:59:27 2017
@@ -85,8 +85,10 @@ class TestSuiteDB(object):
         self.order_fields = list(self.test_suite.order_fields)
         self.run_fields = list(self.test_suite.run_fields)
         self.sample_fields = list(self.test_suite.sample_fields)
+        sample_field_indexes = dict()
         for i, field in enumerate(self.sample_fields):
-            field.index = i
+            sample_field_indexes[field.name] = i
+        self.sample_field_indexes = sample_field_indexes
 
         self.base = sqlalchemy.ext.declarative.declarative_base()
 
@@ -1140,3 +1142,6 @@ class TestSuiteDB(object):
 
     def getNumTests(self):
         return self.query(self.Test).count()
+
+    def get_field_index(self, sample_field):
+        return self.sample_field_indexes[sample_field.name]

Modified: lnt/trunk/lnt/server/reporting/analysis.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/reporting/analysis.py?rev=312059&r1=312058&r2=312059&view=diff
==============================================================================
--- lnt/trunk/lnt/server/reporting/analysis.py (original)
+++ lnt/trunk/lnt/server/reporting/analysis.py Tue Aug 29 15:59:27 2017
@@ -324,22 +324,27 @@ class RunInfo(object):
         # better.
         run_failed = prev_failed = False
         if status_field:
+            status_field_index = self.testsuite.get_field_index(status_field)
             for sample in run_samples:
-                run_failed |= sample[status_field.index] == FAIL
+                run_failed |= sample[status_field_index] == FAIL
             for sample in prev_samples:
-                prev_failed |= sample[status_field.index] == FAIL
+                prev_failed |= sample[status_field_index] == FAIL
+
+        field_index = self.testsuite.get_field_index(field)
 
         # Get the current and previous values.
-        run_values = [s[field.index] for s in run_samples
-                      if s[field.index] is not None]
-        prev_values = [s[field.index] for s in prev_samples
-                       if s[field.index] is not None]
+        run_values = [s[field_index] for s in run_samples
+                      if s[field_index] is not None]
+        prev_values = [s[field_index] for s in prev_samples
+                       if s[field_index] is not None]
         if hash_of_binary_field:
-            hash_values = [s[hash_of_binary_field.index] for s in run_samples
-                           if s[field.index] is not None]
-            prev_hash_values = [s[hash_of_binary_field.index]
+            hash_of_binary_field_index = \
+                    self.testsuite.get_field_index(hash_of_binary_field)
+            hash_values = [s[hash_of_binary_field_index] for s in run_samples
+                           if s[field_index] is not None]
+            prev_hash_values = [s[hash_of_binary_field_index]
                                 for s in prev_samples
-                                if s[field.index] is not None]
+                                if s[field_index] is not None]
 
             # All current hash_values should all be the same.
             # Warn in the log when the hash wasn't the same for all samples.

Modified: lnt/trunk/lnt/server/reporting/summaryreport.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/reporting/summaryreport.py?rev=312059&r1=312058&r2=312059&view=diff
==============================================================================
--- lnt/trunk/lnt/server/reporting/summaryreport.py (original)
+++ lnt/trunk/lnt/server/reporting/summaryreport.py Tue Aug 29 15:59:27 2017
@@ -217,12 +217,14 @@ class SummaryReport(object):
             # Return a datapoint for each passing field.
             for field_name, field, status_field in ts_sample_metric_fields:
                 # Ignore failing samples.
-                if status_field and \
-                        sample[2 + status_field.index] == lnt.testing.FAIL:
-                    continue
+                if status_field:
+                    status_field_index = ts.get_field_index(status_field)
+                    if sample[2 + status_field_index] == lnt.testing.FAIL:
+                        continue
 
                 # Ignore missing samples.
-                value = sample[2 + field.index]
+                field_index = ts.get_field_index(field)
+                value = sample[2 + field_index]
                 if value is None:
                     continue
 
@@ -290,12 +292,14 @@ class SummaryReport(object):
                     continue
 
                 # Ignore failing samples.
-                if status_field and \
-                        sample[2 + status_field.index] == lnt.testing.FAIL:
-                    continue
+                if status_field:
+                    status_field_index = ts.get_field_index(status_field)
+                    if sample[2 + status_field_index] == lnt.testing.FAIL:
+                        continue
 
                 # Ignore missing samples.
-                value = sample[2 + field.index]
+                field_index = ts.get_field_index(field)
+                value = sample[2 + field_index]
                 if value is None:
                     continue
 

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=312059&r1=312058&r2=312059&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/templates/reporting/runs.html (original)
+++ lnt/trunk/lnt/server/ui/templates/reporting/runs.html Tue Aug 29 15:59:27 2017
@@ -159,7 +159,7 @@
 <p>
 <h3>Run-Over-Run Changes Detail</h3>
 {% for _, field, bucket_name, sorted_bucket, test_names, show_perf in prioritized_buckets_run_over_run %}
-  {% set field_index = ts.sample_fields.index(field) %}
+  {% set field_index = ts.get_field_index(field) %}
   {% set field_display_name = {"compile_time":"Compile Time",
                                "execution_time":"Execution Time"}.get(field.name, field.name) %}
   {{
@@ -172,7 +172,7 @@
 {% if baseline %}
 <h3>Run-Over-Baseline Changes Detail</h3>
 {% for _, field, bucket_name, sorted_bucket, test_names, show_perf in prioritized_buckets_run_over_baseline %}
-  {% set field_index = ts.sample_fields.index(field) %}
+  {% set field_index = ts.get_field_index(field) %}
   {% set field_display_name = {"compile_time":"Compile Time",
                                "execution_time":"Execution Time"}.get(field.name, field.name) %}
   {{

Modified: lnt/trunk/lnt/server/ui/templates/v4_global_status.html
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/templates/v4_global_status.html?rev=312059&r1=312058&r2=312059&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/templates/v4_global_status.html (original)
+++ lnt/trunk/lnt/server/ui/templates/v4_global_status.html Tue Aug 29 15:59:27 2017
@@ -38,7 +38,7 @@
         
         <script language="javascript" type="text/javascript">
           $(document).ready(function() {
-            v4_global_status.init("{{ selected_field.index }}");
+            v4_global_status.init("{{ ts.get_field_index(selected_field) }}");
           });
         </script>
 {% endblock %}

Modified: lnt/trunk/lnt/server/ui/templates/v4_new_regressions.html
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/templates/v4_new_regressions.html?rev=312059&r1=312058&r2=312059&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/templates/v4_new_regressions.html (original)
+++ lnt/trunk/lnt/server/ui/templates/v4_new_regressions.html Tue Aug 29 15:59:27 2017
@@ -34,7 +34,8 @@ var g = {}
 var changes = [
 {% for form_change in form.field_changes%}
     {% set fc = changes[loop.index -1] %}
-    {"url": "/{{api_graph}}/{{ fc.ri.machine.id}}/{{fc.ri.test.id}}/{{fc.ri.field.index}}",
+    {% set fc_ri_field_index = ts.get_field_index(fc.ri.field) %}
+    {"url": "/{{api_graph}}/{{ fc.ri.machine.id}}/{{fc.ri.test.id}}/{{fc_ri_field_index}}",
      "start": {{fc.ri.start_order.llvm_project_revision}},
      "end": {{fc.ri.end_order.llvm_project_revision}}
  },
@@ -227,6 +228,7 @@ function update_tooltip(event, pos, item
     {# Show the active submissions. #}
     {% for form_change in form.field_changes%}
         {% set fc = changes[loop.index -1] %}
+        {% set fc_ri_field_index = ts.get_field_index(fc.ri.field) %}
     <tr>
         <td>
             
@@ -238,7 +240,7 @@ function update_tooltip(event, pos, item
         <td>{{utils.render_machine(fc.ri.machine)}}</td>
         <td> {{ fc.ri.field.name }} </td>
          {% set graph_base=v4_url_for('.v4_graph', highlight_run=fc.run.id) %}
-        <td><a href="{{graph_base}}&plot.{{fc.ri.test.id}}={{ fc.ri.machine.id}}.{{fc.ri.test.id}}.{{fc.ri.field.index}}">{{ fc.ri.test.name }}</a></td>
+        <td><a href="{{graph_base}}&plot.{{fc.ri.test.id}}={{ fc.ri.machine.id}}.{{fc.ri.test.id}}.{{fc_ri_field_index}}">{{ fc.ri.test.name }}</a></td>
         <td>m{{ fc.ri.start_order.llvm_project_revision }}, {{utils.render_order_link(fc.ri.end_order)}}</td>
         <td>{{ fc.cr.previous }}</td><td>{{ fc.cr.current }}</td>
         {{ utils.get_regression_cell_value(fc.cr, analysis)}}

Modified: lnt/trunk/lnt/server/ui/templates/v4_regression_detail.html
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/templates/v4_regression_detail.html?rev=312059&r1=312058&r2=312059&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/templates/v4_regression_detail.html (original)
+++ lnt/trunk/lnt/server/ui/templates/v4_regression_detail.html Tue Aug 29 15:59:27 2017
@@ -41,7 +41,8 @@ var max_samples = {{ request.args.get('l
 var changes = [
 {% for form_change in form.field_changes%}
     {% set fc = changes[loop.index -1] %}
-    {"url": "{{fc.ri.machine.id}}/{{fc.ri.test.id}}/{{fc.ri.field.index}}",
+    {% set fc_ri_field_index = ts.get_field_index(fc.ri.field) %}
+    {"url": "{{fc.ri.machine.id}}/{{fc.ri.test.id}}/{{fc_ri_field_index}}",
      "start": {{fc.ri.start_order.llvm_project_revision}},
      "end": {{fc.ri.end_order.llvm_project_revision}}
  },
@@ -98,6 +99,7 @@ var changes = [
     {# Show the active submissions. #}
     {% for form_change in form.field_changes%}
         {% set fc = changes[loop.index -1] %}
+        {% set fc_ri_field_index = ts.get_field_index(fc.ri.field) %}
     <tr class="change-row" data-order-start="{{ fc.ri.start_order.llvm_project_revision }}"
         data-order-end="{{fc.ri.end_order.llvm_project_revision}}">
         <td>
@@ -111,7 +113,7 @@ var changes = [
         <td class="machine">{{utils.render_machine(fc.ri.machine)}}</td>
         <td class="metric"> {{ fc.ri.field.name }} </td>
          {% set graph_base=v4_url_for('.v4_graph', highlight_run=fc.run.id) %}
-        <td><a href="{{graph_base}}&plot.{{fc.ri.test.id}}={{ fc.ri.machine.id}}.{{fc.ri.test.id}}.{{fc.ri.field.index}}">{{ fc.ri.test.name }}</a></td>
+        <td><a href="{{graph_base}}&plot.{{fc.ri.test.id}}={{ fc.ri.machine.id}}.{{fc.ri.test.id}}.{{fc_ri_field_index}}">{{ fc.ri.test.name }}</a></td>
         <td>{{local.prefix}}{{ fc.ri.start_order.llvm_project_revision }}, {{local.render_order_link(fc.ri.end_order)}}</td>
         <td>{{ fc.cr.previous }}</td><td>{{ fc.cr.current }}</td>
         {{ utils.get_regression_cell_value(fc.cr, analysis)}}

Modified: lnt/trunk/lnt/server/ui/templates/v4_run.html
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/templates/v4_run.html?rev=312059&r1=312058&r2=312059&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/templates/v4_run.html (original)
+++ lnt/trunk/lnt/server/ui/templates/v4_run.html Tue Aug 29 15:59:27 2017
@@ -318,6 +318,7 @@ $('.profile-prev-only').tooltip();
 
     {# Report one table for each primary field. #}
     {% for field in metric_fields %}
+      {% set field_index = ts.get_field_index(field) %}
       <section id="{{ field.name }}">
           {% set tests = [] %}
           {% set (runs, compare_runs) = request_info.sri.get_sliding_runs(run, compare_to, request_info.num_comparison_runs) %}
@@ -350,9 +351,9 @@ $('.profile-prev-only').tooltip();
         <tbody class="searchable">
           {% for test_name,test_id,cr in tests %}
             <tr>
-              <td><input type="checkbox" name="plot.{{test_id}}" value="{{machine.id}}.{{test_id}}.{{field.index}}"/></td>
+              <td><input type="checkbox" name="plot.{{test_id}}" value="{{machine.id}}.{{test_id}}.{{field_index}}"/></td>
               <td class="benchmark-name">
-                <a href="{{graph_base}}&plot.{{test_id}}={{ machine.id}}.{{test_id}}.{{field.index}}">
+                <a href="{{graph_base}}&plot.{{test_id}}={{ machine.id}}.{{test_id}}.{{field_index}}">
                   {{ test_name }}
                 </a>
                 {{ utils.render_profile_link(cr.cur_profile, cr.prev_profile, run.id, compare_to.id, test_id) }}
@@ -365,8 +366,8 @@ $('.profile-prev-only').tooltip();
           <tr>
             {% set cr = request_info.sri.get_geomean_comparison_result(
                         run, compare_to, field, tests) %}
-            <td><input type="checkbox" name="mean" value="{{machine.id}}.{{field.index}}"/></td>
-            <td><a href="{{graph_base}}&mean={{machine.id}}.{{field.index}}">Geometric Mean</a></td>
+            <td><input type="checkbox" name="mean" value="{{machine.id}}.{{field_index}}"/></td>
+            <td><a href="{{graph_base}}&mean={{machine.id}}.{{field_index}}">Geometric Mean</a></td>
             {{ get_cell_value(cr) }}
           </tr>
         </tfoot>




More information about the llvm-commits mailing list