mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 07:28:38 +08:00
tools/gdb: Add packet statistic in netstats
Unlike NuttX's one, we use decimal instead of hexadecimal, because other stats may all use decimal. (gdb) netstats IOB: size ntotal nfree nwait nthrottle 1518 72 72 0 40 Packets: IPv4 IPv6 TCP UDP ICMP ICMPv6 Received 137 43 0 49 88 0 Dropped 0 43 0 0 74 0 VHL 0 0 - - - - Frag 0 0 - - - - Chksum 0 - 0 0 - - Type - - - - 74 0 Proto 0 0 - - - - Sent 11481 11542 0 17223 27 4 Rexmit - - 0 - - - Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
parent
4ff0447027
commit
1c884ee230
2 changed files with 43 additions and 0 deletions
|
@ -52,9 +52,44 @@ class NetStats(gdb.Command):
|
|||
except gdb.error as e:
|
||||
gdb.write("Failed to get IOB stats: %s\n" % e)
|
||||
|
||||
def pkt_stats(self):
|
||||
try:
|
||||
netstats = gdb.parse_and_eval("g_netstats")
|
||||
gdb.write(
|
||||
"Packets:%7s%7s%7s%7s%7s%7s\n"
|
||||
% ("IPv4", "IPv6", "TCP", "UDP", "ICMP", "ICMPv6")
|
||||
)
|
||||
|
||||
def stats_line(title, member):
|
||||
gdb.write("%-8s" % title)
|
||||
for proto in ("ipv4", "ipv6", "tcp", "udp", "icmp", "icmpv6"):
|
||||
gdb.write(
|
||||
"%7s"
|
||||
% utils.get_field(utils.get_field(netstats, proto), member, "-")
|
||||
)
|
||||
gdb.write("\n")
|
||||
|
||||
stats_line("Received", "recv")
|
||||
stats_line("Dropped", "drop")
|
||||
stats_line(" VHL", "vhlerr")
|
||||
stats_line(" Frag", "fragerr")
|
||||
stats_line(" Chksum", "chkerr")
|
||||
stats_line(" Type", "typeerr")
|
||||
stats_line(" Proto", "protoerr")
|
||||
# TODO: Maybe print TCP's ackerr, rst, syndrop, synrst here
|
||||
stats_line("Sent", "sent")
|
||||
stats_line(" Rexmit", "rexmit")
|
||||
|
||||
except gdb.error as e:
|
||||
gdb.write("Failed to get Net Stats: %s\n" % e)
|
||||
|
||||
def invoke(self, args, from_tty):
|
||||
if utils.get_symbol_value("CONFIG_MM_IOB"):
|
||||
self.iob_stats()
|
||||
gdb.write("\n")
|
||||
if utils.get_symbol_value("CONFIG_NET_STATISTICS"):
|
||||
self.pkt_stats()
|
||||
gdb.write("\n")
|
||||
|
||||
|
||||
if utils.get_symbol_value("CONFIG_NET"):
|
||||
|
|
|
@ -169,6 +169,14 @@ def get_symbol_value(name, locspec="nx_start", cacheable=True):
|
|||
return value
|
||||
|
||||
|
||||
def get_field(val, key, default=None):
|
||||
"""Get a field from a gdb.Value, return default if key not found"""
|
||||
try:
|
||||
return val[key] if val else default
|
||||
except gdb.error:
|
||||
return default
|
||||
|
||||
|
||||
def import_check(module, name="", errmsg=""):
|
||||
try:
|
||||
module = __import__(module, fromlist=[name])
|
||||
|
|
Loading…
Reference in a new issue