Skip to content

Commit 3557eca

Browse files
committed
[#72335] add plotting graph of power consumption over time
1 parent 872d5e3 commit 3557eca

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

tools/PeakPower/peak_power.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import re
1919
import subprocess
2020
import os
21-
import shutil
21+
import matplotlib.pyplot as plt
2222

2323

2424
def read_from_file(file_name: str):
@@ -31,7 +31,6 @@ def search_for_total_power(report_power: list[str]):
3131
match = re.match(r'Total\s+(([\w\.\-]+\s+)+)', line)
3232
if match:
3333
total_power = match.group(2).replace(' ', '')
34-
print(f'Total power: {total_power} Watts')
3534
return float(total_power)
3635

3736
return 0
@@ -53,10 +52,27 @@ def search_for_total_power(report_power: list[str]):
5352
files = os.listdir(args.input_dir)
5453
files = sorted(files)
5554

55+
power_results = []
56+
clock_cycles_indices = []
57+
58+
current_clock_cycle = 0
5659
for file in files:
57-
print(file)
60+
clock_cycles_indices.append(current_clock_cycle)
61+
print(f'Processing clock cycle no. {current_clock_cycle}')
62+
current_clock_cycle += 1
63+
5864
os.symlink(args.input_dir + "/" + file, input_trace_file)
5965
subprocess.run([open_sta_command, "-exit", open_sta_script], capture_output=True, text=True)
6066
report_contents = read_from_file(power_report_file)
6167
total_power = search_for_total_power(report_contents)
62-
os.remove(input_trace_file)
68+
power_results.append(total_power)
69+
os.remove(input_trace_file)
70+
71+
plt.plot(clock_cycles_indices, power_results, marker='o', linestyle='-', color='g')
72+
73+
plt.title("Power consumption over time")
74+
plt.xlabel("Clock cycles")
75+
plt.ylabel("Power consumption")
76+
plt.grid(True)
77+
78+
plt.show()

0 commit comments

Comments
 (0)