diff options
author | Kyle Blatter <[email protected]> | 2014-11-05 10:08:45 -0800 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2015-01-28 10:59:19 -0800 |
commit | 3bfc7f1b2052a794ffceb6a33f5b21f613a479dc (patch) | |
tree | 21cc2f785aa29213953f5c2bf7f8d15b9b755871 /cmd/arc_summary | |
parent | 53dc1139e7de76045b73ff9c72d75b81653b7012 (diff) |
Refactor arc_summary to simplify -p processing
The -p option is used to specify a specific page of output to be
displayed. If omitted, all output pages would be displayed.
arc_summary, as it stood, had really kludgy processing code for
processing the -p option. It relied on a try-except block which was
treated as an if statement and in normal operation would fail any time a
user didn't specify the -p option on the command line. When the
exception was thrown, the script would then display all output pages.
This happened whether the -p option was omitted or malformed. Thus, in
the principle use case, an exception would be raised in order to run the
script as desired. The same except code would be called regardless of
the exception, however, and malformed -p arguments would also cause the
script to execute.
Additionally, this required the function which handles the case where
all output pages were to be displayed, _call_all, to be potentially
called from several locations within main.
This commit refactors the option processing code to simplify it and make
it easier to catch runtime errors in the script. This is done by
specializing the try-except block to only have an exception when the -p
argument is malformed. When the -p option is correctly selected by the
user, it calls a function in the unSub array directly, which will only
display one page of output.
Finally in the context of this refactoring the page breaks have been
removed. Pages seem to have been added into the output in the FreeNAS
version of the script. This patch removes pages from the output to more
closely resemble the freebsd version of the script.
Signed-off-by: Brian Behlendorf <[email protected]>
Signed-off-by: Kyle Blatter <[email protected]>
Signed-off-by: Ned Bass <[email protected]>
Diffstat (limited to 'cmd/arc_summary')
-rwxr-xr-x | cmd/arc_summary/arc_summary.py | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/cmd/arc_summary/arc_summary.py b/cmd/arc_summary/arc_summary.py index 25db1a941..1456e58f3 100755 --- a/cmd/arc_summary/arc_summary.py +++ b/cmd/arc_summary/arc_summary.py @@ -97,7 +97,6 @@ def div1(): def div2(): - div1() sys.stdout.write("\n") @@ -1049,7 +1048,6 @@ def _sysctl_summary(Kstat): sys.stdout.write("\t\# %s\n" % sysctl_descriptions[name]) sys.stdout.write(format % (name, value)) - unSub = [ _arc_summary, _arc_efficiency, @@ -1058,17 +1056,6 @@ unSub = [ _vdev_summary, ] - -def _call_all(): - page = 1 - Kstat = get_Kstat() - for unsub in unSub: - unsub(Kstat) - sys.stdout.write("\t\t\t\t\t\t\t\tPage: %2d" % page) - div2() - page += 1 - - def zfs_header(): daydate = time.strftime("%a %b %d %H:%M:%S %Y") @@ -1094,20 +1081,27 @@ def main(): if opt == '-p': args['p'] = arg - if args: - alternate_sysctl_layout = True if 'a' in args else False - show_sysctl_descriptions = True if 'd' in args else False - try: - zfs_header() - unSub[int(args['p']) - 1]() - div2() + Kstat = get_Kstat() - except: - _call_all() + alternate_sysctl_layout = 'a' in args + show_sysctl_descriptions = 'd' in args + pages = [] + + if 'p' in args: + try: + pages.append(unSub[int(args['p']) - 1]) + except IndexError , e: + sys.stderr.write('the argument to -p must be between 1 and ' + + str(len(unSub)) + '\n') + sys.exit() else: - _call_all() + pages = unSub + zfs_header() + for page in pages: + page(Kstat) + div2() if __name__ == '__main__': main() |