MCPcopy Create free account
hub / github.com/arvidn/libtorrent / plot_output

Function plot_output

tools/vmstat.py:331–385  ·  view source on GitHub ↗
(filename: str, keys: list[str])

Source from the content-addressed store, hash-verified

329
330
331def 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
339set format y '%.0f'
340set xlabel "time (s)"
341set xrange [0:*]
342set yrange [0:*]
343set y2range [0:*]
344set grid
345""")
346
347 for plot in plots:
348 f.write(f"""set output "{in_file}-{plot.name}.png"
349set title "{plot.title}"
350set ylabel "{plot.ylabel} (MB)"
351set 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)

Callers 2

run_testFunction · 0.90
run_testFunction · 0.90

Calls 2

openFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected