diff --git a/guider/guider.py b/guider/guider.py index f9acd567..ca391d3e 100755 --- a/guider/guider.py +++ b/guider/guider.py @@ -7,7 +7,7 @@ __credits__ = "Peace Lee" __license__ = "GPLv2" __version__ = "3.9.8" -__revision__ = "240817" +__revision__ = "240818" __maintainer__ = "Peace Lee" __email__ = "iipeace5@gmail.com" __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: "") if ignore else None, + default=(lambda o: "") if ignore else None, ) if pretty: @@ -48974,13 +48974,24 @@ 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( @@ -48988,11 +48999,24 @@ def _monitorConn(connFd): ) 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