All of lore.kernel.org
 help / color / mirror / Atom feed
From: schumaker.anna@gmail.com
To: steved@redhat.com, linux-nfs@vger.kernel.org
Cc: Anna.Schumaker@Netapp.com
Subject: [PATCH v3 3/9] nfssysfs.py: Add a command for printing individual xprts
Date: Mon, 30 Aug 2021 11:56:47 -0400	[thread overview]
Message-ID: <20210830155653.1386161-4-Anna.Schumaker@Netapp.com> (raw)
In-Reply-To: <20210830155653.1386161-1-Anna.Schumaker@Netapp.com>

From: Anna Schumaker <Anna.Schumaker@Netapp.com>

This shows more detailed information than what is presented with xprt
switches. I take the chance to add a main-export indicator to the
small_str() used when printing out xprt-switches.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 tools/nfssysfs/nfssysfs.py |  2 ++
 tools/nfssysfs/xprt.py     | 38 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/tools/nfssysfs/nfssysfs.py b/tools/nfssysfs/nfssysfs.py
index 90efcbed7ac8..dfad6ac08fa0 100755
--- a/tools/nfssysfs/nfssysfs.py
+++ b/tools/nfssysfs/nfssysfs.py
@@ -11,8 +11,10 @@ parser.set_defaults(func=show_small_help)
 
 
 import switch
+import xprt
 subparser = parser.add_subparsers(title="commands")
 switch.add_command(subparser)
+xprt.add_command(subparser)
 
 
 args = parser.parse_args()
diff --git a/tools/nfssysfs/xprt.py b/tools/nfssysfs/xprt.py
index d37537771c1d..fbdd9bfc9375 100644
--- a/tools/nfssysfs/xprt.py
+++ b/tools/nfssysfs/xprt.py
@@ -1,12 +1,48 @@
+import sysfs
+
 class Xprt:
     def __init__(self, path):
         self.path = path
         self.id = int(str(path).rsplit("-", 2)[1])
         self.type = str(path).rsplit("-", 2)[2]
         self.dstaddr = open(path / "dstaddr", 'r').readline().strip()
+        self.srcaddr = open(path / "srcaddr", 'r').readline().strip()
+
+        with open(path / "xprt_state") as f:
+            self.state = ','.join(f.readline().split()[1:])
+        self.__dict__.update(sysfs.read_info_file(path / "xprt_info"))
 
     def __lt__(self, rhs):
         return self.id < rhs.id
 
+    def __str__(self):
+        state = self.state
+        if self.main_xprt:
+            state = "MAIN," + self.state
+
+        line = "xprt %s: %s, %s, port %s, state <%s>" % \
+                (self.id, self.type, self.dstaddr, self.dst_port, state)
+        line += "\n	Source: %s, port %s, Requests: %s" % \
+                (self.srcaddr, self.src_port, self.num_reqs)
+        line += "\n	Congestion: cur %s, win %s, Slots: min %s, max %s" % \
+                (self.cur_cong, self.cong_win, self.min_num_slots, self.max_num_slots)
+        line += "\n	Queues: binding %s, sending %s, pending %s, backlog %s, tasks %s" % \
+                (self.binding_q_len, self.sending_q_len, self.pending_q_len, self.backlog_q_len, self.tasks_queuelen)
+        return line
+
     def small_str(self):
-        return "xprt %s: %s, %s" % (self.id, self.type, self.dstaddr)
+        return "xprt %s: %s, %s%s" % (self.id, self.type, self.dstaddr,
+                                     f" [main]" if self.main_xprt else "" )
+
+
+def list_xprts(args):
+    xprts = [ Xprt(f) for f in (sysfs.SUNRPC / "xprt-switches").glob("**/xprt-*") ]
+    xprts.sort()
+    for xprt in xprts:
+        if args.id == None or xprt.id == args.id[0]:
+            print(xprt)
+
+def add_command(subparser):
+    parser = subparser.add_parser("xprt", help="Commands for individual xprts")
+    parser.add_argument("--id", metavar="ID", nargs=1, type=int, help="Id of a specific xprt to show")
+    parser.set_defaults(func=list_xprts)
-- 
2.33.0


  parent reply	other threads:[~2021-08-30 15:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-30 15:56 [PATCH v3 0/9] Add a tool for using the new sysfs files schumaker.anna
2021-08-30 15:56 ` [PATCH v3 1/9] nfssysfs: Add a nfssysfs.py tool schumaker.anna
2021-08-30 15:56 ` [PATCH v3 2/9] nfssysfs.py: Add a command for printing xprt switch information schumaker.anna
2021-08-30 15:56 ` schumaker.anna [this message]
2021-08-30 15:56 ` [PATCH v3 4/9] nfssysfs.py: Add a command for printing rpc-client information schumaker.anna
2021-08-30 15:56 ` [PATCH v3 5/9] nfssysfs.py: Add a command for changing xprt dstaddr schumaker.anna
2021-08-30 15:56 ` [PATCH v3 6/9] nfssysfs.py: Add a command for changing xprt-switch dstaddrs schumaker.anna
2021-08-30 15:56 ` [PATCH v3 7/9] nfssysfs.py: Add a command for changing xprt state schumaker.anna
2021-08-30 15:56 ` [PATCH v3 8/9] nfssysfs: Add a man page schumaker.anna
2021-08-30 15:56 ` [PATCH v3 9/9] nfssysfs: Add installation to the Makefile schumaker.anna
2021-08-31 12:26 ` [PATCH v3 0/9] Add a tool for using the new sysfs files Benjamin Coddington

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=20210830155653.1386161-4-Anna.Schumaker@Netapp.com \
    --to=schumaker.anna@gmail.com \
    --cc=Anna.Schumaker@Netapp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.