From df914160599e71af95f428c3cf59165fba92d102 Mon Sep 17 00:00:00 2001 From: Eugeni Dodonov Date: Tue, 8 Nov 2011 17:36:45 -0200 Subject: intel_gpu_analyze: refactor plot generations This adds a helper function to do the plotting and checking for valid column names. Signed-off-by: Eugeni Dodonov --- tools/intel_gpu_analyze.py | 83 ++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 47 deletions(-) diff --git a/tools/intel_gpu_analyze.py b/tools/intel_gpu_analyze.py index 4974f45..eb63843 100755 --- a/tools/intel_gpu_analyze.py +++ b/tools/intel_gpu_analyze.py @@ -187,6 +187,16 @@ def analyse_perf(logfile, out_dir, perf="perf.html"): print >>output, TAIL output.close() +def plot_series(timeline, values, results, axis, title, linestyle='solid'): + """A helper function to simplify plotting of a function + from the array of results. It checks if the column does, in fact, + exists; and if it does, carries on with plotting""" + for column in [timeline, values]: + if column not in results: + print "Column %s not available for plotting" % values + return + axis.plot(results[timeline], results[values], label=title, linestyle=linestyle) + def analyse(results, title, out_dir, perf_logfile=None, summary="index.html"): """Analyses intel_gpu_top results""" # calculate min/max/avg values @@ -254,24 +264,23 @@ def analyse(results, title, out_dir, perf_logfile=None, summary="index.html"): pylab.ylabel("Usage (%)") pylab.xlabel("Time (s)") - if 'utime' in results: - ax.plot(results['time'], results['utime'], label="User time") - if 'stime' in results: - ax.plot(results['time'], results['stime'], label="System time") + plot_series('time', 'utime', results, ax, "User time") + plot_series('time', 'stime', results, ax, "System time") num_axis = 2 for ring in ["render", "bitstream", "bitstream6", "blitter"]: if results.get("%s_avg" % ring, -1) == -1: print "No data for %s, skipping" % ring continue - ax.plot(results['time'], results[ring], label=ring) + plot_series('time', ring, results, ax, ring) num_axis += 1 # Do we have power? if results.get("power_avg", -1) != -1: # plotting power ax2 = ax.twinx() - ax2.plot(results['time'], results["power"], label="Power (W)", color='red') + plot_series('time', 'power', results, ax2, "Power", "dotted") ax2.set_ylabel('Watts') ax2.set_position([box.x0, box.y0 + box.height * 0.1, box.width, box.height * 0.9]) + ax2.legend(loc = 'upper center', ncol=3, fancybox=True, shadow=True, bbox_to_anchor = (0.5, 0.0)) pylab.grid() # Shink current axis's height by 10% on the bottom @@ -291,10 +300,7 @@ def analyse(results, title, out_dir, perf_logfile=None, summary="index.html"): num_axis = 0 for ring in ["render.ops", "bitstream.ops", "bitstream6.ops", "blitter.ops"]: - if results.get("%s_avg" % ring, -1) == -1: - print "No data for %s, skipping" % ring - continue - ax.plot(results['time'], results[ring], label=ring) + plot_series('time', ring, results, ax, ring) num_axis += 1 pylab.grid() @@ -314,12 +320,9 @@ def analyse(results, title, out_dir, perf_logfile=None, summary="index.html"): pylab.xlabel("Time (s)") ax = pylab.subplot(111) - if "power" in results: - ax.plot(results['time'], results["power"], label="Power (W)", color='red') - if "power.chipset" in results: - ax.plot(results['time'], results['power.chipset'], label="Chipset", color='g') - if "power.gfx" in results: - ax.plot(results['time'], results['power.gfx'], label="GFX", color='m') + plot_series('time', 'power', results, ax, "Power") + plot_series('time', 'power.chipset', results, ax, "Chipset") + plot_series('time', 'power.gfx', results, ax, "GFX") ax.set_position([box.x0, box.y0 + box.height * 0.1, box.width, box.height * 0.9]) ax.legend(loc = 'upper center', ncol=3, fancybox=True, shadow=True, bbox_to_anchor = (0.5, -0.1)) pylab.grid() @@ -332,24 +335,23 @@ def analyse(results, title, out_dir, perf_logfile=None, summary="index.html"): # power vs CPU fig = pylab.figure() ax = pylab.subplot(111) + ax.set_position([box.x0, box.y0 + box.height * 0.1, box.width, box.height * 0.9]) pylab.title("CPU vs Power usage") pylab.ylabel("Usage (%)") pylab.xlabel("Time (s)") - if 'utime' in results: - ax.plot(results['time'], results['utime'], label="User time") - if 'stime' in results: - ax.plot(results['time'], results['stime'], label="System time") + plot_series('time', 'utime', results, ax, "User time") + plot_series('time', 'stime', results, ax, "System time") # plotting power if 'power' in results: ax2 = ax.twinx() - ax2.plot(results['time'], results["power"], label="Power (W)", color='red') + plot_series('time', 'power', results, ax2, "Power", "dashed") ax2.set_ylabel('Watts') + ax2.legend(loc = 'upper center', ncol=1, fancybox=True, shadow=True, bbox_to_anchor = (0.5, 0.0)) pylab.grid() # Shink current axis's height by 10% on the bottom box = ax.get_position() - ax.set_position([box.x0, box.y0 + box.height * 0.1, box.width, box.height * 0.9]) ax.legend(loc = 'upper center', ncol=3, fancybox=True, shadow=True, bbox_to_anchor = (0.5, -0.1)) pylab.savefig("%s/plot_power_cpu.svg" % out_dir, format="svg", dpi=200) print >>output, FIGURE % {'img': 'plot_power_cpu.svg', @@ -365,20 +367,14 @@ def analyse(results, title, out_dir, perf_logfile=None, summary="index.html"): num_axis = 0 for ring in ["render", "bitstream", "bitstream6", "blitter"]: - if results.get("%s_avg" % ring, -1) == -1: - print "No data for %s, skipping" % ring - continue - ax.plot(results['time'], results[ring], label=ring) + plot_series('time', ring, results, ax, ring, "dashed") num_axis += 1 # Do we have power? # plotting power ax2 = ax.twinx() - if "power" in results: - ax2.plot(results['time'], results["power"], label="Power (W)", color='red') - if "power.chipset" in results: - ax2.plot(results['time'], results['power.chipset'], label="Chipset", color='g') - if "power.gfx" in results: - ax2.plot(results['time'], results['power.gfx'], label="GFX", color='m') + plot_series('time', 'power', results, ax2, "Power") + plot_series('time', 'power.chipset', results, ax2, "Chipset") + plot_series('time', 'power.gfx', results, ax2, "GFX") ax2.set_ylabel('Watts') num_axis += 1 @@ -388,7 +384,7 @@ def analyse(results, title, out_dir, perf_logfile=None, summary="index.html"): ax.set_position([box.x0, box.y0 + box.height * 0.1, box.width, box.height * 0.9]) ax2.set_position([box.x0, box.y0 + box.height * 0.1, box.width, box.height * 0.9]) ax.legend(loc = 'upper center', ncol=num_axis, fancybox=True, shadow=True, bbox_to_anchor = (0.5, -0.1)) - ax2.legend(loc = 'upper center', ncol=3, fancybox=True, shadow=True, bbox_to_anchor = (0.5, 0.2)) + ax2.legend(loc = 'upper center', ncol=3, fancybox=True, shadow=True, bbox_to_anchor = (0.5, 0.0)) pylab.savefig("%s/plot_power_gpu.svg" % out_dir, format="svg", dpi=200) print >>output, FIGURE % {'img': 'plot_power_gpu.svg', 'title': 'Power utilization co-related to all GPU rings' @@ -396,34 +392,27 @@ def analyse(results, title, out_dir, perf_logfile=None, summary="index.html"): # per-ring power for ring in ["render", "bitstream", "bitstream6", "blitter"]: - if results.get("%s_avg" % ring, -1) == -1: - print "No data for %s, skipping" % ring - continue fig = pylab.figure() ax = pylab.subplot(111) + box = ax.get_position() + ax.set_position([box.x0, box.y0 + box.height * 0.1, box.width, box.height * 0.9]) pylab.title("Power usage vs %s ring" % ring) pylab.ylabel("Usage (%)") pylab.xlabel("Time (s)") - ax.plot(results['time'], results[ring], label=ring) - # Do we have power? + plot_series('time', ring, results, ax, ring, "dashed") # plotting power ax2 = ax.twinx() - if "power" in results: - ax2.plot(results['time'], results["power"], label="Power (W)", color='red') - if "power.chipset" in results: - ax2.plot(results['time'], results['power.chipset'], label="Chipset", color='g') - if "power.gfx" in results: - ax2.plot(results['time'], results['power.gfx'], label="GFX", color='m') + plot_series('time', 'power', results, ax2, "Power") + plot_series('time', 'power.chipset', results, ax2, "Chipset") + plot_series('time', 'power.gfx', results, ax2, "GFX") ax2.set_ylabel('Watts') pylab.grid() # Shink current axis's height by 10% on the bottom - box = ax.get_position() - ax.set_position([box.x0, box.y0 + box.height * 0.1, box.width, box.height * 0.9]) ax2.set_position([box.x0, box.y0 + box.height * 0.1, box.width, box.height * 0.9]) ax.legend(loc = 'upper center', ncol=1, fancybox=True, shadow=True, bbox_to_anchor = (0.5, -0.1)) - ax2.legend(loc = 'upper center', ncol=3, fancybox=True, shadow=True, bbox_to_anchor = (0.5, 0.2)) + ax2.legend(loc = 'upper center', ncol=3, fancybox=True, shadow=True, bbox_to_anchor = (0.5, 0.0)) pylab.savefig("%s/plot_power_gpu_%s.svg" % (out_dir, ring), format="svg", dpi=200) print >>output, FIGURE % {'img': 'plot_power_gpu_%s.svg' % ring, 'title': 'Power utilization co-related to the %s ring' % ring -- cgit v1.2.1