from pathlib import Path import re LOG_DIR = Path('measurements/memory/x86') CPU_FREQ_GHZ = 2.0 def parse_sysbench_log(file_path): """Parses a single sysbench log file to extract memory bandwidth in MiB/s.""" try: with open(file_path, 'r') as f: content = f.read() match = re.search(r'(\d+\.?\d*)\s+MiB/sec', content) if match: return float(match.group(1)) else: print(f"Warning: Could not find 'MiB/sec' in {file_path.name}") return None except Exception as e: print(f'Error reading {file_path}: {e}') return None def main(): if not LOG_DIR.exists(): print(f"Error: Directory '{LOG_DIR}' not found.") return bandwidths_mib_s = [] log_files = sorted(LOG_DIR.glob('*.log')) print(f'Found {len(log_files)} log files.') for file_path in log_files: val = parse_sysbench_log(file_path) if val is not None: bandwidths_mib_s.append(val) if not bandwidths_mib_s: print('No valid bandwidth data found.') return avg_mi_b_s = sum(bandwidths_mib_s) / len(bandwidths_mib_s) bytes_per_second = avg_mi_b_s * (1024**2) cycles_per_second = CPU_FREQ_GHZ * 1e9 bytes_per_cycle = bytes_per_second / cycles_per_second print('-' * 40) print(f'Files analyzed: {len(bandwidths_mib_s)}') print(f'Average Bandwidth: {avg_mi_b_s:.2f} MiB/sec') print(f'CPU Frequency: {CPU_FREQ_GHZ} GHz') print('-' * 40) print(f'Result: {bytes_per_cycle:.2f} bytes/cycle') print('-' * 40) if __name__ == '__main__': main()