diff --git a/guider/guider.py b/guider/guider.py index 4d5dfd5b..e8c2ddfd 100755 --- a/guider/guider.py +++ b/guider/guider.py @@ -7,7 +7,7 @@ __credits__ = "Peace Lee" __license__ = "GPLv2" __version__ = "3.9.8" -__revision__ = "240707" +__revision__ = "240709" __maintainer__ = "Peace Lee" __email__ = "iipeace5@gmail.com" __repository__ = "https://github.com/iipeace/guider" @@ -56303,7 +56303,7 @@ def doSimplePerfRec(): # print record file info # if SysMgr.warnEnable: SysMgr.printWarn( - "saved record file '%s%s'" + "saved the record file '%s%s'" % (outPath, UtilMgr.getFileSizeStr(outPath)) ) @@ -56342,23 +56342,25 @@ def doSimplePerfRec(): # save sample # if "SAVESAMPLE" in SysMgr.environList: - outPath += ".sample" + sampleOutPath = outPath + ".sample" try: # backup an exist file # - SysMgr.backupFile(outPath) + SysMgr.backupFile(sampleOutPath) - UtilMgr.gzip(outPath, "\n".join(ret).encode()) + UtilMgr.gzip(sampleOutPath, "\n".join(ret).encode()) SysMgr.printInfo( - "saved sample file '%s%s'" - % (outPath, UtilMgr.getFileSizeStr(outPath)) + "saved the sample file '%s%s'" + % ( + sampleOutPath, + UtilMgr.getFileSizeStr(sampleOutPath), + ) ) except SystemExit: sys.exit(0) except: SysMgr.printErr( - "failed to samples to '%s'" % outPath, True + "failed to samples to '%s'" % sampleOutPath, True ) - return # convert simpleperf report # SysMgr.convSimplePerfSample(fpath, ret) @@ -56390,7 +56392,9 @@ def convSimplePerfSample(path, scripts=[]): call = {} callchain = [] taskList = {} + totalTaskList = {} taskObjList = {} + convNum = UtilMgr.convNum # define _getSym # def _getSym(call): @@ -56423,6 +56427,7 @@ def _getSym(call): taskFilter = SysMgr.environList.get("TASKFILTER", []) # parse lines # + totalCnt = 0 totalSize = 0 totalLength = len(scripts) for idx, l in enumerate(scripts): @@ -56461,6 +56466,7 @@ def _getSym(call): # get task info # comm = sample.get("thread_name") current = float(sample.get("time", 0)) / 1000000000 + totalTaskList[tid] = 0 # check task filter # if ( @@ -56477,6 +56483,7 @@ def _getSym(call): # update task info # if tid in taskList: taskList[tid]["nrSample"] += 1 + taskList[tid]["comm"] = comm else: taskList[tid] = {"comm": comm, "nrSample": 1} @@ -56519,6 +56526,8 @@ def _getSym(call): ) taskObjList[tid].current = current + totalCnt += 1 + # init variables # sample = {} callchain = [] @@ -56576,25 +56585,50 @@ def _getSym(call): UtilMgr.deleteProgress() # check sample count # - nrSample = report.get("sample_count") + nrSample = long(report.get("sample_count", 0)) nrLost = long(report.get("lost_count", 0)) - lostStr = ( - (", losted %s samples" % UtilMgr.convNum(nrLost)) if nrLost else "" + lostStr = (", losted %s samples" % convNum(nrLost)) if nrLost else "" + filterStr = ( + ( + ", filtered %s samples from %s tasks" + % (convNum(totalCnt), convNum(len(taskList))) + ) + if nrSample != totalCnt + 1 + else "" ) if not nrSample or nrSample == "0": SysMgr.printErr("no sample collected%s" % lostStr) return else: - SysMgr.printInfo( - "collected %s(%s) samples%s" + sampleStatList = ( + "collected a total of %s(%s) samples%s from %s tasks%s" % ( - UtilMgr.convNum(long(nrSample)), + convNum(nrSample), UtilMgr.convSize2Unit(totalSize), lostStr, + convNum(len(totalTaskList)), + filterStr, ) ) + SysMgr.printInfo(sampleStatList) + SysMgr.addEnvironVar("SYSINFO", "SampleStat " + sampleStatList) + + # print task stats # + taskStatStr = ", ".join( + [ + "%s(%s): %s" % (v["comm"], tid, convNum(v["nrSample"])) + for tid, v in sorted( + taskList.items(), + key=lambda x: x[1]["nrSample"], + reverse=True, + ) + ] + ) + SysMgr.printInfo(taskStatStr) SysMgr.printStat(r"start converting... [ STOP(Ctrl+c) ]") + if taskStatStr: + SysMgr.addEnvironVar("SYSINFO", "TaskStat " + taskStatStr) # add environment variable to remove interval output # SysMgr.compressEnable = True @@ -76475,6 +76509,24 @@ def printSystemInfo(self): except: pass + # ADD # + for l in SysMgr.environList.get("SYSINFO", []): + try: + t, v = l.split(" ", 1) + v = UtilMgr.convLineStr( + v, + "", + indent, + indentRes, + startIndent=False, + ).lstrip() + + SysMgr.infoBufferPrint("{0:20} {1:<1}".format(t, v)) + except SystemExit: + sys.exit(0) + except: + pass + SysMgr.infoBufferPrint(twoLineLoc) def printCpuCacheInfo(self): @@ -92862,114 +92914,115 @@ def _addTitle(title, titleLines): SysMgr.printWarn(new, newline=False) return title - # load call samples # - for fname in inputList: - # get list for call samples # - try: - # get samples # - samples, metas = getter(fname, verb=verb) + def _loadSamples(fname): + # get samples # + samples, metas = getter(fname, verb=verb) - # convert sample dict to list # - if isinstance(samples, dict): - samples = [samples] + # convert sample dict to list # + if isinstance(samples, dict): + samples = [samples] - # check sample # - if not samples or not samples[0]: - SysMgr.printErr("no call sample for '%s'" % fname) - continue + # check sample # + if not samples or not samples[0]: + SysMgr.printErr("no call sample for '%s'" % fname) + return - totalCnt = 0 - for si, sampleList in enumerate(samples): - ts = "" - addFileInfo = "" - metainfo = metas[si] if isinstance(metas, list) else metas + totalCnt = 0 + for si, sampleList in enumerate(samples): + ts = "" + addFileInfo = "" + metainfo = metas[si] if isinstance(metas, list) else metas - # merge stats # - if isinstance(metainfo, dict): - procName = metainfo.get("process", "") - threadName = metainfo.get("thread", "") + # merge stats # + if isinstance(metainfo, dict): + procName = metainfo.get("process", "") + threadName = metainfo.get("thread", "") - if procName: - procList[procName] = procList.get(procName, 0) + 1 + if procName: + procList[procName] = procList.get(procName, 0) + 1 - if threadName: - taskName = "%s(%s)" % (threadName, procName) - threadList[threadName] = ( - threadList.get(threadName, 0) + 1 - ) - threadInfo = "%s(%s)-" % ( - threadName, - metainfo.get("tid"), - ) - else: - threadInfo = "" - taskName = procName + if threadName: + taskName = "%s(%s)" % (threadName, procName) + threadList[threadName] = ( + threadList.get(threadName, 0) + 1 + ) + threadInfo = "%s(%s)-" % ( + threadName, + metainfo.get("tid"), + ) + else: + threadInfo = "" + taskName = procName - if taskName: - taskList[taskName] = taskList.get(taskName, 0) + 1 + if taskName: + taskList[taskName] = taskList.get(taskName, 0) + 1 - ts = metainfo.get("time") + ts = metainfo.get("time") - addFileInfo = " (Task: %s%s(%s)) (Time: %s)" % ( - threadInfo, - procName, - metainfo.get("pid"), - ts, + addFileInfo = " (Task: %s%s(%s)) (Time: %s)" % ( + threadInfo, + procName, + metainfo.get("pid"), + ts, + ) + metainfo = None + # check task filter # + elif metainfo and filterGroup: + try: + item = metainfo.split("[")[5].rsplit(":")[0] + comm, tid = item.rsplit("(", 1) + except SystemExit: + sys.exit(0) + except: + SysMgr.printErr( + "failed to parse '%s'" % metainfo, True ) - metainfo = None - # check task filter # - elif metainfo and filterGroup: - try: - item = metainfo.split("[")[5].rsplit(":")[0] - comm, tid = item.rsplit("(", 1) - except SystemExit: - sys.exit(0) - except: - SysMgr.printErr( - "failed to parse '%s'" % metainfo, True - ) - continue + continue - # check filter # - if not tid[:-1] in filterGroup and not isValidStr( - comm - ): - continue + # check filter # + if not tid[:-1] in filterGroup and not isValidStr(comm): + continue - # add title info # - if metainfo: - _addTitleItem(metainfo, titleLines) + # add title info # + if metainfo: + _addTitleItem(metainfo, titleLines) - # merge samples # - for sample, cnt in sampleList.items(): - # check filter # - if includeList and not isValidStr(sample, includeList): - continue - elif excludeList and isValidStr(sample, excludeList): - continue + # merge samples # + for sample, cnt in sampleList.items(): + # check filter # + if includeList and not isValidStr(sample, includeList): + continue + elif excludeList and isValidStr(sample, excludeList): + continue - # increase counts # - if sample in callList: - callList[sample] += cnt - else: - callList[sample] = cnt - totalCnt += cnt - nrSamples += cnt - - # add path info # - if totalCnt: - nrFiles += 1 - if printFileList: - pathInfo = "[%s] (NrSample: %s) (Size: %s)%s" % ( - fname, - convNum(totalCnt), - UtilMgr.getFileSizeStr(fname).strip(" []"), - addFileInfo, - ) - if ts in titleList: - titleList[str(nrFiles)] = pathInfo - else: - titleList[ts] = pathInfo + # increase counts # + if sample in callList: + callList[sample] += cnt + else: + callList[sample] = cnt + totalCnt += cnt + nrSamples += cnt + + # add path info # + if totalCnt: + nrFiles += 1 + if printFileList: + pathInfo = "[%s] (NrSample: %s) (Size: %s)%s" % ( + fname, + convNum(totalCnt), + UtilMgr.getFileSizeStr(fname).strip(" []"), + addFileInfo, + ) + if ts in titleList: + titleList[str(nrFiles)] = pathInfo + else: + titleList[ts] = pathInfo + + # load call samples # + for fname in inputList: + # get list for call samples # + try: + _loadSamples(fname) except SystemExit: sys.exit(0) except: @@ -92980,13 +93033,29 @@ def _addTitle(title, titleLines): # set profinfo # if not profinfo and len(inputList) == 1: + prevName = "?" sysinfo = SysMgr.sysinfoBuffer.split("\n") for s in sysinfo: - if not s: - continue - t, v = s.split(" ", 1) - profinfo += "%s > %s\n" % (t, v) - profinfo += "\nAnalysis > # " + " ".join(sys.argv) + " -" + try: + if not s: + continue + + # add task info # + t, v = s.split(" ", 1) + if t: + prevName = t + elif prevName == "?": + continue + else: + t = prevName + profinfo += "%s > %s\n" % (t, v) + except SystemExit: + sys.exit(0) + except: + SysMgr.printWarn( + "failed to parse system info", reason=True + ) + profinfo += "\nAnalysis > # " + " ".join(sys.argv) + " -" # add path info # for t, v in sorted( @@ -93263,7 +93332,7 @@ def getCallStatsFile(logFile, verb=False): SysMgr.sysinfoBuffer = infoBuf infoBuf = None continue - elif line[0] in ("=", " "): + elif line in (oneLine, twoLine): continue else: if not line.endswith("\n"):