[llvm-commits] [zorg] r108306 - in /zorg/trunk/lnt/lnt/viewer: GraphUtil.py simple.ptl

Daniel Dunbar daniel at zuster.org
Tue Jul 13 18:39:52 PDT 2010


Author: ddunbar
Date: Tue Jul 13 20:39:52 2010
New Revision: 108306

URL: http://llvm.org/viewvc/llvm-project?rev=108306&view=rev
Log:
LNT/simple: Pull some graphing code out into a helper module.

Added:
    zorg/trunk/lnt/lnt/viewer/GraphUtil.py
Modified:
    zorg/trunk/lnt/lnt/viewer/simple.ptl

Added: zorg/trunk/lnt/lnt/viewer/GraphUtil.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/viewer/GraphUtil.py?rev=108306&view=auto
==============================================================================
--- zorg/trunk/lnt/lnt/viewer/GraphUtil.py (added)
+++ zorg/trunk/lnt/lnt/viewer/GraphUtil.py Tue Jul 13 20:39:52 2010
@@ -0,0 +1,92 @@
+"""
+Helper functions for graphing test results.
+"""
+
+import Util
+
+from lnt.util import stats
+
+from PerfDB import Machine, Run, RunInfo, Sample, Test
+
+def get_test_plots(db, machine, test_ids, run_summary, ts_summary,
+                   show_mad_error = False, show_points = False,
+                   show_all_points = False):
+    # Load all the samples for these tests and this machine.
+    q = db.session.query(Sample.run_id,Sample.test_id,
+                         Sample.value).join(Run)
+    q = q.filter(Run.machine_id == machine.id)
+    q = q.filter(Sample.test_id.in_(test_ids))
+    samples = list(q)
+
+    # Aggregate by test id and then run key.
+    #
+    # FIXME: Pretty expensive.
+    samples_by_test_id = {}
+    for run_id,test_id,value in samples:
+        d = samples_by_test_id.get(test_id)
+        if d is None:
+            d = samples_by_test_id[test_id] = Util.multidict()
+        run_key = run_summary.get_run_order(run_id)
+        if run_key is None:
+            continue
+
+        # FIXME: What to do on failure?
+        run_key = int(run_key)
+        d[run_key] = value
+
+    # Build the graph data
+    pset_id_map = dict([(pset,i)
+                        for i,pset in enumerate(ts_summary.parameter_sets)])
+    num_plots = len(test_ids)
+    for index,test_id in enumerate(test_ids):
+        test = db.getTest(test_id)
+        pset = test.get_parameter_set()
+        name = test.name
+
+        # Get the plot for this test.
+        #
+        # FIXME: Support order by something other than time.
+        errorbar_data = []
+        points_data = []
+        data = []
+        points = []
+        for x,values in samples_by_test_id.get(test_id,{}).items():
+            min_value = min(values)
+            data.append((x, min_value))
+            if show_points:
+                if show_all_points:
+                    for v in values:
+                        points_data.append((x, v))
+                else:
+                    points_data.append((x, min_value))
+            if show_mad_error:
+                med = stats.median(values)
+                mad = stats.median_absolute_deviation(values, med)
+                errorbar_data.append((x, med - mad, med + mad))
+                points.append((x, min_value, mad, med))
+        data.sort()
+        points.sort()
+
+        plot_js = ""
+
+        col = list(Util.makeDarkColor(float(index) / num_plots))
+        pts = ','.join(['[%.4f,%.4f]' % (t,v)
+                        for t,v in data])
+        style = "new Graph2D_LinePlotStyle(1, %r)" % col
+        plot_js += "    graph.addPlot([%s], %s);\n" % (pts,style)
+
+        if points_data:
+            pts_col = (0,0,0)
+            pts = ','.join(['[%.4f,%.4f]' % (t,v)
+                            for t,v in points_data])
+            style = "new Graph2D_PointPlotStyle(1, %r)" % (pts_col,)
+            plot_js += "    graph.addPlot([%s], %s);\n" % (pts,style)
+
+        if errorbar_data:
+            bar_col = [c*.7 for c in col]
+            pts = ','.join(['[%.4f,%.4f,%.4f]' % (x,y_min,y_max)
+                            for x,y_min,y_max in errorbar_data])
+            style = "new Graph2D_ErrorBarPlotStyle(1, %r)" % (bar_col,)
+            plot_js += "    graph.addPlot([%s], %s);\n" % (pts,style)
+
+        yield (test_id, plot_js, col, data, points)

Modified: zorg/trunk/lnt/lnt/viewer/simple.ptl
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/viewer/simple.ptl?rev=108306&r1=108305&r2=108306&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/viewer/simple.ptl (original)
+++ zorg/trunk/lnt/lnt/viewer/simple.ptl Tue Jul 13 20:39:52 2010
@@ -14,6 +14,7 @@
 from lnt.db import runinfo
 from lnt.db import perfdbsummary
 from lnt.util import stats
+from lnt.viewer import GraphUtil
 
 import Util
 from Util import safediv
@@ -233,93 +234,26 @@
                      for name in graph_tests
                      for pset in graph_psets]
 
-        # Load all the samples for those tests and this machine.
-        q = db.session.query(Sample.run_id,Sample.test_id,
-                             Sample.value).join(Run)
-        q = q.filter(Run.machine_id == machine.id)
-        q = q.filter(Sample.test_id.in_(test_ids))
-        samples = list(q)
-
-        # Aggregate by test id and then run key.
-        #
-        # FIXME: Pretty expensive.
-        samples_by_test_id = {}
-        for run_id,test_id,value in samples:
-            d = samples_by_test_id.get(test_id)
-            if d is None:
-                d = samples_by_test_id[test_id] = Util.multidict()
-            run_key = run_summary.get_run_order(run_id)
-            if run_key is None:
-                continue
-
-            # FIXME: What to do on failure?
-            run_key = int(run_key)
-            d[run_key] = value
-
         # Build the graph data
         pset_id_map = dict([(pset,i)
                             for i,pset in enumerate(ts_summary.parameter_sets)])
         legend = []
+        num_points = 0
         plot_points = []
         plots = ""
-        num_plots = len(graph_tests) * len(graph_psets)
-        num_points = 0
-        index = 0
-        show_mad_error = True
-        show_points = True
-        show_all_points = False
-        for name in graph_tests:
-            for pset in graph_psets:
-                test_id = ts_summary.test_id_map[(name,pset)]
-
-                # Get the plot for this test.
-                #
-                # FIXME: Support order by something other than time.
-                errorbar_data = []
-                points_data = []
-                data = []
-                points = []
-                for x,values in samples_by_test_id.get(test_id,{}).items():
-                    min_value = min(values)
-                    data.append((x, min_value))
-                    if show_points:
-                        if show_all_points:
-                            for v in values:
-                                points_data.append((x, v))
-                        else:
-                            points_data.append((x, min_value))
-                    if show_mad_error:
-                        med = stats.median(values)
-                        mad = stats.median_absolute_deviation(values, med)
-                        errorbar_data.append((x, med - mad, med + mad))
-                        points.append((x, min_value, mad, med))
-                data.sort()
-                num_points += len(data)
-
-                col = list(Util.makeDarkColor(float(index) / num_plots))
-                pts = ','.join(['[%.4f,%.4f]' % (t,v)
-                                for t,v in data])
-                style = "new Graph2D_LinePlotStyle(1, %r)" % col
-                plots += "    graph.addPlot([%s], %s);\n" % (pts,style)
-
-                if points_data:
-                    pts_col = (0,0,0)
-                    pts = ','.join(['[%.4f,%.4f]' % (t,v)
-                                    for t,v in points_data])
-                    style = "new Graph2D_PointPlotStyle(1, %r)" % (pts_col,)
-                    plots += "    graph.addPlot([%s], %s);\n" % (pts,style)
-
-                if errorbar_data:
-                    bar_col = [c*.7 for c in col]
-                    pts = ','.join(['[%.4f,%.4f,%.4f]' % (x,y_min,y_max)
-                                    for x,y_min,y_max in errorbar_data])
-                    style = "new Graph2D_ErrorBarPlotStyle(1, %r)" % (bar_col,)
-                    plots += "    graph.addPlot([%s], %s);\n" % (pts,style)
-
-                legend.append(("%s : P%d" % (name, pset_id_map[pset]), col))
-                points.sort()
-                plot_points.append(points)
-                index += 1
+        plots_iter = GraphUtil.get_test_plots(db, machine, test_ids,
+                                              run_summary, ts_summary,
+                                              show_mad_error = True,
+                                              show_points = True)
+        for test_id, plot_js, col, points, ext_points in plots_iter:
+            test = db.getTest(test_id)
+            name = test.name
+            pset = test.get_parameter_set()
+
+            num_points += len(points)
+            legend.append(("%s : P%d" % (name, pset_id_map[pset]), col))
+            plots += plot_js
+            plot_points.append(ext_points)
 
         def graph_body [html] ():
             """
@@ -351,7 +285,7 @@
             <p>
             <b>Plots</b>: %d<br>
             <b>Num Points<b>: %d<br>
-            """ % (num_plots, num_points)
+            """ % (len(test_ids), num_points)
 
             """
             <h2>Deltas</h2>"""





More information about the llvm-commits mailing list