Skip to content

Commit

Permalink
top: Add monitor and sysdump commands in UDS server
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <[email protected]>
  • Loading branch information
iipeace committed Aug 18, 2024
1 parent 6d68ef0 commit 4ca7e16
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions guider/guider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__credits__ = "Peace Lee"
__license__ = "GPLv2"
__version__ = "3.9.8"
__revision__ = "240817"
__revision__ = "240818"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -9582,7 +9582,7 @@ def convDict2Str(dictObj, pretty=True, indent=2, ignore=False):
dictObj,
indent=indent,
ensure_ascii=False,
default=(lambda o: "<not serializable>") if ignore else None,
default=(lambda o: "<N/A>") if ignore else None,
)

if pretty:
Expand Down Expand Up @@ -48974,25 +48974,49 @@ def _monitorConn(connFd):
tobj.daemon = True
tobj.start()

# define notify function #
def _printExecutedCmd():
SysMgr.printInfo(
"executed '%s' command from %s" % (cmd, cliProc)
)

# set final command #
cmdList = cmd.split("|")
mainCmd = cmdList[0]
if mainCmd == "dump":
SysMgr.printFd = MemoryFile(name="buf")
if mainCmd in ("dump", "sysdump"):
# summarize monitoring buffer #
SysMgr.streamEnable = True
TaskAnalyzer.printIntervalUsage(onlySummary=True)
SysMgr.printFd = MemoryFile(name="buf")
TaskAnalyzer.printIntervalUsage(
onlySummary=True, onlyTotal=mainCmd == "sysdump"
)

# send summary stats in JSON #
SysMgr.jsonEnable = True
SysMgr.printFd.seek(0)
stats, memstat = TaskAnalyzer.getStatsFile(
"tmp", handle=SysMgr.printFd
)
SysMgr.printFd = connFd
connObj.write(UtilMgr.convDict2Str(stats, pretty=False))

# print status #
_printExecutedCmd()
elif mainCmd == "monitor":
pass
# clear buffer #
SysMgr.clearProcBuffer()

# execute a command #
SysMgr.printInfo("executed '%s' command from %s" % (cmd, cliProc))
# print status #
_printExecutedCmd()

# start sending stats in JSON #
SysMgr.jsonEnable = True
SysMgr.printFd = connObj

return
else:
SysMgr.printErr("no support '%s' command" % mainCmd)
sys.exit(0)

# terminate #
sys.exit(0)
Expand Down Expand Up @@ -49413,8 +49437,7 @@ def newHandler(signum=None, frame=None):
pid = SysMgr.createProcess()
if pid > 0:
# clear buffer as parent #
SysMgr.procBufferSize = 0
SysMgr.procBuffer = []
SysMgr.clearProcBuffer()

# close an output file to sync #
SysMgr.closePrintFd()
Expand Down Expand Up @@ -52749,7 +52772,7 @@ def parseRuntimeOption(value):
@staticmethod
def reloadFileBuffer(path=None, retFd=False, fd=None):
# pylint: disable=no-member
SysMgr.procBuffer = []
SysMgr.clearProcBuffer()

# load raw data from the file #
try:
Expand Down Expand Up @@ -59815,11 +59838,11 @@ def launchGuider(
SysMgr.groupProcEnable = False
SysMgr.optionList = []
ConfigMgr.confData = {}
SysMgr.procBuffer = []
SysMgr.exitFuncList = []
SysMgr.customCmd = []
SysMgr.rcmdList = {}
SysMgr.requestQueue = []
SysMgr.clearProcBuffer()

# clear global packages #
if initPkg:
Expand Down Expand Up @@ -120038,8 +120061,7 @@ def _printMemUsage(signum=None, frame=None):

# clean up #
targetFile = SysMgr.printFd.name
del SysMgr.procBuffer
SysMgr.procBuffer = []
SysMgr.clearProcBuffer()
SysMgr.printFd = None
SysMgr.outPath = origOutput

Expand Down

0 comments on commit 4ca7e16

Please sign in to comment.