| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
""" |
| 4 |
This script parses logs/bench.log and create plots for each case with |
| 5 |
the timings function of time (date plot). It also creates a web page |
| 6 |
index.html for easy viewing of the generated plots. |
| 7 |
""" |
| 8 |
|
| 9 |
# Copyright (C) 2010 Johannes Ring |
| 10 |
# |
| 11 |
# This file is part of DOLFIN. |
| 12 |
# |
| 13 |
# DOLFIN is free software: you can redistribute it and/or modify |
| 14 |
# it under the terms of the GNU Lesser General Public License as published by |
| 15 |
# the Free Software Foundation, either version 3 of the License, or |
| 16 |
# (at your option) any later version. |
| 17 |
# |
| 18 |
# DOLFIN is distributed in the hope that it will be useful, |
| 19 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
# GNU Lesser General Public License for more details. |
| 22 |
# |
| 23 |
# You should have received a copy of the GNU Lesser General Public License |
| 24 |
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 25 |
# |
| 26 |
# First added: 2010-04-06 |
| 27 |
# Last changed: 2010-04-13 |
| 28 |
|
| 29 |
from __future__ import print_function |
| 30 |
import os |
| 31 |
import re |
| 32 |
import time |
| 33 |
import datetime |
| 34 |
import textwrap |
| 35 |
import numpy |
| 36 |
import matplotlib.pyplot as plt |
| 37 |
import matplotlib.dates as mdates |
| 38 |
|
| 39 |
# Change some of the default Matplotlib parameters |
| 40 |
plt.rcParams.update({'figure.figsize': [6, 4], |
| 41 |
'font.size' : 10, |
| 42 |
'axes.labelsize' : 10, |
| 43 |
'axes.grid': True, |
| 44 |
'text.fontsize' : 10, |
| 45 |
'legend.fontsize' : 8, |
| 46 |
'xtick.labelsize' : 8, |
| 47 |
'ytick.labelsize' : 8, |
| 48 |
}) |
| 49 |
|
| 50 |
# Write to web page index.html |
| 51 |
outfile = open("index.html", "w") |
| 52 |
outfile.write("<h1><big>DOLFIN Benchmarks</big></h1>\n") |
| 53 |
outfile.write("Last updated: %s.\n\n" % time.asctime()) |
| 54 |
|
| 55 |
# Open and read in logs/bench.log |
| 56 |
benchlog = "logs/bench.log" |
| 57 |
lines = open(benchlog, 'r').readlines() |
| 58 |
|
| 59 |
benchmarks = {} |
| •60 |
pattern = r"\((.*)\)\s+(.*)\s+(.*)\s+\"(.*)\"" |
| 61 |
|
| 62 |
# Extract data from logfile |
| 63 |
print("Parsing %s..." % benchlog) |
| 64 |
for line in lines: |
| 65 |
match = re.search(pattern, line) |
| 66 |
if match: |
| 67 |
year, month, day, hour, minute, second = \ |
| 68 |
[int(i) for i in match.group(1).split(',')] |
| 69 |
#date = datetime.datetime(year, month, day, hour, minute, second) |
| 70 |
date = datetime.date(year, month, day) |
| 71 |
name = match.group(2) |
| 72 |
elapsed_time = float(match.group(3)) |
| 73 |
description = match.group(4) |
| 74 |
|
| 75 |
if not name in benchmarks: |
| 76 |
benchmarks[name] = [[[date], [elapsed_time], description]] |
| 77 |
else: |
| 78 |
benchmarks[name][0][0].append(date) |
| 79 |
benchmarks[name][0][1].append(elapsed_time) |
| 80 |
benchmarks[name][0][2] = description # take later description |
| 81 |
|
| 82 |
# Open and read in logs/milestones.log |
| 83 |
milestones = [] |
| 84 |
milestoneslog = "logs/milestones.log" |
| 85 |
if os.path.isfile(milestoneslog): |
| 86 |
lines = open(milestoneslog, 'r').readlines() |
| 87 |
for line in lines: |
| 88 |
date = datetime.datetime.strptime(line.split()[0], "%Y-%m-%d") |
| 89 |
progname = ' '.join(line.split()[1:]) |
| 90 |
milestones.append([date, progname]) |
| 91 |
|
| 92 |
# Get Matplotlib line markers for use later |
| 93 |
markers = [] |
| 94 |
for m in plt.Line2D.markers: |
| 95 |
try: |
| 96 |
if len(m) == 1 and m != ' ': |
| 97 |
markers.append(m) |
| 98 |
except TypeError: |
| 99 |
pass |
| 100 |
|
| 101 |
year = datetime.timedelta(days=365) |
| 102 |
month = datetime.timedelta(days=30) |
| 103 |
week = datetime.timedelta(days=7) |
| 104 |
today = datetime.date.today() |
| 105 |
lasts = ['week', 'month', 'year', 'five years'] |
| 106 |
locators = [mdates.DayLocator(), mdates.DayLocator(interval=2), |
| 107 |
mdates.MonthLocator(), mdates.YearLocator()] |
| 108 |
date_fmts = ['%Y-%m-%d', '%d %b', '%b %Y', '%Y'] |
| 109 |
xmins = [today - week, today - month, today - year, today - 5*year] |
| 110 |
|
| 111 |
outfile.write("<h2>All benchmarks</h2><p>\n") |
| 112 |
outfile.write("<center>\n") |
| 113 |
outfile.write("<table border=\"0\">\n") |
| 114 |
|
| 115 |
def get_maxtime(dates, min_date, max_date, run_timings): |
| 116 |
"""Return the maximum time between min_date and max_date""" |
| 117 |
max_time = 0 |
| 118 |
for i, date in enumerate(dates): |
| 119 |
if date < min_date: |
| 120 |
continue |
| 121 |
elif date > max_date: |
| 122 |
break |
| 123 |
else: |
| 124 |
if max_time < run_timings[i]: |
| 125 |
max_time = run_timings[i] |
| 126 |
return max_time |
| 127 |
|
| 128 |
# Create normalized plots with all benchmarks in same plot for |
| 129 |
# last week, last month, last year, and last five years |
| 130 |
linetypes = {} |
| 131 |
print("Generating plots for all benchmarks...") |
| 132 |
for last, locator, date_fmt, xmin in zip(lasts, locators, date_fmts, xmins): |
| 133 |
fig = plt.figure() |
| 134 |
ax = fig.gca() |
| 135 |
num = 0 |
| 136 |
ymax = 0 |
| 137 |
for benchmark, values in benchmarks.items(): |
| 138 |
num += 1 |
| 139 |
dates = values[0][0] |
| 140 |
run_timings = values[0][1]/numpy.linalg.norm(values[0][1]) |
| 141 |
p = ax.plot(dates, run_timings, |
| 142 |
marker=markers[num % len(markers)], markersize=3, |
| 143 |
label=benchmark) |
| 144 |
ax.hold(True) |
| 145 |
linetypes[benchmark] = p[0] |
| 146 |
maxtime = get_maxtime(dates, xmin, today, run_timings) |
| 147 |
if maxtime > ymax: |
| 148 |
ymax = maxtime |
| 149 |
ax.xaxis.set_major_locator(locator) |
| 150 |
ax.xaxis.set_major_formatter(mdates.DateFormatter(date_fmt)) |
| 151 |
ax.set_xlim(xmin, today) |
| 152 |
ax.set_ylim(0, ymax) |
| 153 |
|
| 154 |
# Add milestones to plot |
| 155 |
for milestone in milestones: |
| 156 |
milestone_num = mdates.date2num(milestone[0]) |
| 157 |
ax.annotate(milestone[1], xy=(milestone_num, 0.1E-10), |
| 158 |
xycoords='data', xytext=(0, 30), |
| 159 |
textcoords='offset points', |
| 160 |
horizontalalignment='center', |
| 161 |
verticalalignment='bottom', |
| 162 |
style='italic', fontsize=6, |
| 163 |
alpha=0.7, rotation='vertical', |
| 164 |
arrowprops=dict(arrowstyle="->", alpha=0.3) |
| 165 |
) |
| 166 |
|
| 167 |
#lgd = plt.legend(loc='best') |
| 168 |
fig.autofmt_xdate() |
| 169 |
plt.title("All benchmarks (last %s)" % last) |
| 170 |
filename = "all_last_%s.png" % last.replace(' ', '_') |
| 171 |
plt.savefig(filename, facecolor='#eeeeee') |
| 172 |
|
| 173 |
# Add plots to web page |
| 174 |
if last in ['week', 'year']: |
| 175 |
outfile.write(" <tr><td><img src=\"%s\" /></td>\n" % filename) |
| 176 |
else: |
| 177 |
outfile.write(" <td><img src=\"%s\" /></td></tr>\n" % filename) |
| 178 |
|
| 179 |
# Separate legend |
| 180 |
linetypes = sorted(linetypes.items()) |
| 181 |
handles = [p for (t, p) in linetypes] |
| 182 |
labels = [t for (t, p) in linetypes] |
| 183 |
plt.figure(figsize=(12, 4)) # twice wide the default |
| 184 |
plt.figlegend(handles, labels, 'center', ncol=3) |
| 185 |
plt.savefig('all_legend.png') |
| 186 |
outfile.write(" <tr><td colspan=\"2\"><img src=\"%s\" /></td></tr>\n" % 'all_legend.png') |
| 187 |
|
| 188 |
outfile.write("</table>\n") |
| 189 |
outfile.write("</center>\n") |
| 190 |
|
| 191 |
# Put together subtasks benchmarks which should be plotted together |
| 192 |
# (annotated by ((...)) in description) |
| 193 |
for benchmark, values in benchmarks.items(): |
| 194 |
postfix = values[0][2].split("((") |
| 195 |
if len(postfix) == 1: |
| 196 |
continue |
| 197 |
assert len(postfix) == 2 |
| 198 |
postfix = postfix[1].strip().replace("))", "") |
| 199 |
benchmarks.pop(benchmark) |
| 200 |
name = "-".join(benchmark.split("-")[:3]) + "-subtasks" |
| 201 |
if not name in benchmarks: |
| 202 |
benchmarks[name] = [] |
| 203 |
benchmarks[name].append((values[0][0], values[0][1], postfix)) |
| 204 |
|
| 205 |
# Now create separate plots for every benchmark |
| 206 |
for benchmark, values in sorted(benchmarks.items()): |
| 207 |
print("Generating plots for %s..." % benchmark) |
| 208 |
|
| 209 |
outfile.write("<h2>%s</h2><p>\n" % benchmark) |
| 210 |
outfile.write("<center>\n") |
| 211 |
outfile.write("<table border=\"0\">\n") |
| 212 |
|
| 213 |
# Create plots for last week, last month, last year, and last five years |
| 214 |
for last, locator, date_fmt, xmin in zip(lasts, locators, date_fmts, xmins): |
| 215 |
fig = plt.figure() |
| 216 |
ax = fig.gca() |
| 217 |
if any(s in benchmark for s in ["fem-speedup-cpp-"]): |
| 218 |
ax.set_ylabel("speedup") |
| 219 |
else: |
| 220 |
ax.set_ylabel("time (seconds)") |
| 221 |
maxtime = 0.0 |
| 222 |
for v in values: |
| 223 |
dates = v[0] |
| 224 |
run_timings = v[1] |
| 225 |
description = textwrap.fill(v[2], width=30) |
| 226 |
maxtime = max(maxtime, get_maxtime(dates, xmin, today, run_timings)) |
| 227 |
ax.set_ylim(0, maxtime + maxtime/2) |
| 228 |
ax.plot(dates, run_timings, marker='o', markersize=3, label=description) |
| 229 |
ax.legend(loc='best') |
| 230 |
ax.xaxis.set_major_locator(locator) |
| 231 |
ax.xaxis.set_major_formatter(mdates.DateFormatter(date_fmt)) |
| 232 |
ax.set_xlim(xmin, today) |
| 233 |
|
| 234 |
# Add milestones to plot |
| 235 |
for milestone in milestones: |
| 236 |
milestone_num = mdates.date2num(milestone[0]) |
| 237 |
ax.annotate(milestone[1], xy=(milestone_num, 0.1E-10), |
| 238 |
xycoords='data', xytext=(0, 30), |
| 239 |
textcoords='offset points', |
| 240 |
horizontalalignment='center', |
| 241 |
verticalalignment='bottom', |
| 242 |
style='italic', fontsize=6, |
| 243 |
alpha=0.7, rotation='vertical', |
| 244 |
arrowprops=dict(arrowstyle="->", alpha=0.3) |
| 245 |
) |
| 246 |
|
| 247 |
fig.autofmt_xdate() |
| 248 |
plt.title("%s (last %s)" % (benchmark, last)) |
| 249 |
filename = "%s_last_%s.png" % (benchmark, last.replace(' ', '_')) |
| 250 |
plt.savefig(filename, facecolor='#eeeeee') |
| 251 |
|
| 252 |
# Add plots to web page |
| 253 |
if last in ['week', 'year']: |
| 254 |
outfile.write(" <tr><td><img src=\"%s\" /></td>\n" % filename) |
| 255 |
else: |
| 256 |
outfile.write(" <td><img src=\"%s\" /></td></tr>\n" % filename) |
| 257 |
|
| 258 |
outfile.write("</table>\n") |
| 259 |
outfile.write("</center>\n") |