|
| 1 | +import os |
| 2 | +import re |
| 3 | +import sys |
| 4 | + |
| 5 | +def parse_perf_file(filepath): |
| 6 | + instrs_total = 0 |
| 7 | + cycles_total = 0 |
| 8 | + with open(filepath, 'r') as f: |
| 9 | + for line in f: |
| 10 | + match = re.search(r'instrs=(\d+), cycles=(\d+)', line) |
| 11 | + if match: |
| 12 | + instrs_total += int(match.group(1)) |
| 13 | + cycles_total += int(match.group(2)) |
| 14 | + return instrs_total, cycles_total |
| 15 | + |
| 16 | +def extract_O_value(filename): |
| 17 | + match = re.search(r'_O(\d+)\.txt', filename) |
| 18 | + return int(match.group(1)) if match else None |
| 19 | + |
| 20 | +def run_perf_summary_on_folder(folder_path): |
| 21 | + str_option = "" |
| 22 | + str_data = "" |
| 23 | + for filename in sorted(os.listdir(folder_path)): |
| 24 | + if filename.endswith('.txt') and '_O' in filename: |
| 25 | + O_value = extract_O_value(filename) |
| 26 | + if O_value is not None: |
| 27 | + filepath = os.path.join(folder_path, filename) |
| 28 | + instrs_total, cycles_total = parse_perf_file(filepath) |
| 29 | + #print(f"{O_value} {instrs_total} {cycles_total}") |
| 30 | + str_option = str_option + str(O_value) + " " |
| 31 | + str_data = str_data + str(instrs_total) + " " + str(cycles_total) + " " |
| 32 | + print(str_option) |
| 33 | + print(str_data) |
| 34 | + |
| 35 | + |
| 36 | +if __name__ == "__main__": |
| 37 | + if len(sys.argv) < 2: |
| 38 | + print("Usage: python script.py <folder_path>") |
| 39 | + sys.exit(1) |
| 40 | + folder_path = sys.argv[1] |
| 41 | + run_perf_summary_on_folder(folder_path) |
0 commit comments