-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bs-read.py
executable file
·49 lines (39 loc) · 1.03 KB
/
bs-read.py
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
#! /usr/bin/python3
import os
import sys
import threading
import time
dev = sys.argv[1]
bs_min = int(sys.argv[2])
bs_steps = int(sys.argv[3])
duration = float(sys.argv[4])
linear = sys.argv[5] == 'linear'
offset = 0
def do_(dev, bs, duration):
global offset
fd = os.open(dev, os.O_RDONLY)
dev_size = os.lseek(fd, 0, os.SEEK_END)
os.posix_fadvise(fd, 0, dev_size, os.POSIX_FADV_DONTNEED)
end = time.time() + duration
n = 0
while time.time() < end:
if offset + bs > dev_size:
offset = 0
os.lseek(fd, offset, os.SEEK_SET)
os.posix_fadvise(fd, offset, bs, os.POSIX_FADV_DONTNEED)
os.read(fd, bs)
offset += bs
n += 1
os.close(fd)
return n
fhb = open('plot-bw-iop.dat', 'w')
for bs_it in range(bs_steps):
if linear:
bs = bs_min * (bs_it + 1)
else:
bs = bs_min << bs_it
iop = do_(dev, bs, duration)
out = f'{bs} {iop} {iop * bs} {iop / duration} {iop * bs / duration}'
print(out)
fhb.write(out + '\n')
fhb.close()