Switch to Matplotlib from Gnuplot
This commit is contained in:
parent
c3edfae2b1
commit
997d039569
2 changed files with 22 additions and 31 deletions
|
|
@ -4,23 +4,22 @@
|
|||
import base64
|
||||
import json
|
||||
import logging
|
||||
import math
|
||||
import pathlib
|
||||
import time
|
||||
|
||||
from matplotlib import pyplot
|
||||
import requests
|
||||
import Gnuplot
|
||||
|
||||
from wk.cfg.net import BENCHMARK_SERVER, IMGUR_CLIENT_ID
|
||||
from wk.ui import ansi
|
||||
|
||||
|
||||
# Hack to hide X11 error when running in CLI mode
|
||||
Gnuplot.gp.GnuplotOpts.default_term = 'xterm'
|
||||
|
||||
|
||||
# STATIC VARIABLES
|
||||
LOG = logging.getLogger(__name__)
|
||||
GRAPH_FIGURE_SIZE = (
|
||||
9.167, # 660px at 72dpi
|
||||
4.167, # 300px at 72dpi
|
||||
)
|
||||
GRAPH_HORIZONTAL = ('▁', '▂', '▃', '▄', '▅', '▆', '▇', '█')
|
||||
GRAPH_VERTICAL = (
|
||||
'▏', '▎', '▍', '▌',
|
||||
|
|
@ -57,32 +56,23 @@ def export_io_graph(disk, log_dir, read_rates):
|
|||
max_rate = max(read_rates) / (1024**2)
|
||||
max_rate = max(800, max_rate)
|
||||
out_path = pathlib.Path(f'{log_dir}/{disk.path.name}_iobenchmark.png')
|
||||
plot_data = out_path.with_suffix('.data')
|
||||
plot_data = ([], [])
|
||||
|
||||
# Adjust Y-axis range to either 1000 or roughly max rate + 200
|
||||
## Round up to the nearest 100 and then add 200
|
||||
y_range = (math.ceil(max_rate/100)*100) + 200
|
||||
# Prep data for graph
|
||||
for i, rate in enumerate(read_rates):
|
||||
plot_data[0].append((i+1) / len(read_rates) * 100) # Step
|
||||
plot_data[1].append(int(rate / (1024**2))) # Data
|
||||
|
||||
# Save plot data to file for Gnuplot
|
||||
with open(plot_data, 'w', encoding='utf-8') as _f:
|
||||
for i, rate in enumerate(read_rates):
|
||||
percent = (i+1) / len(read_rates) * 100
|
||||
rate = int(rate / (1024**2))
|
||||
_f.write(f'{percent:0.1f} {rate}\n')
|
||||
|
||||
# Run gnuplot commands
|
||||
_g = Gnuplot.Gnuplot()
|
||||
_g('reset')
|
||||
_g(f'set output "{out_path}"')
|
||||
_g('set terminal png large size 660,300 truecolor font "Noto Sans,11"')
|
||||
_g('set title "I/O Benchmark"')
|
||||
_g(f'set yrange [0:{y_range}]')
|
||||
_g('set style data lines')
|
||||
_g(f'plot "{plot_data}" title "{disk.description.replace("_", " ")}"')
|
||||
|
||||
# Cleanup
|
||||
_g.close()
|
||||
del _g
|
||||
# Build graph
|
||||
_, ax = pyplot.subplots(
|
||||
dpi=72,
|
||||
figsize=GRAPH_FIGURE_SIZE,
|
||||
layout='constrained',
|
||||
)
|
||||
ax.set_title('I/O Benchmark')
|
||||
ax.plot(*plot_data, label=disk.description.replace('_', ' '))
|
||||
ax.legend()
|
||||
pyplot.savefig(out_path)
|
||||
|
||||
return out_path
|
||||
|
||||
|
|
|
|||
|
|
@ -153,8 +153,9 @@ def export_and_upload_graphs(state, test_obj, rate_list):
|
|||
image_path = None
|
||||
try:
|
||||
image_path = graph.export_io_graph(test_obj.dev, state.log_dir, rate_list)
|
||||
except RuntimeError:
|
||||
except RuntimeError as err:
|
||||
# Failed to export PNG, skip uploads below
|
||||
LOG.error('Failed to export graph: %s', err)
|
||||
test_obj.report.append('Failed to export graph')
|
||||
return
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue