-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculate_bandwidth.py
More file actions
94 lines (73 loc) · 2.55 KB
/
calculate_bandwidth.py
File metadata and controls
94 lines (73 loc) · 2.55 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
85
86
87
88
89
90
91
92
93
94
import argparse
import re
from pathlib import Path
import numpy as np
def pa():
p = argparse.ArgumentParser(description='Test')
p.add_argument('logdir', type=str, help='directory with logfiles')
return p.parse_args()
def parse_time(time_str):
"""
Parse a time string in the format 'XmYs' and convert it to seconds.
"""
match = re.match(r"(\d+)m(\d+)\.(\d+)s", time_str)
if match:
minutes = int(match.group(1))
seconds = int(match.group(2))
milliseconds = int(match.group(3)) / 1000
return minutes * 60 + seconds + milliseconds
return None
def read_timing_file(filename):
"""
Read a timing file and extract the real, user, and sys times in seconds.
"""
with open(filename, 'r') as file:
lines = file.readlines()
timing = {}
for line in lines:
if line.startswith('real'):
timing['real'] = parse_time(line.split()[1])
elif line.startswith('user'):
timing['user'] = parse_time(line.split()[1])
elif line.startswith('sys'):
timing['sys'] = parse_time(line.split()[1])
return timing
args = pa()
logdir = args.logdir
speeds = []
for file in Path(logdir).glob('*'):
timing = read_timing_file(file)
speeds.append(timing['real'])
#divide by 8 to get the speed in Gb/s
#speeds = [8*speed for speed in speeds]
rates = [8/speed for speed in speeds]
print("Avg rate:", sum(rates)/len(rates), "Gb/s")
print("Stdev rate:", np.std(rates), "Gb/s")
#print("Avg time:", sum(speeds)/len(speeds), "s")
#print("Stdev time:", np.std(speeds), "s")
# def extract_speeds(file_path):
# # Regular expression to match the bandwidth line
# speed_pattern = re.compile(r'(\d+(\.\d+)?) MB/s')
# with open(file_path, 'r') as file:
# lines = file.readlines()
# speeds = []
# for line in lines:
# match = speed_pattern.search(line)
# if match:
# speeds.append(float(match.group(1)))
# return speeds
# def convert_mb_s_to_gb_s(speed_mb_s):
# """ Convert speed from MB/s to Gb/s. """
# return speed_mb_s * 8 / 1000
# args = pa()
# logdir = args.logdir
# speeds = []
# for file in Path(logdir).glob('*'):
# speed = extract_speeds(file)
# #print(speeds)
# #take the min value
# speeds.append(min(speed))
# print("Avg speed:", sum(speeds)/len(speeds), "MB/s")
# print("Avg speed:", convert_mb_s_to_gb_s(sum(speeds)/len(speeds)), "Gb/s")
# print("Stdev speed:", np.std(speeds), "MB/s")
# print("Stdev speed:", convert_mb_s_to_gb_s(np.std(speeds)), "Gb/s")