From b7ffc4824d6bc2107ee90ffa6374d229cd54624d Mon Sep 17 00:00:00 2001 From: iipeace Date: Wed, 10 Jul 2024 23:04:18 +0900 Subject: [PATCH] top: Add crash count info Signed-off-by: iipeace --- guider/guider.py | 107 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 90 insertions(+), 17 deletions(-) diff --git a/guider/guider.py b/guider/guider.py index e8c2ddfd..3272d089 100755 --- a/guider/guider.py +++ b/guider/guider.py @@ -7,7 +7,7 @@ __credits__ = "Peace Lee" __license__ = "GPLv2" __version__ = "3.9.8" -__revision__ = "240709" +__revision__ = "240710" __maintainer__ = "Peace Lee" __email__ = "iipeace5@gmail.com" __repository__ = "https://github.com/iipeace/guider" @@ -7554,7 +7554,14 @@ def getPath(path): return dirname, filename @staticmethod - def getFiles(path, name=None, incFile=True, incDir=False, recursive=True): + def getFiles( + path, + name=None, + incFile=True, + incDir=False, + recursive=True, + exceptList=[], + ): flist = [] for r, d, f in os.walk(path): @@ -7563,6 +7570,8 @@ def getFiles(path, name=None, incFile=True, incDir=False, recursive=True): for s in target: if name and not UtilMgr.isValidStr(s, name): continue + elif exceptList and UtilMgr.isValidStr(s, exceptList): + continue flist.append(os.path.join(r, s)) if not recursive: @@ -27261,6 +27270,7 @@ class SysMgr(object): cpuStealUsage = 0 nrOOMKill = 0 nrTotalOOMKill = -1 + nrTotalCrash = -1 nrIrq = 0 # peak # @@ -27675,6 +27685,52 @@ def getMaxPid(): except: pass + @staticmethod + def getNrCrash(): + try: + # custom # + customNrCrash = 0 + crashDirs = SysMgr.environList.get("CRASHDIR", []) + for path in crashDirs: + if not os.path.isdir(path): + continue + customNrCrash += len(UtilMgr.getFiles(path, recursive=False)) + + # android # + path = "/data/tombstones" + if os.path.isdir(path): + nrCrash = len( + UtilMgr.getFiles(path, name=["*.pb"], recursive=False) + ) + return nrCrash + customNrCrash + + # ccos # + path = "/ccos/data/log/trace" + if os.path.isdir(path): + nrCrash = len( + UtilMgr.getFiles( + path, recursive=False, exceptList=["*json"] + ) + ) + return nrCrash + customNrCrash + + # ubuntu # + path = "/var/crash" + if os.path.isdir(path): + nrCrash = len( + UtilMgr.getFiles(path, name=["*.crash"], recursive=False) + ) + return nrCrash + customNrCrash + + return customNrCrash + except SystemExit: + sys.exit(0) + except: + SysMgr.printWarn( + "failed to get the number of crash files", reason=True + ) + return customNrCrash + @staticmethod def waitForResource(cpuRes=-1, cpuCond="MORE", memRes=-1, memCond="MORE"): # check condition # @@ -29879,6 +29935,7 @@ def clearStats(): SysMgr.minMemAvail = SysMgr.maxSize SysMgr.nrOOMKill = 0 SysMgr.nrTotalOOMKill = -1 + SysMgr.nrTotalCrash = -1 SysMgr.maxNrUDPSock = 0 SysMgr.maxNrUDPTxQ = 0 SysMgr.maxNrUDPRxQ = 0 @@ -29902,10 +29959,6 @@ def getPeakList(incInter=True): "blkWrMB": SysMgr.maxBlkWr, "cpuPer": SysMgr.maxCpuUsage, "cpuStealPer": SysMgr.maxCpuSteal, - "procCpuPer": SysMgr.maxProcCpuUsage, - "procCpuComm": SysMgr.maxProcCpuComm, - "procMemMB": SysMgr.maxProcMemUsage, - "procMemComm": SysMgr.maxProcMemComm, "diskFreeMB": SysMgr.minDiskFree, "gpuPer": SysMgr.maxGpuUsage, "gpumemMB": SysMgr.maxGpuMemUsage, @@ -29916,12 +29969,17 @@ def getPeakList(incInter=True): "netOutMB": SysMgr.maxNetOut, "nrContextSwitch": SysMgr.maxNrContextSwitch, "nrCore": SysMgr.maxNrCore, + "nrCrash": SysMgr.nrTotalCrash, "nrFd": SysMgr.maxNrFd, "nrIrq": SysMgr.maxNrIrq, + "nrLoad15m": SysMgr.maxLoad15m, "nrLoad1m": SysMgr.maxLoad1m, "nrLoad5m": SysMgr.maxLoad5m, - "nrLoad15m": SysMgr.maxLoad15m, "nrOOMKill": SysMgr.nrTotalOOMKill, + "procCpuComm": SysMgr.maxProcCpuComm, + "procCpuPer": SysMgr.maxProcCpuUsage, + "procMemComm": SysMgr.maxProcMemComm, + "procMemMB": SysMgr.maxProcMemUsage, "nrProcess": SysMgr.maxNrProcess, "nrTaskAbnormal": SysMgr.maxNrTaskAbnormal, "nrTaskDie": SysMgr.maxNrTaskDie, @@ -30929,13 +30987,13 @@ def parseNewTombstone(buf): ) # get header # - idx = 1 + fidx = 0 lines = buf.split("\n")[1:] - for l in lines: + for idx, l in enumerate(lines): if not l or not l[0]: - idx += 1 continue elif l.startswith("backtrace:"): + fidx = idx break elif UtilMgr.isValidStr(l, kfilter): d = l.split(":", 1) @@ -30948,10 +31006,8 @@ def parseNewTombstone(buf): d = l.split(" ", 1) res[d[0].strip()] = d[1].strip() - idx += 1 - # get backtrace # - res = SysMgr.parseTombstoneLines(lines, res, idx, 5, 2) + res = SysMgr.parseTombstoneLines(lines, res, fidx, 5, 2) return res @@ -37095,6 +37151,9 @@ def printHelp(force=False, isExit=True): - {3:1} all {2:1} with memory(RSS) adding swap # {0:1} {1:1} -a -q SWAPMEMSUM + - {3:1} all {2:1} with crash count from crash directories + # {0:1} {1:1} -a -q CRASHDIR:/data/crash + - {3:1} all {2:1} with GPU memory # {0:1} {1:1} -a -q GPUMEM # {0:1} {1:1} -a -q GPUMEM, GPUALLMEM @@ -92914,7 +92973,7 @@ def _addTitle(title, titleLines): SysMgr.printWarn(new, newline=False) return title - def _loadSamples(fname): + def _loadSamples(fname, nrSamples, nrFiles): # get samples # samples, metas = getter(fname, verb=verb) @@ -92925,7 +92984,7 @@ def _loadSamples(fname): # check sample # if not samples or not samples[0]: SysMgr.printErr("no call sample for '%s'" % fname) - return + return nrSamples, nrFiles totalCnt = 0 for si, sampleList in enumerate(samples): @@ -93018,11 +93077,13 @@ def _loadSamples(fname): else: titleList[ts] = pathInfo + return nrSamples, nrFiles + # load call samples # for fname in inputList: # get list for call samples # try: - _loadSamples(fname) + nrSamples, nrFiles = _loadSamples(fname, nrSamples, nrFiles) except SystemExit: sys.exit(0) except: @@ -141155,6 +141216,17 @@ def printDefaultUsage(self, title): oomstr = " " oomKill = 0 + try: + SysMgr.nrTotalCrash = SysMgr.getNrCrash() + if SysMgr.nrTotalCrash: + crashstr = " [Crash: %d] " % SysMgr.nrTotalCrash + else: + crashstr = " " + except SystemExit: + sys.exit(0) + except: + crashstr = " " + try: self.nrContextSwitch = nrCtxt = ( self.cpuData["ctxt"]["ctxt"] - self.prevCpuData["ctxt"]["ctxt"] @@ -141230,7 +141302,7 @@ def printDefaultUsage(self, title): ( "%s [Time: %7.3f] [Inter: %.1f]%s [Ctxt: %d] " "[Life: +%d/-%d]%s[IRQ: %d]%s[Core: %d] [Task: %d/%d] " - "[Load: %s] [RAM: %s] [Swap: %s]%s\n" + "[Load: %s] [RAM: %s] [Swap: %s]%s%s\n" ) % ( title, @@ -141250,6 +141322,7 @@ def printDefaultUsage(self, title): memTotal, swapTotal, battery, + crashstr, ), "BOLD", )