Skip to content

Commit b12520f

Browse files
authored
Merge pull request verilog-to-routing#1851 from ganeshgore/log_memory_ci
[CI] Logs Memory during CI Run
2 parents a86083f + 173b223 commit b12520f

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

vtr_flow/scripts/run_vtr_flow.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,26 @@ def vtr_command_argparser(prog=None):
411411
return parser
412412

413413

414+
def format_human_readable_memory(num_kbytes):
415+
"""format the number of bytes given as a human readable value"""
416+
if num_kbytes < 1024:
417+
value = "%.2f KiB" % (num_kbytes)
418+
elif num_kbytes < (1024 ** 2):
419+
value = "%.2f MiB" % (num_kbytes / (1024 ** 1))
420+
else:
421+
value = "%.2f GiB" % (num_kbytes / (1024 ** 2))
422+
return value
423+
424+
425+
def get_memory_usage(logfile):
426+
"""Extrats the memory usage from the *.out log files"""
427+
with open(logfile, "r") as fpmem:
428+
for line in fpmem.readlines():
429+
if "Maximum resident set size" in line:
430+
return format_human_readable_memory(int(line.split()[-1]))
431+
return "--"
432+
433+
414434
# pylint: enable=too-many-statements
415435

416436

@@ -488,9 +508,12 @@ def vtr_command_main(arg_list, prog=None):
488508

489509
finally:
490510
seconds = datetime.now() - start
511+
491512
print(
492-
"{status} (took {time})".format(
493-
status=error_status, time=vtr.format_elapsed_time(seconds)
513+
"{status} (took {time}, vpr run consumed {max_mem} memory)".format(
514+
status=error_status,
515+
time=vtr.format_elapsed_time(seconds),
516+
max_mem=get_memory_usage(temp_dir / "vpr.out"),
494517
)
495518
)
496519
temp_dir.mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)