From 9b4e797cdd7e10ace8de83626ea844a6acabcafb Mon Sep 17 00:00:00 2001 From: Radhika Jagtap Date: Wed, 21 Jun 2017 11:17:43 +0100 Subject: util: Add script to plot DRAM low power sweep This change adds a script to generate graphs from the stats file output by the configuration script low_power_sweep.py. The graphs show stacked bars for time spent and energy consumed wherein each component of the stacked bar represents a DRAM power state (Idle, Refresh, Active, Active Power-down, Precharge Power-down and Self-refresh). The script generates one plot per delay value. It also generates a pdf (--pdf option) in which the graphs are laid out such that you can easily compare how the increasing delay and other swept params affect the resulting energy. Change-Id: Id80b0947bfde27e11e5505b23a3adb30f793a43f Reviewed-by: Wendy Elsasser Reviewed-on: https://gem5-review.googlesource.com/5727 Reviewed-by: Andreas Sandberg Maintainer: Andreas Sandberg --- util/plot_dram/dram_lat_mem_rd_plot.py | 151 +++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100755 util/plot_dram/dram_lat_mem_rd_plot.py (limited to 'util/plot_dram/dram_lat_mem_rd_plot.py') diff --git a/util/plot_dram/dram_lat_mem_rd_plot.py b/util/plot_dram/dram_lat_mem_rd_plot.py new file mode 100755 index 000000000..422b14049 --- /dev/null +++ b/util/plot_dram/dram_lat_mem_rd_plot.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python2 + +# Copyright (c) 2015 ARM Limited +# All rights reserved +# +# The license below extends only to copyright in the software and shall +# not be construed as granting a license to any other intellectual +# property including but not limited to intellectual property relating +# to a hardware implementation of the functionality of the software +# licensed hereunder. You may use the software subject to the license +# terms below provided that you ensure that this notice is replicated +# unmodified and in its entirety in all distributions of the software, +# modified or unmodified, in source code or in binary form. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer; +# redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution; +# neither the name of the copyright holders nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Authors: Andreas Hansson + +try: + import matplotlib.pyplot as plt + import matplotlib as mpl + import numpy as np +except ImportError: + print "Failed to import matplotlib and numpy" + exit(-1) + +import sys +import re + +# This script is intended to post process and plot the output from +# running configs/dram/lat_mem_rd.py, as such it parses the simout and +# stats.txt to get the relevant data points. +def main(): + + if len(sys.argv) != 2: + print "Usage: ", sys.argv[0], "" + exit(-1) + + try: + stats = open(sys.argv[1] + '/stats.txt', 'r') + except IOError: + print "Failed to open ", sys.argv[1] + '/stats.txt', " for reading" + exit(-1) + + try: + simout = open(sys.argv[1] + '/simout', 'r') + except IOError: + print "Failed to open ", sys.argv[1] + '/simout', " for reading" + exit(-1) + + # Get the address ranges + got_ranges = False + ranges = [] + + iterations = 1 + + for line in simout: + if got_ranges: + ranges.append(int(line) / 1024) + + match = re.match("lat_mem_rd with (\d+) iterations, ranges:.*", line) + if match: + got_ranges = True + iterations = int(match.groups(0)[0]) + + simout.close() + + if not got_ranges: + print "Failed to get address ranges, ensure simout is up-to-date" + exit(-1) + + # Now parse the stats + raw_rd_lat = [] + + for line in stats: + match = re.match(".*readLatencyHist::mean\s+(.+)\s+#.*", line) + if match: + raw_rd_lat.append(float(match.groups(0)[0]) / 1000) + stats.close() + + # The stats also contain the warming, so filter the latency stats + i = 0 + filtered_rd_lat = [] + for l in raw_rd_lat: + if i % (iterations + 1) == 0: + pass + else: + filtered_rd_lat.append(l) + i = i + 1 + + # Next we need to take care of the iterations + rd_lat = [] + for i in range(iterations): + rd_lat.append(filtered_rd_lat[i::iterations]) + + final_rd_lat = map(lambda p: min(p), zip(*rd_lat)) + + # Sanity check + if not (len(ranges) == len(final_rd_lat)): + print "Address ranges (%d) and read latency (%d) do not match" % \ + (len(ranges), len(final_rd_lat)) + exit(-1) + + for (r, l) in zip(ranges, final_rd_lat): + print r, round(l, 2) + + # lazy version to check if an integer is a power of two + def is_pow2(num): + return num != 0 and ((num & (num - 1)) == 0) + + plt.semilogx(ranges, final_rd_lat) + + # create human readable labels + xticks_locations = [r for r in ranges if is_pow2(r)] + xticks_labels = [] + for x in xticks_locations: + if x < 1024: + xticks_labels.append('%d kB' % x) + else: + xticks_labels.append('%d MB' % (x / 1024)) + plt.xticks(xticks_locations, xticks_labels, rotation=-45) + + plt.minorticks_off() + plt.xlim((xticks_locations[0], xticks_locations[-1])) + plt.ylabel("Latency (ns)") + plt.grid(True) + plt.show() + +if __name__ == "__main__": + main() -- cgit v1.2.3