better plot

This commit is contained in:
AF 2022-07-15 21:36:22 +03:00
parent 5420a475e6
commit 500f1df88c

15
plot.py
View File

@ -14,6 +14,16 @@ def plottable(log: list[tuple[float, int]]):
return np.array([[], []]) return np.array([[], []])
def format_params(params) -> str:
match params:
case dict():
return '{' + ' '.join(f'{key}={format_params(value)}' for key, value in params.items()) + '}'
case list():
return f'[{" ".join(format_params(value) for value in params)}]'
case _:
return json.dumps(params)
def plot(fn: str): def plot(fn: str):
plt.rcParams['figure.figsize'] = [16, 9] plt.rcParams['figure.figsize'] = [16, 9]
plt.style.use('dark_background') plt.style.use('dark_background')
@ -26,7 +36,7 @@ def plot(fn: str):
title = fn title = fn
if (params := jsonified.pop('params', None)) is not None: if (params := jsonified.pop('params', None)) is not None:
title += f' {":".join(map(str, params))}' title += f' {format_params(params)}'
plt.title(title) plt.title(title)
def logplot(plot_function, metric: str, **kwargs): def logplot(plot_function, metric: str, **kwargs):
@ -36,15 +46,18 @@ def plot(fn: str):
logplot(plt.plot, 'DelayedResolver:sleep:concurrency') logplot(plt.plot, 'DelayedResolver:sleep:concurrency')
logplot(plt.plot, 'ActiveBinaryTree:add:concurrency') logplot(plt.plot, 'ActiveBinaryTree:add:concurrency')
logplot(plt.plot, 'ActiveBinaryTree:contains:concurrency') logplot(plt.plot, 'ActiveBinaryTree:contains:concurrency')
logplot(plt.plot, 'FlowStandard:verify_subset:concurrency')
logplot(plt.plot, 'Stack:list:concurrency') logplot(plt.plot, 'Stack:list:concurrency')
logplot(plt.scatter, 'ActiveBinaryTree:add:entry', c='tomato', zorder=100, s=.5) logplot(plt.scatter, 'ActiveBinaryTree:add:entry', c='tomato', zorder=100, s=.5)
logplot(plt.scatter, 'ActiveBinaryTree:add:exit', c='gold', zorder=99, s=.5) logplot(plt.scatter, 'ActiveBinaryTree:add:exit', c='gold', zorder=99, s=.5)
plt.legend() plt.legend()
plt.show() plt.show()
plt.clf()
if __name__ == '__main__': if __name__ == '__main__':
Path('trace').mkdir(exist_ok=True)
if Path('trace/latest.json').exists(): if Path('trace/latest.json').exists():
plot('trace/latest.json') plot('trace/latest.json')
for fp in list(Path('trace').glob('*.json')): for fp in list(Path('trace').glob('*.json')):