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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
|
from pathlib import Path
from matplotlib import pyplot as plt
linewidth = 2
# markers= ['+', ',', 'o', '.', 's', 'v', 'x', '>', '<', '^']
# markers= [ 'x', '+', 'o', 's', 'v', '^', '>', '<', ]
markers = [
"s",
"o",
"v",
"^",
"+",
"x",
">",
"<",
]
markersize = 8
def get_values(filename):
sizes = []
values = []
isize = None
txtime = 0
for line in Path(filename).read_text().splitlines():
if line.startswith("range"):
tmp = line.split(":")[1]
tmp = tmp.strip()
tmp = tmp[1:-1]
lower, upper = int(tmp.split(",")[0]), int(tmp.split(",")[1])
isize = upper - lower
# print "isize-->", isize
if isize is None or isize == 0:
continue
if insert and line.startswith("Insert time"):
tmp = line.split(":")[1]
# itime = float(tmp[:tmp.index(',')])
itime = float(tmp)
sizes.append(isize)
values.append(itime)
elif line.startswith("Index time"):
tmp = line.split(":")[1]
# xtime = float(tmp[:tmp.index(',')])
xtime = float(tmp)
txtime += xtime
if create_index and create_index in line:
sizes.append(isize)
values.append(xtime)
elif create_total and txtime > xtime:
sizes.append(isize)
values.append(txtime)
elif table_size and line.startswith("Table size"):
tsize = float(line.split(":")[1])
sizes.append(isize)
values.append(tsize)
elif indexes_size and line.startswith("Indexes size"):
xsize = float(line.split(":")[1])
sizes.append(isize)
values.append(xsize)
elif total_size and line.startswith("Full size"):
fsize = float(line.split(":")[1])
sizes.append(isize)
values.append(fsize)
elif (query or query_cold or query_warm) and line.startswith(
"[NOREP]"
):
tmp = line.split(":")[1]
try:
qtime = float(tmp[: tmp.index("+-")])
except ValueError:
qtime = float(tmp)
if colname in line:
if query and "1st" in line:
sizes.append(isize)
values.append(qtime)
elif query_cold and "cold" in line:
sizes.append(isize)
values.append(qtime)
elif query_warm and "warm" in line:
sizes.append(isize)
values.append(qtime)
return sizes, values
def show_plot(plots, yaxis, legends, gtitle):
plt.xlabel("Number of hits")
plt.ylabel(yaxis)
plt.title(gtitle)
# plt.ylim(0, 100)
plt.grid(True)
# legends = [f[f.find('-'):f.index('.out')] for f in filenames]
# legends = [l.replace('-', ' ') for l in legends]
# plt.legend([p[0] for p in plots], legends, loc = "upper left")
plt.legend([p[0] for p in plots], legends, loc="best")
# plt.subplots_adjust(bottom=0.2, top=None, wspace=0.2, hspace=0.2)
if outfile:
plt.savefig(outfile)
else:
plt.show()
if __name__ == "__main__":
import sys
import getopt
usage = (
"""usage: %s [-o file] [-t title] [--insert] [--create-index] [--create-total] [--table-size] [--indexes-size] [--total-size] [--query=colname] [--query-cold=colname] [--query-warm=colname] files
-o filename for output (only .png and .jpg extensions supported)
-t title of the plot
--insert -- Insert time for table
--create-index=colname -- Index time for column
--create-total -- Total time for creation of table + indexes
--table-size -- Size of table
--indexes-size -- Size of all indexes
--total-size -- Total size of table + indexes
--query=colname -- Time for querying the specified column
--query-cold=colname -- Time for querying the specified column (cold cache)
--query-warm=colname -- Time for querying the specified column (warm cache)
\n"""
% sys.argv[0]
)
try:
opts, pargs = getopt.getopt(
sys.argv[1:],
"o:t:",
[
"insert",
"create-index=",
"create-total",
"table-size",
"indexes-size",
"total-size",
"query=",
"query-cold=",
"query-warm=",
],
)
except Exception:
sys.stderr.write(usage)
sys.exit(0)
progname = sys.argv[0]
args = sys.argv[1:]
# if we pass too few parameters, abort
if len(pargs) < 1:
sys.stderr.write(usage)
sys.exit(0)
# default options
outfile = None
insert = 0
create_index = None
create_total = 0
table_size = 0
indexes_size = 0
total_size = 0
query = 0
query_cold = 0
query_warm = 0
colname = None
yaxis = "No axis name"
tit = None
gtitle = "Please set a title!"
# Get the options
for option in opts:
if option[0] == "-o":
outfile = option[1]
elif option[0] == "-t":
tit = option[1]
elif option[0] == "--insert":
insert = 1
yaxis = "Time (s)"
gtitle = "Insert time for table"
elif option[0] == "--create-index":
create_index = option[1]
yaxis = "Time (s)"
gtitle = "Create index time for column " + create_index
elif option[0] == "--create-total":
create_total = 1
yaxis = "Time (s)"
gtitle = "Create time for table + indexes"
elif option[0] == "--table-size":
table_size = 1
yaxis = "Size (MB)"
gtitle = "Table size"
elif option[0] == "--indexes-size":
indexes_size = 1
yaxis = "Size (MB)"
gtitle = "Indexes size"
elif option[0] == "--total-size":
total_size = 1
yaxis = "Size (MB)"
gtitle = "Total size (table + indexes)"
elif option[0] == "--query":
query = 1
colname = option[1]
yaxis = "Time (s)"
gtitle = "Query time for " + colname + " column (first query)"
elif option[0] == "--query-cold":
query_cold = 1
colname = option[1]
yaxis = "Time (s)"
gtitle = "Query time for " + colname + " column (cold cache)"
elif option[0] == "--query-warm":
query_warm = 1
colname = option[1]
yaxis = "Time (s)"
gtitle = "Query time for " + colname + " column (warm cache)"
filenames = pargs
if tit:
gtitle = tit
plots = []
legends = []
for filename in filenames:
plegend = filename[filename.find("-") : filename.index(".out")]
plegend = plegend.replace("-", " ")
xval, yval = get_values(filename)
print(f"Values for {filename} --> {xval}, {yval}")
if "PyTables" in filename or "pytables" in filename:
plot = plt.loglog(xval, yval, linewidth=2)
# plot = semilogx(xval, yval, linewidth=2)
plots.append(plot)
plt.setp(
plot,
marker=markers[0],
markersize=markersize,
linewidth=linewidth,
)
else:
plots.append(plt.loglog(xval, yval, linewidth=3, color="m"))
# plots.append(semilogx(xval, yval, linewidth=3, color='m'))
# plots.append(semilogx(xval, yval, linewidth=5))
legends.append(plegend)
if 0: # Per a introduir dades simulades si es vol...
xval = [
1000,
10_000,
100_000,
1_000_000,
10_000_000,
100_000_000,
1_000_000_000,
]
# yval = [0.003, 0.005, 0.02, 0.06, 1.2,
# 40, 210]
yval = [0.0009, 0.0011, 0.0022, 0.005, 0.02, 0.2, 5.6]
plots.append(plt.loglog(xval, yval, linewidth=5))
legends.append("PyTables Std")
show_plot(plots, yaxis, legends, gtitle)
|