-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvis_trace_heatmap.py
More file actions
68 lines (51 loc) · 2.17 KB
/
vis_trace_heatmap.py
File metadata and controls
68 lines (51 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import csv, sys
import numpy as np
import matplotlib.pyplot as plt
from sim.perf_model import *
plt.rc('xtick', labelsize='x-small')
plt.rc('ytick', labelsize='x-small')
def plot_scatter(dataX, dataY, xtitle, ytitle, title, outname, format):
plt.figure(figsize=(2.5, 2), dpi=250)
ax = plt.subplot(111)
plt.grid(b=True, linestyle='--')
ax.set_axisbelow(True)
plt.plot(dataX, dataY, '.', markersize=0.0001, color='black')
ax.set_xticks([])
ax.set_yticks([])
ax.set_ylabel(ytitle, fontsize='small')
ax.set_xlabel(xtitle, fontsize='small')
ax.set_title(title, fontsize='small')
plt.tight_layout()
plt.savefig(outname + "." + format, format=format)
plt.show()
def plot_heatmap(data, xtitle, ytitle, title, outname, format):
plt.figure(figsize=(3, 2), dpi=250)
ax = plt.subplot(111)
ax.set_axisbelow(True)
im = ax.imshow(data, cmap='Reds', interpolation='nearest', aspect='auto', origin='lower')
plt.colorbar(im, ticks=[0, int(np.max(data))])
# ax.set_yticks([])
ax.set_ylabel(ytitle, fontsize='small')
ax.set_xlabel(xtitle, fontsize='small')
ax.set_title(title, fontsize='small')
plt.tight_layout()
plt.savefig(outname + "." + format, format=format)
plt.show()
if __name__ == "__main__":
# Example run: python vis_trace_heatmap.py traces/pin_traces/trace_backprop_10000.txt heatmap.csv 5000
trace_file = sys.argv[1]
resfile = sys.argv[2]
reqs_per_period = int(sys.argv[3])
prof = Profile(trace_file)
prof.init()
sim = PerfModel(prof, 'Fast:NearSlow', 'oracle', 0.2, reqs_per_period)
sim.init()
# Plot memory access trace
plot_scatter(range(prof.traffic.num_reqs), [req.page_id for req in prof.traffic.req_seq], 'Access (Time)', 'Page (Space)', 'Memory Access Trace', 'trace', 'png')
# Plot heatmap of per page access counts across periods
plot_heatmap([page.oracle_counts_binned_ep for page in prof.hmem.page_list], 'Period', 'Page', 'Page Access Counts', 'heatmap', 'png')
# Write to csv: row = page, columns = per page access counts during a period
w = csv.writer(open(resfile, "w"))
for page in prof.hmem.page_list:
# prints the page's access counts across periods
w.writerow(page.oracle_counts_binned_ep)