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 base64
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import math
|
|
||||||
import pathlib
|
import pathlib
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from matplotlib import pyplot
|
||||||
import requests
|
import requests
|
||||||
import Gnuplot
|
|
||||||
|
|
||||||
from wk.cfg.net import BENCHMARK_SERVER, IMGUR_CLIENT_ID
|
from wk.cfg.net import BENCHMARK_SERVER, IMGUR_CLIENT_ID
|
||||||
from wk.ui import ansi
|
from wk.ui import ansi
|
||||||
|
|
||||||
|
|
||||||
# Hack to hide X11 error when running in CLI mode
|
|
||||||
Gnuplot.gp.GnuplotOpts.default_term = 'xterm'
|
|
||||||
|
|
||||||
|
|
||||||
# STATIC VARIABLES
|
# STATIC VARIABLES
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
GRAPH_FIGURE_SIZE = (
|
||||||
|
9.167, # 660px at 72dpi
|
||||||
|
4.167, # 300px at 72dpi
|
||||||
|
)
|
||||||
GRAPH_HORIZONTAL = ('▁', '▂', '▃', '▄', '▅', '▆', '▇', '█')
|
GRAPH_HORIZONTAL = ('▁', '▂', '▃', '▄', '▅', '▆', '▇', '█')
|
||||||
GRAPH_VERTICAL = (
|
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(read_rates) / (1024**2)
|
||||||
max_rate = max(800, max_rate)
|
max_rate = max(800, max_rate)
|
||||||
out_path = pathlib.Path(f'{log_dir}/{disk.path.name}_iobenchmark.png')
|
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
|
# Prep data for graph
|
||||||
## Round up to the nearest 100 and then add 200
|
for i, rate in enumerate(read_rates):
|
||||||
y_range = (math.ceil(max_rate/100)*100) + 200
|
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
|
# Build graph
|
||||||
with open(plot_data, 'w', encoding='utf-8') as _f:
|
_, ax = pyplot.subplots(
|
||||||
for i, rate in enumerate(read_rates):
|
dpi=72,
|
||||||
percent = (i+1) / len(read_rates) * 100
|
figsize=GRAPH_FIGURE_SIZE,
|
||||||
rate = int(rate / (1024**2))
|
layout='constrained',
|
||||||
_f.write(f'{percent:0.1f} {rate}\n')
|
)
|
||||||
|
ax.set_title('I/O Benchmark')
|
||||||
# Run gnuplot commands
|
ax.plot(*plot_data, label=disk.description.replace('_', ' '))
|
||||||
_g = Gnuplot.Gnuplot()
|
ax.legend()
|
||||||
_g('reset')
|
pyplot.savefig(out_path)
|
||||||
_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
|
|
||||||
|
|
||||||
return out_path
|
return out_path
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -153,8 +153,9 @@ def export_and_upload_graphs(state, test_obj, rate_list):
|
||||||
image_path = None
|
image_path = None
|
||||||
try:
|
try:
|
||||||
image_path = graph.export_io_graph(test_obj.dev, state.log_dir, rate_list)
|
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
|
# Failed to export PNG, skip uploads below
|
||||||
|
LOG.error('Failed to export graph: %s', err)
|
||||||
test_obj.report.append('Failed to export graph')
|
test_obj.report.append('Failed to export graph')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue