Skip to content

Instantly share code, notes, and snippets.

@zougloub
Created May 20, 2018 22:59
Show Gist options
  • Save zougloub/979545b84c8dae133765fc13617d9625 to your computer and use it in GitHub Desktop.
Save zougloub/979545b84c8dae133765fc13617d9625 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 vi:noet
# Characterization test for SMR drives
import sys, os, subprocess, time, mmap
if __name__ == "__main__":
device = sys.argv[1]
size = int(subprocess.check_output(["blockdev", "--getsize64", device]).decode().rstrip())
print("{device} has size {size}".format(**locals()))
fd = os.open(device, os.O_RDWR | os.O_DIRECT)
buflen = 1<<20
def pattern_gen():
buf = mmap.mmap(-1, buflen)
pos = size - buflen
while pos > 0:
yield buf, pos
pos -= 100 * (1<<20)
now = time.time()
last = now
last_count = 0
for idx_offset, (buf, offset) in enumerate(pattern_gen()):
now = time.time()
if now > last + 1:
iops = idx_offset - last_count
print("---")
print("{} iops".format(iops))
print("{:.3f} GB written".format(idx_offset * buflen / 1e9))
last_count = idx_offset
last = now
res = os.pwrite(fd, buf, offset)
if res != buflen:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment