|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Aggregate results from /mnt/cfs/results directory. |
| 4 | +Each log file contains one line with format: |
| 5 | +<trace> <algorithm> cache size <size>, <num_req> req, miss ratio <miss_ratio>, throughput <throughput> MQPS |
| 6 | +""" |
| 7 | + |
| 8 | +import os |
| 9 | +import re |
| 10 | +import csv |
| 11 | +from pathlib import Path |
| 12 | +from collections import defaultdict |
| 13 | +import argparse |
| 14 | + |
| 15 | + |
| 16 | +def parse_log_file(filepath): |
| 17 | + """Parse a single log file and extract information.""" |
| 18 | + try: |
| 19 | + with open(filepath, 'r') as f: |
| 20 | + line = f.read().strip() |
| 21 | + |
| 22 | + if not line: |
| 23 | + return None |
| 24 | + |
| 25 | + # Parse the log line |
| 26 | + # Example: /mnt/cfs/oracleReuse/systor/2016_LUN0.oracleGeneral.zst S4FIFO-0.0500-1 cache size 64548, 552023811 req, miss ratio 0.7538, throughput 1.55 MQPS |
| 27 | + |
| 28 | + # Extract trace path |
| 29 | + parts = line.split() |
| 30 | + if len(parts) < 10: |
| 31 | + return None |
| 32 | + |
| 33 | + trace = parts[0] |
| 34 | + algorithm = parts[1] |
| 35 | + |
| 36 | + # Extract cache size |
| 37 | + cache_size_match = re.search(r'cache size\s+(\d+)', line) |
| 38 | + cache_size = int(cache_size_match.group(1)) if cache_size_match else None |
| 39 | + |
| 40 | + # Extract number of requests |
| 41 | + req_match = re.search(r'(\d+)\s+req', line) |
| 42 | + num_req = int(req_match.group(1)) if req_match else None |
| 43 | + |
| 44 | + # Extract miss ratio |
| 45 | + miss_ratio_match = re.search(r'miss ratio\s+([\d.]+)', line) |
| 46 | + miss_ratio = float(miss_ratio_match.group(1)) if miss_ratio_match else None |
| 47 | + |
| 48 | + # Extract throughput |
| 49 | + throughput_match = re.search(r'throughput\s+([\d.]+)\s+MQPS', line) |
| 50 | + throughput = float(throughput_match.group(1)) if throughput_match else None |
| 51 | + |
| 52 | + # Parse filename to extract parameters |
| 53 | + filename = os.path.basename(filepath) |
| 54 | + # Example: s4fifo_2016_LUN0.oracleGeneral.zst_c0.001_s0.05_g0.9_m1_t0_k0.0.log |
| 55 | + param_match = re.search(r'_c([\d.]+)_s([\d.]+)_g([\d.]+)_m(\d+)_t(\d+)_k([\d.]+)\.log$', filename) |
| 56 | + |
| 57 | + if param_match: |
| 58 | + c_param = float(param_match.group(1)) |
| 59 | + s_param = float(param_match.group(2)) |
| 60 | + g_param = float(param_match.group(3)) |
| 61 | + m_param = int(param_match.group(4)) |
| 62 | + t_param = int(param_match.group(5)) |
| 63 | + k_param = float(param_match.group(6)) |
| 64 | + else: |
| 65 | + c_param = s_param = g_param = m_param = t_param = k_param = None |
| 66 | + |
| 67 | + return { |
| 68 | + 'filename': filename, |
| 69 | + 'trace': trace, |
| 70 | + 'algorithm': algorithm, |
| 71 | + 'cache_size': cache_size, |
| 72 | + 'num_req': num_req, |
| 73 | + 'miss_ratio': miss_ratio, |
| 74 | + 'throughput': throughput, |
| 75 | + 'c_param': c_param, |
| 76 | + 's_param': s_param, |
| 77 | + 'g_param': g_param, |
| 78 | + 'm_param': m_param, |
| 79 | + 't_param': t_param, |
| 80 | + 'k_param': k_param, |
| 81 | + } |
| 82 | + |
| 83 | + except Exception as e: |
| 84 | + print(f"Error parsing {filepath}: {e}") |
| 85 | + return None |
| 86 | + |
| 87 | + |
| 88 | +def aggregate_results(results_dir, output_file): |
| 89 | + """Aggregate all results from the directory.""" |
| 90 | + results = [] |
| 91 | + |
| 92 | + results_path = Path(results_dir) |
| 93 | + log_files = list(results_path.glob('*.log')) |
| 94 | + |
| 95 | + print(f"Found {len(log_files)} log files") |
| 96 | + |
| 97 | + total = len(log_files) |
| 98 | + processed = 0 |
| 99 | + |
| 100 | + for log_file in log_files: |
| 101 | + data = parse_log_file(log_file) |
| 102 | + if data: |
| 103 | + results.append(data) |
| 104 | + |
| 105 | + processed += 1 |
| 106 | + if processed % 10000 == 0: |
| 107 | + print(f"Processed {processed}/{total} files ({100*processed/total:.1f}%)") |
| 108 | + |
| 109 | + print(f"Successfully parsed {len(results)} files") |
| 110 | + |
| 111 | + # Write to CSV |
| 112 | + if results: |
| 113 | + fieldnames = [ |
| 114 | + 'filename', 'trace', 'algorithm', 'cache_size', 'num_req', |
| 115 | + 'miss_ratio', 'throughput', 'c_param', 's_param', 'g_param', |
| 116 | + 'm_param', 't_param', 'k_param' |
| 117 | + ] |
| 118 | + |
| 119 | + with open(output_file, 'w', newline='') as f: |
| 120 | + writer = csv.DictWriter(f, fieldnames=fieldnames) |
| 121 | + writer.writeheader() |
| 122 | + writer.writerows(results) |
| 123 | + |
| 124 | + print(f"Results written to {output_file}") |
| 125 | + |
| 126 | + # Print summary statistics |
| 127 | + print("\n=== Summary Statistics ===") |
| 128 | + print(f"Total results: {len(results)}") |
| 129 | + |
| 130 | + traces = set(r['trace'] for r in results) |
| 131 | + print(f"Unique traces: {len(traces)}") |
| 132 | + |
| 133 | + algorithms = set(r['algorithm'] for r in results) |
| 134 | + print(f"Unique algorithms: {len(algorithms)}") |
| 135 | + |
| 136 | + if results[0]['miss_ratio'] is not None: |
| 137 | + miss_ratios = [r['miss_ratio'] for r in results if r['miss_ratio'] is not None] |
| 138 | + if miss_ratios: |
| 139 | + print(f"Miss ratio range: {min(miss_ratios):.4f} - {max(miss_ratios):.4f}") |
| 140 | + print(f"Average miss ratio: {sum(miss_ratios)/len(miss_ratios):.4f}") |
| 141 | + |
| 142 | + |
| 143 | +def main(): |
| 144 | + parser = argparse.ArgumentParser(description='Aggregate S4FIFO experiment results') |
| 145 | + parser.add_argument('--results-dir', default='/mnt/cfs/results', |
| 146 | + help='Directory containing result log files') |
| 147 | + parser.add_argument('--output', default='aggregated_results.csv', |
| 148 | + help='Output CSV file') |
| 149 | + |
| 150 | + args = parser.parse_args() |
| 151 | + |
| 152 | + aggregate_results(args.results_dir, args.output) |
| 153 | + |
| 154 | + |
| 155 | +if __name__ == '__main__': |
| 156 | + main() |
0 commit comments