-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathparsefio2.py
More file actions
84 lines (63 loc) · 3.02 KB
/
Copy pathparsefio2.py
File metadata and controls
84 lines (63 loc) · 3.02 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import json
import csv
import argparse
def parse_log_file_mode_based(file_path, mode='default'):
with open(file_path, 'r') as f:
lines = f.readlines()
if not lines[0].strip().startswith('{'):
lines = lines[1:]
json_str = ''.join(lines)
try:
log_data = json.loads(json_str)
except json.JSONDecodeError:
print(f"Skipping file due to JSON decode error: {file_path}")
return {}
extracted_data = {}
for job in log_data.get('jobs', []):
extracted_data['jobname'] = job.get('jobname', 'Unknown')
extracted_data['iodepth'] = job.get('job options', {}).get('iodepth', None)
extracted_data['bs'] = job.get('job options', {}).get('bs', None)
if mode == 'default':
for rw_mode in ['read', 'write']:
for key_metric in ['iops', 'bw']:
key = f"{rw_mode}_{key_metric}"
value = job.get(rw_mode, {}).get(key_metric, None)
# Convert read_bw and write_bw from KiB/s to MB/s
if key_metric == 'bw':
value = (value * 1024) / (1000 ** 2) if value else None
extracted_data[key] = value
if rw_mode == 'read':
clat_ns_percentiles = job.get(rw_mode, {}).get('clat_ns', {}).get('percentile', {})
for percentile in ["99.000000", "99.900000", "99.990000", "99.999000", "99.999900"]:
key = f"{rw_mode}_clat_ns_{percentile}"
value = clat_ns_percentiles.get(percentile, None)
# Convert latency from ns to ms
value = value / 1_000_000 if value else None
extracted_data[key] = value
return extracted_data
def write_to_csv(data_list, csv_file_path):
with open(csv_file_path, 'w', newline='') as csvfile:
fieldnames = list(data_list[0].keys())
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for data in data_list:
writer.writerow(data)
def main(input_dir):
log_files = [f for f in os.listdir(input_dir) if f.endswith('summary.log')]
# Sort files by modification time
log_files.sort(key=lambda x: os.path.getmtime(os.path.join(input_dir, x)))
all_extracted_data = []
for log_file in log_files:
log_file_path = os.path.join(input_dir, log_file)
extracted_data = parse_log_file_mode_based(log_file_path, mode='default')
if extracted_data:
all_extracted_data.append(extracted_data)
csv_file_path = os.path.join(input_dir, 'parsed_summary.csv')
write_to_csv(all_extracted_data, csv_file_path)
print(f"CSV file has been written to {csv_file_path}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Parse summary log files into a CSV.')
parser.add_argument('input_dir', type=str, help='Path to the directory containing the summary log files.')
args = parser.parse_args()
main(args.input_dir)