Skip to content

Commit 074b8f0

Browse files
benedikt-voelkelBenedikt Volkel
andauthored
Add memory over time (#378)
* Add memory over time * Correct labels and dimensions Co-authored-by: Benedikt Volkel <benedikt.volkel@cern.ch>
1 parent 8a6dc4e commit 074b8f0

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

MC/utils/o2dpg_sim_metrics.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ def match_category(proposed):
7575
return cat[0], proposed
7676

7777

78-
def extract_cpu_usage(pipeline_metrics):
78+
def extract_metric_over_time(pipeline_metrics, key):
7979
iterations = []
8080
for pm in pipeline_metrics:
8181
if len(iterations) < pm["iter"]:
8282
# NOTE that iterations start at 1 and NOT at 0
8383
iterations.extend([0] * (pm["iter"] - len(iterations)))
84-
iterations[pm["iter"] - 1] += pm["cpu"]
84+
iterations[pm["iter"] - 1] += pm[key]
8585
return iterations
8686

8787

@@ -111,7 +111,9 @@ def make_cat_map(pipeline_path):
111111

112112
cpu_limit = current_pipeline["meta"]["cpu_limit"]
113113
# scale by constraint number of CPUs
114-
current_pipeline["cpu_efficiencies"] = [e / cpu_limit for e in extract_cpu_usage(current_pipeline_metrics)]
114+
current_pipeline["cpu_efficiencies"] = [e / cpu_limit for e in extract_metric_over_time(current_pipeline_metrics, "cpu")]
115+
current_pipeline["pss_vs_time"] = extract_metric_over_time(current_pipeline_metrics, "pss")
116+
current_pipeline["uss_vs_time"] = extract_metric_over_time(current_pipeline_metrics, "uss")
115117

116118
metrics_map = {}
117119
for mm in current_pipeline_metrics:
@@ -424,9 +426,9 @@ def run(args):
424426
"""
425427
Top level run function
426428
"""
427-
if not args.metrics_summary and not args.influxdb_file and not args.cpu_eff:
429+
if not args.metrics_summary and not args.influxdb_file and not args.cpu_eff and not args.mem_usage:
428430
# if nothing is given explicitly, do everything
429-
args.metrics_summary, args.influxdb_file, args.cpu_eff = (True, True, True)
431+
args.metrics_summary, args.influxdb_file, args.cpu_eff, args.mem_usage = (True, True, True, True)
430432

431433
# organise paths
432434
full_path = abspath(args.path)
@@ -504,8 +506,18 @@ def run(args):
504506
ax.text(0, global_eff, f"Overall efficiency: {global_eff:.2f} %", fontsize=30)
505507
save_figure(figure, join(out_dir, f"cpu_efficiency_{pipeline_name}.png"))
506508

507-
return 0
509+
if args.mem_usage:
510+
for met, ylabel in zip(("pss_vs_time", "uss_vs_time"), ("PSS [MB]", "USS [MB]")):
511+
iterations = save_map[met]
512+
if iterations:
513+
pipeline_name = basename(full_path)
514+
figure, ax = make_plot(range(len(iterations)), iterations, "sampling iteration", ylabel, title=pipeline_name)
515+
average = sum(iterations) / len(iterations)
516+
ax.axhline(average, color="black")
517+
ax.text(0, average, f"Average: {average:.2f} MB", fontsize=30)
518+
save_figure(figure, join(out_dir, f"{met}_{pipeline_name}.png"))
508519

520+
return 0
509521

510522
def main():
511523

@@ -514,6 +526,7 @@ def main():
514526
parser.add_argument("--tags", help="key-value pairs, seperated by ;, example: alidist=1234567;o2=7654321;tag=someTag")
515527
parser.add_argument("--metrics-summary", dest="metrics_summary", action="store_true", help="create the metrics summary")
516528
parser.add_argument("--cpu-eff", dest="cpu_eff", action="store_true", help="run only cpu efficiency evaluation")
529+
parser.add_argument("--mem-usage", dest="mem_usage", action="store_true", help="run mem usage evaluation")
517530
parser.add_argument("--influxdb-file", dest="influxdb_file", action="store_true", help="prepare a file to be uploaded to InfluxDB")
518531
parser.add_argument("--influxdb-table-base", dest="influxdb_table_base", help="base name of InfluxDB table name", default="O2DPG_MC")
519532
parser.add_argument("--output", help="output_directory", default="metrics_summary")

0 commit comments

Comments
 (0)