This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 4ff0447027e4bf5713cc4ab1aa64b13965f5ff05
Author: Zhe Weng <weng...@xiaomi.com>
AuthorDate: Thu Aug 22 15:55:16 2024 +0800

    tools/gdb: Add net.py and netstats command
    
    Only support IOB stats now, may add socket status later.
    
    (gdb) netstats
    IOB:       size    ntotal     nfree     nwait nthrottle
               1518        72        72         0        40
    
    Signed-off-by: Zhe Weng <weng...@xiaomi.com>
---
 tools/gdb/net.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/tools/gdb/net.py b/tools/gdb/net.py
new file mode 100644
index 0000000000..d361a211a1
--- /dev/null
+++ b/tools/gdb/net.py
@@ -0,0 +1,61 @@
+############################################################################
+# tools/gdb/net.py
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################
+
+import gdb
+import utils
+
+
+class NetStats(gdb.Command):
+    """Network statistics"""
+
+    def __init__(self):
+        super(NetStats, self).__init__("netstats", gdb.COMMAND_USER)
+
+    def iob_stats(self):
+        try:
+            size = utils.get_symbol_value("CONFIG_IOB_BUFSIZE")
+            ntotal = utils.get_symbol_value("CONFIG_IOB_NBUFFERS")
+
+            nfree = gdb.parse_and_eval("g_iob_sem")["semcount"]
+            nwait, nfree = (0, nfree) if nfree >= 0 else (-nfree, 0)
+
+            nthrottle = (
+                gdb.parse_and_eval("g_throttle_sem")["semcount"]
+                if utils.get_symbol_value("CONFIG_IOB_THROTTLE") > 0
+                else 0
+            )
+
+            gdb.write(
+                "IOB: %10s%10s%10s%10s%10s\n"
+                % ("size", "ntotal", "nfree", "nwait", "nthrottle")
+            )
+            gdb.write(
+                "     %10d%10d%10d%10d%10d\n" % (size, ntotal, nfree, nwait, 
nthrottle)
+            )
+        except gdb.error as e:
+            gdb.write("Failed to get IOB stats: %s\n" % e)
+
+    def invoke(self, args, from_tty):
+        if utils.get_symbol_value("CONFIG_MM_IOB"):
+            self.iob_stats()
+
+
+if utils.get_symbol_value("CONFIG_NET"):
+    NetStats()

Reply via email to