import json from pathlib import Path import matplotlib.pyplot as plt import numpy as np def plottable(log: list[tuple[float, int]]): if log: return np.array(log).transpose() else: return np.array([[], []]) def plot(fn: str): plt.rcParams['figure.figsize'] = [16, 9] plt.style.use("dark_background") plt.subplots_adjust(left=0.05, right=0.99, top=0.95, bottom=0.05) plt.title(fn) plt.xlabel('time (s)') plt.ylabel('concurrency (1)') with open(fn) as file: jsonified = json.load(file) if (log := jsonified.get('DelayedResolver:sleep:concurrency')) is not None: plt.plot(*plottable(log)) if (log := jsonified.get('ActiveBinaryTree:add:concurrency')) is not None: plt.plot(*plottable(log)) if (log := jsonified.get('ActiveBinaryTree:contains:concurrency')) is not None: plt.plot(*plottable(log)) if (log := jsonified.get('Stack:list:concurrency')) is not None: plt.plot(*plottable(log)) if (log := jsonified.get('ActiveBinaryTree:add:entry')) is not None: plt.scatter(*plottable(log), c='tomato', zorder=100, s=.5) if (log := jsonified.get('ActiveBinaryTree:add:exit')) is not None: plt.scatter(*plottable(log), c='gold', zorder=99, s=.5) plt.show() if __name__ == '__main__': plot('trace/latest.json') for fp in list(Path('trace').glob('*.json')): if fp != Path('trace/latest.json'): plot(str(fp))