-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_workload_stats.py
191 lines (154 loc) · 7.19 KB
/
plot_workload_stats.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import os, sys
import seaborn as sns
import math
import matplotlib.font_manager as fm
import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter
import numpy as np
from matplotlib import ticker
params = {'figure.figsize' : [10, 7.2],
# 'font.family': 'MankSans-Medium',
'pdf.fonttype' : 42,
'ps.fonttype' : 42,
'grid.color': '#aaaaaa',
'grid.linestyle': '--',
'grid.linewidth': 1.0,
'figure.autolayout': True,
}
font_size = 23
legend_font_size = 17
plt.rcParams.update(params)
plt.rc('font', size=font_size) # controls default text sizes
plt.rc('axes', titlesize=font_size) # fontsize of the axes title
plt.rc('axes', labelsize=font_size) # fontsize of the x and y labels
plt.rc('xtick', labelsize=font_size-2) # fontsize of the tick labels
plt.rc('ytick', labelsize=font_size-2) # fontsize of the tick labels
plt.rc('legend', fontsize=legend_font_size) # legend fontsize
output_fmt = 'pdf'
# Color mapping (for consistent colors)
all_colors = sns.color_palette('PuBu', 5)
lcolors = ['#9ACD32', '#d43d3d', '#72a7db', '#e3c07d', '#ed98ed', '#755638', '#767676']
dcolors = ['#006400', '#990000', '#0066CC', '#FFA700', '#993399', '#753b05', '#333333']
folder_name = sys.argv[1]
save_folder = sys.argv[2]
histogram_workload = sys.argv[3]
workloads = ['apache2', 'axel', 'md5', 'ffmpeg', 'pbzip2']
workload_alloc_arr = {}
# read all 5 workloads:
for f in os.listdir(folder_name):
if ".txt" in f and (sum(list(map(lambda x: x in f, workloads))) > 0):
# get workload name:
wname = workloads[0]
for x in workloads:
if x in f:
wname = x
print("READING file %s for workload %s!!!"%(f, wname))
workload_alloc_arr[wname] = []
# read file:
with open( os.path.join(folder_name, f), 'r' ) as wf:
for wfl in wf.readlines():
if "malloc" in wfl:
workload_alloc_arr[wname].append( int(wfl.split(' ')[1] ) )
# Plot1: bar chart for avg, stdev of alloc sizes for all workloads
worokload_alloc_ct = [len(workload_alloc_arr[x]) for x in workloads]
workload_alloc_sum = [ sum(workload_alloc_arr[x]) for x in workloads]
workload_alloc_avg = [ np.mean(workload_alloc_arr[x]) for x in workloads ]
workload_alloc_med = [ np.percentile(workload_alloc_arr[x], 50) for x in workloads]
workload_alloc_stdev = [ np.std(workload_alloc_arr[x]) for x in workloads ]
print(workloads, "Count: ", worokload_alloc_ct, "Sum: ", workload_alloc_sum, " Avg: ", workload_alloc_avg, " Std: ", workload_alloc_stdev)
print("Median: ", workload_alloc_med)
def plot_bar(ally, allticks, ally_std, fname):
plt.clf()
allx = np.arange(len(ally))
bar_width = 0.8
fig, ax1 = plt.subplots(figsize=(10, 5), ncols=1, nrows=1, sharex=True, sharey=False)
# ax2 = ax1.twinx()
fig.tight_layout()
ax1.bar(allx, ally, width=bar_width, color=all_colors[1], label='Avg Allocation Size')
# ax1.errorbar(allx, ally, yerr=ally_std, fmt="o", color=all_colors[3], elinewidth=2.5)
ax1.set_xticks(allx) # , rotation = 0
ax1.set_xticklabels(allticks)
ax1.set_ylabel('Allocation Size (bytes)')
ax1.set_yscale('log')
# ax1.set_ylim(bottom = 10, top = 1000000)
# Increasing #ticks on y-axis of ax1:
# y1_ticks = ticker.MaxNLocator(5)
# ax1.yaxis.set_major_locator(y1_ticks)
# Adding gridlines
ax1.set_axisbelow(True) # to put the gridlines behind bars
ax1.yaxis.grid()
plt.savefig("%s_NoErrBar.%s"%(fname, output_fmt), format=output_fmt, bbox_inches='tight', pad_inches=0.1)
plot_bar(workload_alloc_avg, workloads, workload_alloc_stdev, os.path.join(save_folder, "All5Workloads_Avg_v2") )
# Plot2: Per workload, histogram of alloc sizes.
def plot_hist(arr, fname):
plt.clf()
max_sz = max(arr)
xarr = [ (pow(2,i)) for i in range(int(math.log(max_sz,2))+1) ]
print("arr: ", arr, " xarr: ", xarr, max_sz)
plt.hist(arr, xarr)
plt.yscale("log")
plt.xlabel("Allocation size (bytes)")
plt.ylabel("#Allocations")
# rotate xticks:
plt.xticks(rotation = 20)
# grid only on y-axis
plt.grid(True,axis="y")
plt.savefig("%s.%s"%(fname, output_fmt), format=output_fmt, bbox_inches='tight', pad_inches=0.1)
def plot_cdf(arr, fname):
plt.clf()
# v1: starts with 0.2
# count, bins_count = np.histogram(arr, bins=1000000)
# pdf = count / sum(count)
# cdf = np.cumsum(pdf)
# print("Arr len: ", len(arr), count[:10], pdf[:10], sum(count), cdf[:10], bins_count[:10], sorted(arr)[:10] )
# plt.plot(bins_count[1:], cdf, label="CDF")
# v2: directly using arr's values instead of binning:
s_arr = np.sort(arr)
pr = 1. * np.arange(len(arr))/(len(arr) - 1)
plt.plot(s_arr, pr, label="CDF")
plt.ylim(0,1)
# plt.xlim(1,20000)
plt.xscale('log')
plt.xlabel("Allocation size (bytes)")
plt.ylabel("CDF")
plt.savefig("%s_XLog.%s"%(fname, output_fmt), format=output_fmt, bbox_inches='tight', pad_inches=0.1)
def plot_multi_cdfs(dict_arr, fname):
plt.clf()
max_x = 10
ind = 0
for i in list(dict_arr.keys()):
i_s_arr = np.sort(dict_arr[i])
i_pr = 1. * np.arange(len(dict_arr[i]))/(len(dict_arr[i]) - 1)
plt.plot(i_s_arr, i_pr, label=i, color=dcolors[ind], lw=2)
max_x = max(max_x, max(dict_arr[i]))
ind += 1
plt.ylim(0,1)
plt.xlim(1,max_x+10)
plt.xticks([10, 100, 1000, 10000, 100000, 1000000, 10000000])
plt.xscale('log')
plt.xlabel("Allocation size (bytes)")
plt.ylabel("CDF")
plt.grid(True,axis="y")
leg = plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.2), ncol=len(dict_arr), handlelength=1.5, columnspacing=1.5)
leg.set_in_layout(False) # this makes the figure of original size, with legend outside.
# plt.margins(x=0.1,y=0.5)
plt.savefig("%s_XLog_Leg.%s"%(fname, output_fmt), format=output_fmt, bbox_inches='tight', pad_inches=0.5)
def plot_multi_cdfs_v2(dict_arr, fname):
plt.clf()
fig, ax1 = plt.subplots(figsize=(7, 3), ncols=1, nrows=1, sharex=True, sharey=False)
for i in list(dict_arr.keys()):
i_s_arr = np.sort(dict_arr[i])
i_pr = 1. * np.arange(len(dict_arr[i]))/(len(dict_arr[i]) - 1)
ax1.plot(i_s_arr, i_pr, label=i)
ax1.set_ylim(0,1)
ax1.set_xscale('log')
ax1.set_xlabel("Allocation size (bytes)")
ax1.set_ylabel("CDF")
ax1.set_axisbelow(True) # to put the gridlines behind bars
ax1.yaxis.grid()
fig.legend(loc='upper center', bbox_to_anchor=(0.5, 1.31), ncol=len(dict_arr))
# leg = plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.45), ncol=3)
plt.savefig("%s_V2.%s"%(fname, output_fmt), format=output_fmt) # , bbox_inches='tight', pad_inches=0.1
plot_hist(workload_alloc_arr[histogram_workload], os.path.join(save_folder, "%s_Workload_AllocSzHistogram"%(histogram_workload)))
plot_cdf(workload_alloc_arr[histogram_workload], os.path.join(save_folder, "%s_Workload_AllocSzCDF"%(histogram_workload)))
plot_multi_cdfs(workload_alloc_arr, os.path.join(save_folder, "All5Workloads_AllocSzCDF"))