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
|
#!/usr/bin/env python
# a stacked bar plot with errorbars
from pathlib import Path
import numpy as np
from matplotlib import pyplot as plt
checks = [
"open_close",
"only_open",
"full_browse",
"partial_browse",
"full_browse_attrs",
"partial_browse_attrs",
"open_group",
"open_leaf",
"total",
]
width = 0.15 # the width of the bars: can also be len(x) sequence
colors = ["r", "m", "g", "y", "b"]
ind = np.arange(len(checks)) # the x locations for the groups
def get_values(filename):
values = []
for line in Path(filename).read_text().splitlines():
if show_memory:
if line.startswith("VmData:"):
values.append(float(line.split()[1]) / 1024)
else:
if line.startswith("WallClock time:"):
values.append(float(line.split(":")[1]))
return values
def plot_bar(values, n):
global ind
if not gtotal:
# Remove the grand totals
values.pop()
if n == 0:
checks.pop()
ind = np.arange(len(checks))
p = plt.bar(ind + width * n, values, width, color=colors[n])
return p
def show_plot(bars, filenames, tit):
if show_memory:
plt.ylabel("Memory (MB)")
else:
plt.ylabel("Time (s)")
plt.title(tit)
n = len(filenames)
plt.xticks(
ind + width * n / 2,
checks,
rotation=45,
horizontalalignment="right",
fontsize=8,
)
if not gtotal:
# loc = 'center right'
loc = "upper left"
else:
loc = "center left"
legends = [filename[: filename.index("_")] for filename in filenames]
legends = [line.replace("-", " ") for line in legends]
plt.legend([p[0] for p in bars], legends, loc=loc)
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 [-g] [-m] [-o file] [-t title] files
-g grand total
-m show memory instead of time
-o filename for output (only .png and .jpg extensions supported)
-t title of the plot
\n"""
% sys.argv[0]
)
try:
opts, pargs = getopt.getopt(sys.argv[1:], "gmo:t:")
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
tit = "Comparison of differents PyTables versions"
gtotal = 0
show_memory = 0
outfile = None
# Get the options
for option in opts:
if option[0] == "-g":
gtotal = 1
elif option[0] == "-m":
show_memory = 1
elif option[0] == "-o":
outfile = option[1]
elif option[0] == "-t":
tit = option[1]
filenames = pargs
bars = []
n = 0
for filename in filenames:
values = get_values(filename)
print("Values-->", values)
bars.append(plot_bar(values, n))
n += 1
show_plot(bars, filenames, tit)
|