|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | """ |
3 | | -plot_results.py |
| 3 | +draw.py |
4 | 4 |
|
5 | | -Reads 5 "results_summary_{N}.txt" files, each containing columns: |
| 5 | +We have 6 data files: |
| 6 | + results_summary_1.txt |
| 7 | + results_summary_2.txt |
| 8 | + results_summary_3.txt |
| 9 | + results_summary_4.txt |
| 10 | + results_summary_5.txt |
| 11 | + results_summary_6.txt |
| 12 | +
|
| 13 | +Each has 11 columns (skip the first row as a header): |
6 | 14 | 1) SMP |
7 | 15 | 2) real_boot_time |
8 | | - 3) times_call_semu_timer_clocksource |
| 16 | + 3) times_called |
9 | 17 | 4) ns_per_call |
10 | 18 | 5) predict_sec |
11 | 19 | 6) scale_factor |
12 | | - 7) percentage |
13 | | - 8) real_ns_per_call |
14 | | -
|
15 | | -We skip the header row in each file. For each column 2..8, we create |
16 | | -one figure, plotting SMP on the x-axis vs. that column's values |
17 | | -on the y-axis. We have 5 lines in each plot, one line per environment. |
18 | | -
|
19 | | -Additionally, we create one more figure for the difference: |
20 | | - (predict_sec [col 5]) - (real_boot_time [col 2]) |
21 | | -
|
22 | | -Environment CPU Descriptions: |
23 | | -1: 13th Gen Intel(R) Core(TM) i7-13700 |
24 | | -2: Intel(R) Xeon(R) CPU E5-2640 v4 @ 2.40GHz |
25 | | -3: Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz |
26 | | -4: arm (ThunderX2-99xx) |
27 | | -5: mag |
| 20 | + 7) test_total_clocksource_ns |
| 21 | + 8) real_total_clocksource_ns |
| 22 | + 9) percentage |
| 23 | + 10) real_ns_per_call |
| 24 | + 11) diff_ns_per_call |
| 25 | +
|
| 26 | +We want to plot columns 2..11 (10 columns) vs. column 1 (SMP). |
| 27 | +Then create 1 more difference plot for (predict_sec - real_boot_time). |
| 28 | +
|
| 29 | +Thus, we produce 11 plots total: |
| 30 | + - 10 from col=2..11 |
| 31 | + - 1 difference plot (predict_sec - real_boot_time). |
28 | 32 | """ |
29 | 33 |
|
30 | 34 | import matplotlib |
31 | | -# Force a non-interactive backend (no hover tooltips): |
32 | | -matplotlib.use("Agg") |
| 35 | +matplotlib.use("Agg") # for non-interactive environments |
33 | 36 |
|
34 | 37 | import numpy as np |
35 | 38 | import matplotlib.pyplot as plt |
36 | 39 |
|
37 | | -# Filenames expected |
38 | | -# results_summary_1.txt |
39 | | -# results_summary_2.txt |
40 | | -# results_summary_3.txt |
41 | | -# results_summary_4.txt |
42 | | -# results_summary_5.txt |
43 | | - |
44 | 40 | ENV_FILES = [ |
45 | 41 | "results_summary_1.txt", |
46 | 42 | "results_summary_2.txt", |
|
56 | 52 | "3: Env3", |
57 | 53 | "4: Env4", |
58 | 54 | "5: Env5", |
59 | | - "6: Env6" |
| 55 | + "6: Env6", |
60 | 56 | ] |
61 | 57 |
|
62 | | -# Map from column index to a label (column 1 is SMP) |
63 | | -# We want columns 2..8 |
| 58 | +# A dictionary for column labels (2..11): |
64 | 59 | COL_LABELS = { |
65 | | - 2: "real boot time (sec)", |
66 | | - 3: "times call 'semu_timer_clocksource'", |
67 | | - 4: "ns_per_call", |
68 | | - 5: "predict boot time (sec)", |
| 60 | + 2: "real_boot_time", |
| 61 | + 3: "times_called", |
| 62 | + 4: "predict_ns_per_call", |
| 63 | + 5: "predict_boot_time", |
69 | 64 | 6: "scale_factor", |
| 65 | + 7: "test_total_clocksource_ns", |
| 66 | + 8: "real_total_clocksource_ns", |
| 67 | + 9: "percentage", |
| 68 | + 10: "real_ns_per_call", |
| 69 | + 11: "diff_ns_per_call", |
70 | 70 | } |
71 | 71 |
|
72 | 72 | def main(): |
73 | | - # 1) Plot each data column from 2..8 |
74 | | - for col in range(2, 7): |
| 73 | + # 1) Create a figure for each column from 2..11 |
| 74 | + for col in range(2, 12): # 2..11 inclusive => 10 columns |
75 | 75 | label = COL_LABELS[col] |
76 | 76 |
|
77 | 77 | plt.figure(figsize=(8, 6)) |
78 | 78 | plt.title(f"{label} vs. SMP") |
79 | 79 | plt.xlabel("SMP") |
80 | 80 | plt.ylabel(label) |
81 | 81 |
|
| 82 | + # For each environment data |
82 | 83 | for i, fname in enumerate(ENV_FILES): |
83 | 84 | try: |
84 | | - # Load numeric data, skipping first row (header). |
| 85 | + # skiprows=1 => skip header line |
| 86 | + # Load all columns => we have 11 total |
85 | 87 | data = np.loadtxt(fname, skiprows=1) |
86 | 88 | except OSError: |
87 | | - print(f"Warning: could not open {fname}, skipping.") |
| 89 | + print(f"Warning: could not open {fname}. Skipping.") |
| 90 | + continue |
| 91 | + except ValueError as e: |
| 92 | + print(f"ValueError loading {fname}: {e}") |
88 | 93 | continue |
89 | 94 |
|
90 | | - if data.shape[1] < 6: |
91 | | - print(f"Warning: {fname} does not have at least 8 columns, skipping.") |
| 95 | + # We expect at least 11 columns |
| 96 | + if data.shape[1] < 11: |
| 97 | + print(f"Warning: {fname} does not have 11 columns. Found shape: {data.shape}") |
92 | 98 | continue |
93 | 99 |
|
94 | | - x = data[:, 0] # SMP is col 1 => index=0 |
95 | | - y = data[:, col - 1] # col -> zero-based |
| 100 | + x = data[:, 0] # SMP is col=1 => index=0 |
| 101 | + y = data[:, col - 1] # col => zero-based index |
96 | 102 |
|
97 | 103 | plt.plot(x, y, marker='o', label=ENV_NAMES[i]) |
98 | 104 |
|
99 | 105 | plt.legend(loc="best") |
100 | 106 | plt.grid(True) |
101 | | - |
102 | | - outname = f"{label}.png" |
103 | | - plt.savefig(outname, dpi=150) |
| 107 | + outfile = f"{label}.png" |
| 108 | + plt.savefig(outfile, dpi=150) |
104 | 109 | plt.close() |
105 | | - print(f"Created {outname}") |
106 | | - |
107 | | - print("All standard column plots generated!") |
108 | | - |
109 | | - # 2) Create an additional figure for (predict_sec - real_boot_time). |
110 | | - # predict_sec is column 5 => index 4 |
111 | | - # real_boot_time is column 2 => index 1 |
112 | | - label_diff = "boot time difference" # name of the new figure |
| 110 | + print(f"Created {outfile}") |
113 | 111 |
|
| 112 | + # 2) Create an additional difference plot for (predict_sec - real_boot_time). |
| 113 | + # predict_sec => col=5 => index=4 |
| 114 | + # real_boot_time => col=2 => index=1 |
| 115 | + label_diff = "diff_boot_time" |
114 | 116 | plt.figure(figsize=(8, 6)) |
115 | 117 | plt.title(f"{label_diff} vs. SMP") |
116 | 118 | plt.xlabel("SMP") |
117 | | - plt.ylabel("boot time difference (seconds)") |
| 119 | + plt.ylabel("predict_sec - real_boot_time") |
| 120 | + |
118 | 121 | for i, fname in enumerate(ENV_FILES): |
119 | 122 | try: |
120 | 123 | data = np.loadtxt(fname, skiprows=1) |
121 | 124 | except OSError: |
122 | | - print(f"Warning: could not open {fname}, skipping.") |
| 125 | + print(f"Warning: could not open {fname}. Skipping.") |
| 126 | + continue |
| 127 | + except ValueError as e: |
| 128 | + print(f"ValueError loading {fname}: {e}") |
123 | 129 | continue |
124 | 130 |
|
125 | | - if data.shape[1] < 6: |
126 | | - print(f"Warning: {fname} does not have at least 8 columns, skipping.") |
| 131 | + if data.shape[1] < 11: |
| 132 | + print(f"Warning: {fname} does not have 11 columns. Found shape: {data.shape}") |
127 | 133 | continue |
128 | 134 |
|
129 | | - x = data[:, 0] # SMP |
130 | | - predict_sec = data[:, 4] # col5 => index=4 |
131 | | - real_bt = data[:, 1] # col2 => index=1 |
132 | | - diff = predict_sec - real_bt # difference |
| 135 | + x = data[:, 0] |
| 136 | + predict_sec = data[:, 4] # col=5 => index=4 |
| 137 | + real_bt = data[:, 1] # col=2 => index=1 |
| 138 | + diff = predict_sec - real_bt |
133 | 139 |
|
134 | 140 | plt.plot(x, diff, marker='o', label=ENV_NAMES[i]) |
135 | 141 |
|
136 | 142 | plt.legend(loc="best") |
137 | 143 | plt.grid(True) |
138 | | - outdiff = f"{label_diff}.png" |
139 | | - plt.savefig(outdiff, dpi=150) |
| 144 | + outfile_diff = f"{label_diff}.png" |
| 145 | + plt.savefig(outfile_diff, dpi=150) |
140 | 146 | plt.close() |
141 | | - print(f"Created {outdiff}") |
| 147 | + print(f"Created {outfile_diff}") |
142 | 148 |
|
143 | | - print("Done! All plots generated including difference (predict - real_boot_time).") |
| 149 | + print("Done! Generated 10 standard plots (cols=2..11) + 1 difference plot (predict - real).") |
144 | 150 |
|
145 | 151 | if __name__ == "__main__": |
146 | 152 | main() |
0 commit comments