tools/gdb: Add command 'netcheck' for checks on network stack
The diagnostics result looks like: { "title": "Netcheck Report", "command": "netcheck", "result": "PASS", "message": [] } or { "title": "Netcheck Report", "command": "netcheck", "result": "WARN", "message": [ "[WARNING] IOB used up: free -1 throttle 0" ] } The netcheck command reports like: IOB check: WARN [WARNING] IOB used up: free -1 throttle 0 Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
parent
b293c722bd
commit
aa74ba5ace
1 changed files with 65 additions and 0 deletions
|
@ -20,6 +20,8 @@
|
|||
#
|
||||
############################################################################
|
||||
|
||||
from enum import Enum
|
||||
|
||||
import gdb
|
||||
|
||||
from . import utils
|
||||
|
@ -251,3 +253,66 @@ class NetStats(gdb.Command):
|
|||
if utils.get_symbol_value("CONFIG_NET_UDP") and "udp" in args:
|
||||
self.udp_stats()
|
||||
gdb.write("\n")
|
||||
|
||||
|
||||
class NetCheckResult(Enum):
|
||||
PASS = 0
|
||||
WARN = 1
|
||||
FAILED = 2
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.value < other.value
|
||||
|
||||
|
||||
class NetCheck(gdb.Command):
|
||||
"""Network check"""
|
||||
|
||||
def __init__(self):
|
||||
if utils.get_symbol_value("CONFIG_NET"):
|
||||
super().__init__("netcheck", gdb.COMMAND_USER)
|
||||
|
||||
def diagnose(self, *args, **kwargs):
|
||||
result, message = NetCheckResult.PASS, []
|
||||
|
||||
if utils.get_symbol_value("CONFIG_MM_IOB"):
|
||||
ret, msg = self.check_iob()
|
||||
result = max(result, ret)
|
||||
message.extend(msg)
|
||||
|
||||
return {
|
||||
"title": "Netcheck Report",
|
||||
"summary": "Net status check",
|
||||
"result": "pass" if result else "fail",
|
||||
"command": "netcheck",
|
||||
"data": message,
|
||||
}
|
||||
|
||||
def check_iob(self):
|
||||
result = NetCheckResult.PASS
|
||||
message = []
|
||||
try:
|
||||
nfree = gdb.parse_and_eval("g_iob_sem")["semcount"]
|
||||
nthrottle = (
|
||||
gdb.parse_and_eval("g_throttle_sem")["semcount"]
|
||||
if utils.get_symbol_value("CONFIG_IOB_THROTTLE") > 0
|
||||
else 0
|
||||
)
|
||||
|
||||
if nfree < 0 or nthrottle < 0:
|
||||
result = max(result, NetCheckResult.WARN)
|
||||
message.append(
|
||||
"[WARNING] IOB used up: free %d throttle %d" % (nfree, nthrottle)
|
||||
)
|
||||
|
||||
except gdb.error as e:
|
||||
result = max(result, NetCheckResult.FAILED)
|
||||
message.append("[FAILED] Failed to check IOB: %s" % e)
|
||||
|
||||
finally:
|
||||
return result, message
|
||||
|
||||
def invoke(self, args, from_tty):
|
||||
if utils.get_symbol_value("CONFIG_MM_IOB"):
|
||||
result, message = self.check_iob()
|
||||
gdb.write("IOB check: %s\n" % result.name)
|
||||
gdb.write("\n".join(message))
|
||||
|
|
Loading…
Reference in a new issue