@@ -1007,37 +1007,29 @@ def iostat_command(args):
else:
old_mountstats = None
+ sample_time = 0
+
# make certain devices contains only NFS mount points
devices = list_nfs_mounts(origdevices, mountstats)
-
- sample_time = 0
+ print_iostat_summary(old_mountstats, mountstats, devices, sample_time)
if args.interval is None:
- print_iostat_summary(old_mountstats, mountstats, devices, sample_time)
return
- if args.count is not None:
- count = args.count
- while count != 0:
- print_iostat_summary(old_mountstats, mountstats, devices, sample_time)
- old_mountstats = mountstats
- time.sleep(args.interval)
- sample_time = args.interval
- mountstats = parse_stats_file(args.infile)
- # nfs mountpoints may appear or disappear, so we need to
- # recheck the devices list each time we parse mountstats
- devices = list_nfs_mounts(origdevices, mountstats)
+ count = args.count
+ while True:
+ if count is not None:
count -= 1
- else:
- while True:
- print_iostat_summary(old_mountstats, mountstats, devices, sample_time)
- old_mountstats = mountstats
- time.sleep(args.interval)
- sample_time = args.interval
- mountstats = parse_stats_file(args.infile)
- # nfs mountpoints may appear or disappear, so we need to
- # recheck the devices list each time we parse mountstats
- devices = list_nfs_mounts(origdevices, mountstats)
+ if count == 0:
+ break
+ time.sleep(args.interval)
+ old_mountstats = mountstats
+ sample_time = args.interval
+ mountstats = parse_stats_file(args.infile)
+ # nfs mountpoints may appear or disappear, so we need to
+ # recheck the devices list each time we parse mountstats
+ devices = list_nfs_mounts(origdevices, mountstats)
+ print_iostat_summary(old_mountstats, mountstats, devices, sample_time)
args.infile.close()
if args.since:
@@ -614,37 +614,29 @@ client are listed.
print('Illegal <count> value %s' % arg)
return
- # make certain devices contains only NFS mount points
- devices = list_nfs_mounts(origdevices, mountstats)
-
old_mountstats = None
sample_time = 0.0
+ # make certain devices contains only NFS mount points
+ devices = list_nfs_mounts(origdevices, mountstats)
+ print_iostat_summary(old_mountstats, mountstats, devices, sample_time, options)
+
if not interval_seen:
- print_iostat_summary(old_mountstats, mountstats, devices, sample_time, options)
return
- if count_seen:
- while count != 0:
- print_iostat_summary(old_mountstats, mountstats, devices, sample_time, options)
- old_mountstats = mountstats
- time.sleep(interval)
- sample_time = interval
- mountstats = parse_stats_file('/proc/self/mountstats')
- # nfs mountpoints may appear or disappear, so we need to
- # recheck the devices list each time we parse mountstats
- devices = list_nfs_mounts(origdevices,mountstats)
+ while True:
+ if count_seen:
count -= 1
- else:
- while True:
- print_iostat_summary(old_mountstats, mountstats, devices, sample_time, options)
- old_mountstats = mountstats
- time.sleep(interval)
- sample_time = interval
- mountstats = parse_stats_file('/proc/self/mountstats')
- # nfs mountpoints may appear or disappear, so we need to
- # recheck the devices list each time we parse mountstats
- devices = list_nfs_mounts(origdevices,mountstats)
+ if count == 0:
+ break
+ time.sleep(interval)
+ old_mountstats = mountstats
+ sample_time = interval
+ mountstats = parse_stats_file('/proc/self/mountstats')
+ # nfs mountpoints may appear or disappear, so we need to
+ # recheck the devices list each time we parse mountstats
+ devices = list_nfs_mounts(origdevices, mountstats)
+ print_iostat_summary(old_mountstats, mountstats, devices, sample_time, options)
#
# Main
We always want to print at least once, so move the first print before the interval/count tests. The infinite loop and counted loop are nearly identical, so we merge them, and break out of the loop if necessary. By decrementing the count and checking at the beginning of the loop, we also fix a bug where we sleep and parse the mountstats file one extra time after count iterations. Signed-off-by: Frank Sorenson <sorenson@redhat.com> --- tools/mountstats/mountstats.py | 40 ++++++++++++++-------------------- tools/nfs-iostat/nfs-iostat.py | 40 ++++++++++++++-------------------- 2 files changed, 32 insertions(+), 48 deletions(-)