From: Frank Sorenson <sorenson@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: steved@redhat.com, chuck.lever@oracle.com
Subject: [nfs-utils PATCH 8/8] mountstats/nfsiostat: merge and rework the infinite and counted loops
Date: Thu, 30 Jan 2025 08:20:07 -0600 [thread overview]
Message-ID: <20250130142008.3600334-9-sorenson@redhat.com> (raw)
In-Reply-To: <20250130142008.3600334-1-sorenson@redhat.com>
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(-)
diff --git a/tools/mountstats/mountstats.py b/tools/mountstats/mountstats.py
index fbd57f51..d488f9e1 100755
--- a/tools/mountstats/mountstats.py
+++ b/tools/mountstats/mountstats.py
@@ -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:
diff --git a/tools/nfs-iostat/nfs-iostat.py b/tools/nfs-iostat/nfs-iostat.py
index f69ffb0e..e46b1a83 100755
--- a/tools/nfs-iostat/nfs-iostat.py
+++ b/tools/nfs-iostat/nfs-iostat.py
@@ -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
--
2.48.1
next prev parent reply other threads:[~2025-01-30 14:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 14:19 [nfs-utils PATCH 0/8] mountstats/nfsiostat: bugfixes for iostat Frank Sorenson
2025-01-30 14:20 ` [nfs-utils PATCH 1/8] mountstats/nfsiostat: add a function to return the fstype Frank Sorenson
2025-01-30 14:20 ` [nfs-utils PATCH 2/8] mountstats: when printing iostats, verify that old and new types are the same Frank Sorenson
2025-01-30 14:20 ` [nfs-utils PATCH 3/8] nfsiostat: mirror how mountstats iostat prints the stats Frank Sorenson
2025-01-30 14:20 ` [nfs-utils PATCH 4/8] nfsiostat: fix crash when filtering mountstats after unmount Frank Sorenson
2025-01-30 14:20 ` [nfs-utils PATCH 5/8] nfsiostat: make comment explain mount/unmount more broadly Frank Sorenson
2025-01-30 14:20 ` [nfs-utils PATCH 6/8] mountstats: filter for nfs mounts in a function, each iostat iteration Frank Sorenson
2025-01-30 14:20 ` [nfs-utils PATCH 7/8] mountstats/nfsiostat: Move the checks for empty mountpoint list into the print function Frank Sorenson
2025-01-30 14:20 ` Frank Sorenson [this message]
2025-01-30 14:28 ` [nfs-utils PATCH 0/8] mountstats/nfsiostat: bugfixes for iostat Chuck Lever
2025-02-05 22:53 ` Steve Dickson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250130142008.3600334-9-sorenson@redhat.com \
--to=sorenson@redhat.com \
--cc=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=steved@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox