-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperformance_analyzer.py
More file actions
39 lines (34 loc) · 1.64 KB
/
performance_analyzer.py
File metadata and controls
39 lines (34 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import subprocess
import time
import os
class PerformanceAnalyzer:
def __init__(self):
pass
def compile_ffmpeg(self, compiler_flags):
# Clean previous builds
subprocess.run(['make', 'distclean'], cwd='ffmpeg_source', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
configure_cmd = ['./configure', '--disable-doc', '--disable-debug', f'CFLAGS={" ".join(compiler_flags)}']
start_time = time.time()
try:
# Configure
subprocess.run(configure_cmd, check=True, cwd='ffmpeg_source', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
# Build
energy_before = self.get_energy_usage()
subprocess.run(['make', '-j4'], check=True, cwd='ffmpeg_source', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
energy_after = self.get_energy_usage()
end_time = time.time()
compile_time = end_time - start_time
energy_consumption = energy_after - energy_before
return compile_time, energy_consumption
except subprocess.CalledProcessError:
print("FFmpeg compilation failed")
return None, None
def get_energy_usage(self):
# Placeholder for energy measurement logic; integrate with Intel RAPL or other tools
energy_usage = 0
try:
with open("/sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj", "r") as f:
energy_usage = int(f.read().strip())
except FileNotFoundError:
print("Energy measurement not supported on this system.")
return energy_usage / 1e6 # Convert from microjoules to joules