@@ -435,13 +435,49 @@ def format_human_readable_memory(num_kbytes):
435
435
return value
436
436
437
437
438
+ def get_max_memory_usage (temp_dir ):
439
+ """
440
+ Extracts the maximum memory usage of the VTR flow from generated .out files
441
+ """
442
+ cnt = 0
443
+ output_files = {
444
+ "yosys" : Path (temp_dir / "yosys.out" ),
445
+ "odin" : Path (temp_dir / "odin.out" ),
446
+ "abc" : Path (temp_dir / "abc{}.out" .format (cnt )),
447
+ "vpr" : Path (temp_dir / "vpr.out" ),
448
+ }
449
+ memory_usages = {"yosys" : - 1 , "odin" : - 1 , "abc" : - 1 , "vpr" : - 1 }
450
+
451
+ if output_files ["yosys" ].is_file ():
452
+ memory_usages ["yosys" ] = get_memory_usage (output_files ["yosys" ])
453
+
454
+ if output_files ["odin" ].is_file ():
455
+ memory_usages ["odin" ] = get_memory_usage (output_files ["odin" ])
456
+
457
+ while output_files ["abc" ].is_file ():
458
+ new_abc_mem_usage = get_memory_usage (output_files ["abc" ])
459
+ if new_abc_mem_usage > memory_usages ["abc" ]:
460
+ memory_usages ["abc" ] = new_abc_mem_usage
461
+
462
+ cnt += 1
463
+ output_files ["abc" ] = Path (temp_dir / "abc{}.out" .format (cnt ))
464
+
465
+ if output_files ["vpr" ].is_file ():
466
+ memory_usages ["vpr" ] = get_memory_usage (output_files ["vpr" ])
467
+
468
+ max_mem_key = max (memory_usages , key = memory_usages .get )
469
+ if memory_usages [max_mem_key ] != - 1 :
470
+ return format_human_readable_memory (memory_usages [max_mem_key ]), max_mem_key
471
+ return "-" , "-"
472
+
473
+
438
474
def get_memory_usage (logfile ):
439
- """Extrats the memory usage from the *.out log files"""
475
+ """Extracts the memory usage from the *.out log files"""
440
476
with open (logfile , "r" ) as fpmem :
441
477
for line in fpmem .readlines ():
442
478
if "Maximum resident set size" in line :
443
- return format_human_readable_memory ( int (line .split ()[- 1 ]) )
444
- return "--"
479
+ return int (line .split ()[- 1 ])
480
+ return - 1
445
481
446
482
447
483
# pylint: enable=too-many-statements
@@ -525,10 +561,11 @@ def vtr_command_main(arg_list, prog=None):
525
561
seconds = datetime .now () - start
526
562
527
563
print (
528
- "{status} (took {time}, vpr run consumed {max_mem} memory)" .format (
564
+ "{status} (took {time}, "
565
+ "overall memory peak {stage[0]} consumed by {stage[1]} run)" .format (
529
566
status = error_status ,
530
567
time = vtr .format_elapsed_time (seconds ),
531
- max_mem = get_memory_usage (temp_dir / "vpr.out" ),
568
+ stage = get_max_memory_usage (temp_dir ),
532
569
)
533
570
)
534
571
temp_dir .mkdir (parents = True , exist_ok = True )
0 commit comments