@@ -435,13 +435,47 @@ 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
+ return max_mem_key , format_human_readable_memory (memory_usages [max_mem_key ])
470
+
471
+
438
472
def get_memory_usage (logfile ):
439
- """Extrats the memory usage from the *.out log files"""
473
+ """Extracts the memory usage from the *.out log files"""
440
474
with open (logfile , "r" ) as fpmem :
441
475
for line in fpmem .readlines ():
442
476
if "Maximum resident set size" in line :
443
- return format_human_readable_memory ( int (line .split ()[- 1 ]) )
444
- return "--"
477
+ return int (line .split ()[- 1 ])
478
+ return None
445
479
446
480
447
481
# pylint: enable=too-many-statements
@@ -525,10 +559,10 @@ def vtr_command_main(arg_list, prog=None):
525
559
seconds = datetime .now () - start
526
560
527
561
print (
528
- "{status} (took {time}, vpr run consumed {max_mem } memory)" .format (
562
+ "{status} (took {time}, {stage[0]} run consumed {stage[1] } memory)" .format (
529
563
status = error_status ,
530
564
time = vtr .format_elapsed_time (seconds ),
531
- max_mem = get_memory_usage (temp_dir / "vpr.out" ),
565
+ stage = get_max_memory_usage (temp_dir ),
532
566
)
533
567
)
534
568
temp_dir .mkdir (parents = True , exist_ok = True )
0 commit comments