(runs, alpha, outfile, exclude=None, latency="p99", metric="both",
tps_scale="linear", latency_scale="log")
| 38 | |
| 39 | |
| 40 | def plot(runs, alpha, outfile, exclude=None, latency="p99", metric="both", |
| 41 | tps_scale="linear", latency_scale="log"): |
| 42 | matched = [r for r in runs if r["alpha"] == alpha and r["ts"]] |
| 43 | if exclude: |
| 44 | matched = [r for r in matched if r["connector"] not in exclude] |
| 45 | |
| 46 | if not matched: |
| 47 | print(f"no runs with timeSeries data found at alpha={alpha}", file=sys.stderr) |
| 48 | sys.exit(1) |
| 49 | |
| 50 | latency_key = f"{latency}_ms" |
| 51 | |
| 52 | if metric == "both": |
| 53 | fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(11, 8), sharex=True) |
| 54 | axes = [(ax1, "tps", "TPS"), (ax2, latency_key, f"{latency} latency (ms)")] |
| 55 | elif metric == "tps": |
| 56 | fig, ax1 = plt.subplots(1, 1, figsize=(11, 5)) |
| 57 | axes = [(ax1, "tps", "TPS")] |
| 58 | elif metric == "latency": |
| 59 | fig, ax1 = plt.subplots(1, 1, figsize=(11, 5)) |
| 60 | axes = [(ax1, latency_key, f"{latency} latency (ms)")] |
| 61 | else: |
| 62 | raise ValueError(f"unknown metric: {metric}") |
| 63 | |
| 64 | # one line per run; group by connector for legend de-dup |
| 65 | seen_connectors = {} |
| 66 | for r in matched: |
| 67 | ts = r["ts"] |
| 68 | x = [p["tSec"] for p in ts] |
| 69 | |
| 70 | label = r["connector"] |
| 71 | if label in seen_connectors: |
| 72 | label = None |
| 73 | else: |
| 74 | seen_connectors[r["connector"]] = True |
| 75 | |
| 76 | for ax, key, _ in axes: |
| 77 | ax.plot(x, [p[key] for p in ts], label=label, linewidth=2, alpha=0.85) |
| 78 | |
| 79 | contention = "uncontended" if alpha == 0 else f"alpha={alpha}" |
| 80 | title = f"alpha={alpha} ({contention})" |
| 81 | if exclude: |
| 82 | title += f" (excluded: {','.join(exclude)})" |
| 83 | |
| 84 | for i, (ax, key, ylabel) in enumerate(axes): |
| 85 | ax.set_ylabel(ylabel) |
| 86 | ax.legend(loc="upper right" if key == "tps" else "upper left") |
| 87 | ax.grid(True, alpha=0.3, which="both") |
| 88 | |
| 89 | scale = tps_scale if key == "tps" else latency_scale |
| 90 | if scale == "log": |
| 91 | ax.set_yscale("log") |
| 92 | elif scale == "symlog": |
| 93 | ax.set_yscale("symlog", linthresh=1) |
| 94 | # "linear" leaves the matplotlib default |
| 95 | |
| 96 | if i == 0: |
| 97 | ax.set_title(title) |
no test coverage detected
searching dependent graphs…