36 lines
1019 B
Python
36 lines
1019 B
Python
import os, time, statistics, math, sys
|
|
|
|
path = sys.argv[1] if len(sys.argv) > 1 else "/tmp/reval-fsync.bin"
|
|
count = int(sys.argv[2]) if len(sys.argv) > 2 else 200
|
|
size = int(sys.argv[3]) if len(sys.argv) > 3 else 4096
|
|
payload = b"x" * size
|
|
lat = []
|
|
|
|
fd = os.open(path, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0o600)
|
|
try:
|
|
for i in range(count):
|
|
t0 = time.perf_counter_ns()
|
|
os.write(fd, payload)
|
|
os.fsync(fd)
|
|
t1 = time.perf_counter_ns()
|
|
lat.append((t1 - t0) / 1_000_000)
|
|
finally:
|
|
os.close(fd)
|
|
try:
|
|
os.unlink(path)
|
|
except FileNotFoundError:
|
|
pass
|
|
|
|
lat_sorted = sorted(lat)
|
|
def pct(p):
|
|
idx = min(len(lat_sorted)-1, max(0, math.ceil((p/100)*len(lat_sorted))-1))
|
|
return lat_sorted[idx]
|
|
|
|
print("count", len(lat))
|
|
print("write_bytes", size)
|
|
print("mean_ms", round(statistics.mean(lat), 6))
|
|
print("median_ms", round(statistics.median(lat), 6))
|
|
print("p95_ms", round(pct(95), 6))
|
|
print("p99_ms", round(pct(99), 6))
|
|
print("max_ms", round(max(lat), 6))
|