Created
January 14, 2017 07:37
-
-
Save YoungForest/0b3fdfbe15821b32991d9d48a9122290 to your computer and use it in GitHub Desktop.
硬盘写操作压力测试
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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