|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import matplotlib |
| 3 | +from matplotlib.backends.backend_pdf import PdfPages |
| 4 | +import matplotlib.pyplot as plt |
| 5 | +import re |
| 6 | +import os |
| 7 | +import sys |
| 8 | + |
| 9 | +if len(sys.argv) > 1: |
| 10 | + matplotlib.use("Agg") |
| 11 | + |
| 12 | + |
| 13 | +def parse_log(log): |
| 14 | + # Define regex pattern to extract data |
| 15 | + pattern = re.compile( |
| 16 | + r"^\s*(\d+|final)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)" |
| 17 | + r"\s*\|\s*(\d+)\s*\|\s*([-.\d]+)\s*\|\s*([-.\d]+)\s*\|\s*(\d+)\s*\|" |
| 18 | + ) |
| 19 | + |
| 20 | + # Initialize lists to store extracted data |
| 21 | + iterations = [] |
| 22 | + wns = [] |
| 23 | + |
| 24 | + # Split log into lines and parse each line |
| 25 | + got_match = False |
| 26 | + for line in log.strip().split("\n"): |
| 27 | + match = pattern.match(line) |
| 28 | + if match: |
| 29 | + got_match = True |
| 30 | + iter_val = match.group(1) |
| 31 | + if iter_val == "final": |
| 32 | + iter_val = ( |
| 33 | + iterations[-1] + 1 |
| 34 | + ) # Increment last iteration value for 'final' |
| 35 | + else: |
| 36 | + iter_val = int(iter_val) |
| 37 | + iterations.append(iter_val) |
| 38 | + wns.append(float(match.group(7))) |
| 39 | + if got_match and line.startswith("-----------------"): |
| 40 | + break |
| 41 | + |
| 42 | + return iterations, wns |
| 43 | + |
| 44 | + |
| 45 | +def plot_data(data_series): |
| 46 | + ax1 = plt.gca() |
| 47 | + |
| 48 | + # Plot each data series |
| 49 | + for iterations, wns, label in data_series: |
| 50 | + ax1.plot(iterations, wns, label=label, marker="o") |
| 51 | + |
| 52 | + ax1.set_title("WNS against Iterations") |
| 53 | + ax1.set_xlabel("Iterations") |
| 54 | + ax1.set_ylabel("WNS (ns)", color="b") |
| 55 | + ax1.legend(loc="lower right") |
| 56 | + |
| 57 | + plt.tight_layout() |
| 58 | + return plt |
| 59 | + |
| 60 | + |
| 61 | +def run(): |
| 62 | + if len(sys.argv) == 1: |
| 63 | + # Example log data |
| 64 | + example_log = """ |
| 65 | + Iter | Removed | Resized | Inserted | Cloned | Pin | WNS | TNS | Viol | Worst |
| 66 | + | Buffers | Gates | Buffers | Gates | Swaps | | | Endpts | Endpt |
| 67 | + --------------------------------------------------------------------------------------------------- |
| 68 | + 0 | 0 | 0 | 0 | 0 | 0 | -2195.436 | -114289224.0 | 26254 | core/int_issue_unit/io_dis_uops_0_ready_REG$_DFF_P_/D |
| 69 | + 10 | 0 | 7 | 0 | 1 | 1 | -1346.351 | -80532448.0 | 26254 | core/int_issue_unit/io_dis_uops_0_ready_REG$_DFF_P_/D |
| 70 | + [WARNING RSZ-0075] makeBufferedNet failed for driver core/rob/_99958_/CON |
| 71 | + [WARNING RSZ-0075] makeBufferedNet failed for driver core/rob/_99958_/CON |
| 72 | + [WARNING RSZ-0075] makeBufferedNet failed for driver core/rob/_99958_/CON |
| 73 | + [WARNING RSZ-0075] makeBufferedNet failed for driver lsu/_716839_/SN |
| 74 | + 20 | 0 | 9 | 2 | 2 | 7 | -1300.067 | -77633032.0 | 26254 | core/int_issue_unit/io_dis_uops_0_ready_REG$_DFF_P_/D |
| 75 | + [WARNING RSZ-0075] makeBufferedNet failed for driver core/rob/_99958_/CON |
| 76 | + [WARNING RSZ-0075] makeBufferedNet failed for driver lsu/_716839_/SN |
| 77 | + 21 | 0 | 9 | 2 | 2 | 8 | -1297.841 | -77515352.0 | 26252 | core/int_issue_unit/io_dis_uops_0_ready_REG$_DFF_P_/D |
| 78 | + final | 0 | 9 | 2 | 2 | 8 | -1297.841 | -77515352.0 | 26252 | core/int_issue_unit/io_dis_uops_0_ready_REG$_DFF_P_/D |
| 79 | + --------------------------------------------------------------------------------------------------- |
| 80 | + """ |
| 81 | + data = [[*parse_log(example_log), "example_log"]] |
| 82 | + plot_data(data) |
| 83 | + plt.show() |
| 84 | + return |
| 85 | + |
| 86 | + data = [] |
| 87 | + for file_path in sys.argv[2:]: |
| 88 | + with open(file_path, "r") as file: |
| 89 | + log = file.read() |
| 90 | + iterations, wns = parse_log(log) |
| 91 | + if len(iterations) == 0: |
| 92 | + continue |
| 93 | + label = "/".join(file_path.split(os.sep)[-4:]) |
| 94 | + data.append((iterations, wns, label)) |
| 95 | + plot_data(data) |
| 96 | + with PdfPages(sys.argv[1]) as pdf: |
| 97 | + pdf.savefig() |
| 98 | + |
| 99 | + |
| 100 | +if __name__ == "__main__": |
| 101 | + run() |
0 commit comments