util: Port util to python3
This commit is the result of running 2to3 converter on the util subdirectory JIRA: https://gem5.atlassian.net/browse/GEM5-832 Change-Id: I4e7e2d2b1b99f7bcc5fe0f6dc5d25880323616eb Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/37797 Reviewed-by: Hoa Nguyen <hoanguyen@ucdavis.edu> Maintainer: Gabe Black <gabe.black@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -166,7 +166,7 @@ def plotLowPStates(plot_dir, stats_fname, bank_util_list, seqbytes_list,
|
||||
results[delay][bank_util][seq_bytes][state] = \
|
||||
int(stime)
|
||||
#### state energy values ####
|
||||
elif line.strip().split()[0] in StatToKey.keys():
|
||||
elif line.strip().split()[0] in list(StatToKey.keys()):
|
||||
# Example format:
|
||||
# system.mem_ctrls_0.actEnergy 35392980
|
||||
statistic, e_val = line.strip().split()[0:2]
|
||||
@@ -211,14 +211,14 @@ def plotIdle(plot_dir):
|
||||
fig, ax = plt.subplots()
|
||||
width = 0.35
|
||||
ind = np.arange(len(States))
|
||||
l1 = ax.bar(ind, map(lambda x : idleResults[x], States), width)
|
||||
l1 = ax.bar(ind, [idleResults[x] for x in States], width)
|
||||
|
||||
ax.xaxis.set_ticks(ind + width/2)
|
||||
ax.xaxis.set_ticklabels(States)
|
||||
ax.set_ylabel('Time (ps) spent in a power state')
|
||||
fig.suptitle("Idle 50 us")
|
||||
|
||||
print "saving plot:", idlePlotName(plot_dir)
|
||||
print("saving plot:", idlePlotName(plot_dir))
|
||||
plt.savefig(idlePlotName(plot_dir), format='eps')
|
||||
plt.close(fig)
|
||||
|
||||
@@ -251,16 +251,15 @@ def plotStackedStates(delay, states_list, bottom_state, plot_name, ylabel_str):
|
||||
# Must have a bottom of the stack first
|
||||
state = bottom_state
|
||||
|
||||
l_states[state] = map(lambda x: results[delay][bank_util][x][state],
|
||||
seqBytesValues)
|
||||
l_states[state] = [results[delay][bank_util][x][state] \
|
||||
for x in seqBytesValues]
|
||||
p_states[state] = ax[sub_idx].bar(ind, l_states[state], width,
|
||||
color=StackColors[state])
|
||||
|
||||
time_sum = l_states[state]
|
||||
for state in states_list[1:]:
|
||||
l_states[state] = map(lambda x:
|
||||
results[delay][bank_util][x][state],
|
||||
seqBytesValues)
|
||||
l_states[state] = [results[delay][bank_util][x][state] \
|
||||
for x in seqBytesValues]
|
||||
# Now add on top of the bottom = sum of values up until now
|
||||
p_states[state] = ax[sub_idx].bar(ind, l_states[state], width,
|
||||
color=StackColors[state],
|
||||
@@ -280,11 +279,11 @@ def plotStackedStates(delay, states_list, bottom_state, plot_name, ylabel_str):
|
||||
myFontSize='small'
|
||||
fontP = FontProperties()
|
||||
fontP.set_size(myFontSize)
|
||||
fig.legend(map(lambda x: p_states[x], states_list), states_list,
|
||||
fig.legend([p_states[x] for x in states_list], states_list,
|
||||
prop=fontP)
|
||||
|
||||
plt.savefig(plot_name, format='eps', bbox_inches='tight')
|
||||
print "saving plot:", plot_name
|
||||
print("saving plot:", plot_name)
|
||||
plt.close(fig)
|
||||
|
||||
# These plat name functions are also called in the main script
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2.7
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (c) 2015 ARM Limited
|
||||
# All rights reserved
|
||||
@@ -40,7 +40,7 @@ try:
|
||||
import matplotlib as mpl
|
||||
import numpy as np
|
||||
except ImportError:
|
||||
print "Failed to import matplotlib and numpy"
|
||||
print("Failed to import matplotlib and numpy")
|
||||
exit(-1)
|
||||
|
||||
import sys
|
||||
@@ -52,19 +52,19 @@ import re
|
||||
def main():
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print "Usage: ", sys.argv[0], "<simout directory>"
|
||||
print("Usage: ", sys.argv[0], "<simout directory>")
|
||||
exit(-1)
|
||||
|
||||
try:
|
||||
stats = open(sys.argv[1] + '/stats.txt', 'r')
|
||||
except IOError:
|
||||
print "Failed to open ", sys.argv[1] + '/stats.txt', " for reading"
|
||||
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"
|
||||
print("Failed to open ", sys.argv[1] + '/simout', " for reading")
|
||||
exit(-1)
|
||||
|
||||
# Get the address ranges
|
||||
@@ -85,7 +85,7 @@ def main():
|
||||
simout.close()
|
||||
|
||||
if not got_ranges:
|
||||
print "Failed to get address ranges, ensure simout is up-to-date"
|
||||
print("Failed to get address ranges, ensure simout is up-to-date")
|
||||
exit(-1)
|
||||
|
||||
# Now parse the stats
|
||||
@@ -112,16 +112,16 @@ def main():
|
||||
for i in range(iterations):
|
||||
rd_lat.append(filtered_rd_lat[i::iterations])
|
||||
|
||||
final_rd_lat = map(lambda p: min(p), zip(*rd_lat))
|
||||
final_rd_lat = [min(p) for p in 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))
|
||||
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)
|
||||
print(r, round(l, 2))
|
||||
|
||||
# lazy version to check if an integer is a power of two
|
||||
def is_pow2(num):
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2.7
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (c) 2014 ARM Limited
|
||||
# All rights reserved
|
||||
@@ -41,7 +41,7 @@ try:
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
except ImportError:
|
||||
print "Failed to import matplotlib and numpy"
|
||||
print("Failed to import matplotlib and numpy")
|
||||
exit(-1)
|
||||
|
||||
import sys
|
||||
@@ -54,13 +54,13 @@ import re
|
||||
def main():
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
print "Usage: ", sys.argv[0], "-u|p|e <simout directory>"
|
||||
print("Usage: ", sys.argv[0], "-u|p|e <simout directory>")
|
||||
exit(-1)
|
||||
|
||||
if len(sys.argv[1]) != 2 or sys.argv[1][0] != '-' or \
|
||||
not sys.argv[1][1] in "upe":
|
||||
print "Choose -u (utilisation), -p (total power), or -e " \
|
||||
"(power efficiency)"
|
||||
print("Choose -u (utilisation), -p (total power), or -e " \
|
||||
"(power efficiency)")
|
||||
exit(-1)
|
||||
|
||||
# Choose the appropriate mode, either utilisation, total power, or
|
||||
@@ -70,13 +70,13 @@ def main():
|
||||
try:
|
||||
stats = open(sys.argv[2] + '/stats.txt', 'r')
|
||||
except IOError:
|
||||
print "Failed to open ", sys.argv[2] + '/stats.txt', " for reading"
|
||||
print("Failed to open ", sys.argv[2] + '/stats.txt', " for reading")
|
||||
exit(-1)
|
||||
|
||||
try:
|
||||
simout = open(sys.argv[2] + '/simout', 'r')
|
||||
except IOError:
|
||||
print "Failed to open ", sys.argv[2] + '/simout', " for reading"
|
||||
print("Failed to open ", sys.argv[2] + '/simout', " for reading")
|
||||
exit(-1)
|
||||
|
||||
# Get the burst size, number of banks and the maximum stride from
|
||||
@@ -95,7 +95,7 @@ def main():
|
||||
simout.close()
|
||||
|
||||
if not got_sweep:
|
||||
print "Failed to establish sweep details, ensure simout is up-to-date"
|
||||
print("Failed to establish sweep details, ensure simout is up-to-date")
|
||||
exit(-1)
|
||||
|
||||
# Now parse the stats
|
||||
@@ -120,7 +120,7 @@ def main():
|
||||
|
||||
# Sanity check
|
||||
if not (len(peak_bw) == len(bus_util) and len(bus_util) == len(avg_pwr)):
|
||||
print "Peak bandwidth, bus utilisation, and average power do not match"
|
||||
print("Peak bandwidth, bus utilisation, and average power do not match")
|
||||
exit(-1)
|
||||
|
||||
# Collect the selected metric as our Z-axis, we do this in a 2D
|
||||
@@ -139,7 +139,7 @@ def main():
|
||||
# avg_pwr is in mW, peak_bw in MiByte/s, bus_util in percent
|
||||
z.append(avg_pwr[j] / (bus_util[j] / 100.0 * peak_bw[j] / 1000.0))
|
||||
else:
|
||||
print "Unexpected mode %s" % mode
|
||||
print("Unexpected mode %s" % mode)
|
||||
exit(-1)
|
||||
|
||||
i += 1
|
||||
@@ -152,7 +152,7 @@ def main():
|
||||
|
||||
# We should have a 2D grid with as many columns as banks
|
||||
if len(zs) != banks:
|
||||
print "Unexpected number of data points in stats output"
|
||||
print("Unexpected number of data points in stats output")
|
||||
exit(-1)
|
||||
|
||||
fig = plt.figure()
|
||||
|
||||
@@ -81,7 +81,7 @@ def main():
|
||||
# place tex and pdf files in outdir
|
||||
os.chdir(args.outdir)
|
||||
texfile_s = 'stacked_lowp_sweep.tex'
|
||||
print "\t", texfile_s
|
||||
print("\t", texfile_s)
|
||||
outfile = open(texfile_s, 'w')
|
||||
|
||||
startDocText(outfile)
|
||||
@@ -106,9 +106,9 @@ def main():
|
||||
endDocText(outfile)
|
||||
outfile.close()
|
||||
|
||||
print "\n Generating pdf file"
|
||||
print "*******************************"
|
||||
print "\tpdflatex ", texfile_s
|
||||
print("\n Generating pdf file")
|
||||
print("*******************************")
|
||||
print("\tpdflatex ", texfile_s)
|
||||
# Run pdflatex to generate to pdf
|
||||
call(["pdflatex", texfile_s])
|
||||
call(["open", texfile_s.split('.')[0] + '.pdf'])
|
||||
|
||||
Reference in New Issue
Block a user