"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "", "" "". "" "" "" "" "" "" "" "," "" "" "," "" "" "," "" "," "" ">> Disk Information .py>> Author: Liu Yang>> e-mail: [email protected] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "." "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" #!/usr/bin/env python#-*-coding:utf-8-*-import sys,osimport Psutilfrom Time Import sleep ' judgment Platform ' def Platform_judge (): # Returns the platform Information lowercase platform=sys.platform.lower () return plat The form ' converts the bytes number into a more intuitive symbol display ' ' Def bytes2symbols (bytes_value): ' Unit symbol ' ' symbols = (' K ', ' M ', ' G ', ' T ', ' P ', ' E ', ' Z ') , ' Y ') "Each unit corresponds to the bytes number of dictionaries, first defined as null ' ' prefix={} ' to get such {k:1024, m:1024*1024,g:1024**3}, for Loop" ' for I,s in E Numerate (symbols): # ' Enumerate () for enumeration function ' # ' I: for subscript ' # ' s: Represents the value of the subscript corresponding to the value ' # ' to take to the symbol tuple, as For Prfix dictionary key, assign value to value according to key ' prefix[s]=1024** (i+1) # ' ' Print the corresponding Dictionary ' ' ' # ' ' # ' (prefix) symbols_value=0 Symbol= ' # ' Loop prefix dictionary, get converted value ' for Key,value In Prefix.items (): If Bytes_value >=value:symbols_value=bytes_value/value symbol=key # If the minimum KB is not met, the elif bytes_value <1024:return '%0.2fb '%bytes_value # "is shown in B to return the converted value (str)" ' Return '%0.2F%SB '% (symbols_value,symbol) ' real-time IO rate display ' def disk_io_message (): T1 = psutil.disk_io_counters () SL EEP (1) "Judgment Platform, command clear screen" if platform_judge () = = ' Linux ': Os.system (' Clear ') else:os.system (' cls ') t 2 = psutil.disk_io_counters () read_bytes = Bytes2symbols (t2.read_bytes-t1.read_bytes) write_bytes = Bytes2symbols ( T2.write_bytes-t1.write_bytes) # TPS TPS = T2.read_count + T2.write_count-t1.read_count-t1.write_count prin T (' Read/s:%10s '%read_bytes) print (' Write/s:%10s '%write_bytes) print (' tps:%10d '%tps) ' disk partition information display ' Def disk_partitions (): # Get a list of disk details disks=psutil.disk_partitions () # loop list, print for disk in Disks:print ('%s%6s%10s '% (disk.device , disk.fstype,disk.opts))if __name__ = = ' __main__ ': # Platform=platform_judge () # Value=bytes2symbols (1025) # Print (value) # Print (plat form) while True:disk_io_message () # Disk partition information # disk_partitions () # IO Real-time Performance Information # disk_io_message ()
[Python Study Notes] disk partitioning and IO performance