Correct style in arcstat and arc_summary

Fix arcstat and arc_summary so they pass
flake8 python code style checks.

Signed-off-by: Giuseppe Di Natale <dinatale2@llnl.gov>
This commit is contained in:
Giuseppe Di Natale 2016-10-06 10:04:54 -07:00
parent 5cc78dc812
commit 0bde1f7cb5
2 changed files with 51 additions and 58 deletions

View File

@ -66,22 +66,6 @@ def get_Kstat():
name, unused, value = kstat.split()
Kstat[namespace + name] = D(value)
Kstats = [
"hw.pagesize",
"hw.physmem",
"kern.maxusers",
"vm.kmem_map_free",
"vm.kmem_map_size",
"vm.kmem_size",
"vm.kmem_size_max",
"vm.kmem_size_min",
"vm.kmem_size_scale",
"vm.stats",
"vm.swap_total",
"vm.swap_reserved",
"kstat.zfs",
"vfs.zfs"
]
Kstat = {}
load_proc_kstats('/proc/spl/kstat/zfs/arcstats',
'kstat.zfs.misc.arcstats.')
@ -92,6 +76,7 @@ def get_Kstat():
return Kstat
def div1():
sys.stdout.write("\n")
for i in range(18):
@ -188,17 +173,17 @@ def get_arc_summary(Kstat):
output['memory_throttle_count'] = fHits(memory_throttle_count)
### ARC Misc. ###
# ARC Misc.
deleted = Kstat["kstat.zfs.misc.arcstats.deleted"]
mutex_miss = Kstat["kstat.zfs.misc.arcstats.mutex_miss"]
### ARC Misc. ###
# ARC Misc.
output["arc_misc"] = {}
output["arc_misc"]["deleted"] = fHits(deleted)
output["arc_misc"]['mutex_miss'] = fHits(mutex_miss)
output["arc_misc"]['evict_skips'] = fHits(mutex_miss)
### ARC Sizing ###
# ARC Sizing
arc_size = Kstat["kstat.zfs.misc.arcstats.size"]
mru_size = Kstat["kstat.zfs.misc.arcstats.p"]
target_max_size = Kstat["kstat.zfs.misc.arcstats.c_max"]
@ -207,7 +192,7 @@ def get_arc_summary(Kstat):
target_size_ratio = (target_max_size / target_min_size)
### ARC Sizing ###
# ARC Sizing
output['arc_sizing'] = {}
output['arc_sizing']['arc_size'] = {
'per': fPerc(arc_size, target_max_size),
@ -226,7 +211,7 @@ def get_arc_summary(Kstat):
'num': fBytes(target_size),
}
### ARC Hash Breakdown ###
# ARC Hash Breakdown
output['arc_hash_break'] = {}
output['arc_hash_break']['hash_chain_max'] = Kstat[
"kstat.zfs.misc.arcstats.hash_chain_max"
@ -267,7 +252,7 @@ def get_arc_summary(Kstat):
'num': fBytes(mfu_size),
}
### ARC Hash Breakdown ###
# ARC Hash Breakdown
hash_chain_max = Kstat["kstat.zfs.misc.arcstats.hash_chain_max"]
hash_chains = Kstat["kstat.zfs.misc.arcstats.hash_chains"]
hash_collisions = Kstat["kstat.zfs.misc.arcstats.hash_collisions"]
@ -288,7 +273,7 @@ def get_arc_summary(Kstat):
def _arc_summary(Kstat):
### ARC Sizing ###
# ARC Sizing
arc = get_arc_summary(Kstat)
sys.stdout.write("ARC Summary: (%s)\n" % arc['health'])
@ -297,7 +282,7 @@ def _arc_summary(Kstat):
arc['memory_throttle_count'])
sys.stdout.write("\n")
### ARC Misc. ###
# ARC Misc.
sys.stdout.write("ARC Misc:\n")
sys.stdout.write("\tDeleted:\t\t\t\t%s\n" % arc['arc_misc']['deleted'])
sys.stdout.write("\tMutex Misses:\t\t\t\t%s\n" %
@ -306,7 +291,7 @@ def _arc_summary(Kstat):
arc['arc_misc']['mutex_miss'])
sys.stdout.write("\n")
### ARC Sizing ###
# ARC Sizing
sys.stdout.write("ARC Size:\t\t\t\t%s\t%s\n" % (
arc['arc_sizing']['arc_size']['per'],
arc['arc_sizing']['arc_size']['num']
@ -344,7 +329,7 @@ def _arc_summary(Kstat):
sys.stdout.write("\n")
### ARC Hash Breakdown ###
# ARC Hash Breakdown
sys.stdout.write("ARC Hash Breakdown:\n")
sys.stdout.write("\tElements Max:\t\t\t\t%s\n" %
arc['arc_hash_break']['elements_max'])
@ -875,7 +860,8 @@ def _tunable_summary(Kstat):
values = {}
for name in names:
with open("/sys/module/zfs/parameters/" + name) as f: value = f.read()
with open("/sys/module/zfs/parameters/" + name) as f:
value = f.read()
values[name] = value.strip()
descriptions = {}
@ -950,13 +936,15 @@ def usage():
sys.stdout.write("\t -p PAGE, --page=PAGE : "
"Select a single output page to display,\n")
sys.stdout.write("\t "
"should be an integer between 1 and " + str(len(unSub)) + "\n\n")
"should be an integer between 1 and " +
str(len(unSub)) + "\n\n")
sys.stdout.write("Examples:\n")
sys.stdout.write("\tarc_summary.py -a\n")
sys.stdout.write("\tarc_summary.py -p 4\n")
sys.stdout.write("\tarc_summary.py -ad\n")
sys.stdout.write("\tarc_summary.py --page=2\n")
def main():
global show_tunable_descriptions
global alternate_tunable_layout
@ -987,7 +975,7 @@ def main():
if 'p' in args:
try:
pages.append(unSub[int(args['p']) - 1])
except IndexError as e:
except IndexError:
sys.stderr.write('the argument to -p must be between 1 and ' +
str(len(unSub)) + '\n')
sys.exit()

View File

@ -229,15 +229,19 @@ def print_header():
sys.stdout.write("%*s%s" % (cols[col][0], col, sep))
sys.stdout.write("\n")
def get_terminal_lines():
try:
import fcntl, termios, struct
import fcntl
import termios
import struct
data = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, '1234')
sz = struct.unpack('hh', data)
return sz[0]
except:
pass
def update_hdr_intr():
global hdr_intr
@ -245,6 +249,7 @@ def update_hdr_intr():
if lines and lines > 3:
hdr_intr = lines - 3
def resize_handler(signum, frame):
update_hdr_intr()