-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
top: Add monitor and sysdump commands in UDS server
Signed-off-by: iipeace <[email protected]>
- Loading branch information
Showing
1 changed file
with
36 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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: | ||
|
@@ -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) | ||
|
@@ -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() | ||
|
@@ -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: | ||
|
@@ -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: | ||
|
@@ -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 | ||
|
||
|