| 329 | |
| 330 | |
| 331 | def plot_output(filename: str, keys: list[str]) -> None: |
| 332 | if "time" not in keys: |
| 333 | return |
| 334 | |
| 335 | output_dir, in_file = os.path.split(filename) |
| 336 | gnuplot_file = f"{output_dir}/plot_{in_file}.gnuplot" |
| 337 | with open(gnuplot_file, "w+") as f: |
| 338 | f.write("""set term png size 1200,700 |
| 339 | set format y '%.0f' |
| 340 | set xlabel "time (s)" |
| 341 | set xrange [0:*] |
| 342 | set yrange [0:*] |
| 343 | set y2range [0:*] |
| 344 | set grid |
| 345 | """) |
| 346 | |
| 347 | for plot in plots: |
| 348 | f.write(f"""set output "{in_file}-{plot.name}.png" |
| 349 | set title "{plot.title}" |
| 350 | set ylabel "{plot.ylabel} (MB)" |
| 351 | set y2label "{plot.y2label}" |
| 352 | {"set y2tics" if plot.y2label != "" else ""} |
| 353 | """) |
| 354 | |
| 355 | plot_string = "plot " |
| 356 | tidx = keys.index("time") + 1 |
| 357 | idx = 0 |
| 358 | for p in keys: |
| 359 | idx += 1 |
| 360 | if p == "time" or p == "": |
| 361 | continue |
| 362 | |
| 363 | if p not in plot.lines: |
| 364 | continue |
| 365 | |
| 366 | m = metrics[p] |
| 367 | |
| 368 | title = p.replace("_", "\\\\_") |
| 369 | if m.cumulative: |
| 370 | title += "/s" |
| 371 | |
| 372 | divider = 1 |
| 373 | if m.axis == "x1y1": |
| 374 | divider = 1024 * 1024 |
| 375 | |
| 376 | # escape underscores, since gnuplot interprets those as markup |
| 377 | plot_string += ( |
| 378 | f'"{in_file}" using {tidx}:(${idx}/{divider}) ' |
| 379 | + f'title "{title}" axis {m.axis} with steps, \\\n' |
| 380 | ) |
| 381 | if len(plot_string) > 5: |
| 382 | plot_string = plot_string[0:-4] + "\n\n" |
| 383 | f.write(plot_string) |
| 384 | |
| 385 | subprocess.check_output(["gnuplot", os.path.split(gnuplot_file)[1]], cwd=output_dir) |