Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
硬盘写操作压力测试
import time
import sys
import os
def main():
if (len(sys.argv) != 3):
sys.exit("Ususage: %s diskname level.(level can be 0, 1, 2, 3, Bigger level means higher disk read speed.)" %(sys.argv[0]))
disk = sys.argv[1]
# disk = r'/tmp/tmpfile'
disk += '1'
if sys.argv[2] == '0':
speed = 10
elif sys.argv[2] == '1':
speed = 100
elif sys.argv[2] == '2':
speed = 500
elif sys.argv[2] == '3':
speed = 1000
else:
sys.exit("Level has to be 0, 1, 2 or 3")
os.system('sudo mount %s /mnt' %(disk))
try:
while True:
start = time.clock()
os.system('sudo dd if=/dev/zero of=%s bs=1024k count=%d conv=fdatasync > /dev/null 2> /dev/null' %('/mnt/tmp/output', speed))
end = time.clock()
if 1 > end - start:
time.sleep(1 - (end - start))
os.system('sudo rm %s' %('/mnt/tmp/output'))
except Exception as e:
pass
else:
pass
finally:
os.system('sudo rm %s' %('/mnt/tmp/output'))
os.system('sudo umount /mnt')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.