Skip to content

Commit

Permalink
topdiff: Ignore invalid files and sort valid files
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <[email protected]>
  • Loading branch information
iipeace committed Sep 3, 2024
1 parent 47d8283 commit 25d1a81
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 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__ = "240902"
__revision__ = "240903"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -115829,6 +115829,7 @@ def _getProcName(pinfo):
# save all stats in a file #
validFlist.append(lfile)
statFileList[lfile] = gstats
idx = len(validFlist) - 1

# define proc usage #
cpuProcUsage = gstats["cpuProcUsage"]
Expand Down Expand Up @@ -115931,7 +115932,7 @@ def _getProcName(pinfo):
if idx > 0:
targetList = {}
prevIdx = 0 if fromStart else idx - 1
prevList = flist[prevIdx]
prevList = validFlist[prevIdx]
if not prevList in statFileList:
continue
prevProcList = statFileList[prevList]["cpuProcUsage"]
Expand All @@ -115950,7 +115951,7 @@ def _getProcName(pinfo):
pass

# set diff to the union list if this file is latest one #
if nrFiles == 1:
if len(validFlist) == 1:
cpuStats = statFileList[lfile]["cpuProcUsage"]
for pname in list(unionCpuList):
try:
Expand All @@ -115959,11 +115960,11 @@ def _getProcName(pinfo):
sys.exit(0)
except:
pass
elif idx == nrFiles - 1 and nrFiles > 1:
prevProcList = statFileList.get(flist[-2], {}).get(
else:
prevProcList = statFileList.get(validFlist[-2], {}).get(
"cpuProcUsage", {}
)
lastProcList = statFileList.get(flist[-1], {}).get(
lastProcList = statFileList.get(validFlist[-1], {}).get(
"cpuProcUsage", {}
)
for pname, value in unionCpuList.items():
Expand Down Expand Up @@ -116048,7 +116049,7 @@ def _getProcName(pinfo):
if idx > 0:
targetList = {}
prevIdx = 0 if fromStart else idx - 1
prevList = flist[prevIdx]
prevList = validFlist[prevIdx]
if not prevList in statFileList:
continue
prevProcList = statFileList[prevList]["gpuProcUsage"]
Expand All @@ -116067,7 +116068,7 @@ def _getProcName(pinfo):
pass

# set diff to the union list if this file is latest one #
if nrFiles == 1:
if len(validFlist) == 1:
gpuStats = statFileList[lfile]["gpuProcUsage"]
for pname in list(unionGpuList):
try:
Expand All @@ -116076,7 +116077,7 @@ def _getProcName(pinfo):
sys.exit(0)
except:
pass
elif idx == nrFiles and nrFiles > 1:
else:
unionGpuList[pname] = value["diff"]

# remove * characters #
Expand Down Expand Up @@ -116152,7 +116153,7 @@ def _getProcName(pinfo):
if idx > 0:
targetList = {}
prevIdx = 0 if fromStart else idx - 1
prevList = flist[prevIdx]
prevList = validFlist[prevIdx]
if not prevList in statFileList:
continue
prevProcList = statFileList[prevList]["memProcUsage"]
Expand All @@ -116176,7 +116177,7 @@ def _getProcName(pinfo):
continue

# set diff to the union list if this file is latest one #
if nrFiles == 1:
if len(validFlist) == 1:
memStats = statFileList[lfile]["memProcUsage"]
for pname in list(unionRssList):
try:
Expand All @@ -116185,11 +116186,11 @@ def _getProcName(pinfo):
sys.exit(0)
except:
pass
elif idx == nrFiles - 1 and nrFiles > 1:
prevProcList = statFileList.get(flist[-2], {}).get(
else:
prevProcList = statFileList.get(validFlist[-2], {}).get(
"memProcUsage", {}
)
lastProcList = statFileList.get(flist[-1], {}).get(
lastProcList = statFileList.get(validFlist[-1], {}).get(
"memProcUsage", {}
)
for pname, value in unionRssList.items():
Expand Down Expand Up @@ -116280,7 +116281,7 @@ def _getProcName(pinfo):
# save diff itself #
if idx > 0:
prevIdx = 0 if fromStart else idx - 1
prevSdList = statFileList[flist[prevIdx]].get(
prevSdList = statFileList[validFlist[prevIdx]].get(
"systemdInfo", {}
)
prevSdList = prevSdList.get("BOOT", {}).get(unit, {})
Expand All @@ -116297,7 +116298,7 @@ def _getProcName(pinfo):
stats["initDiff"] = stats["actDiff"]

# set diff to the union list if this file is latest one #
if nrFiles == 1:
if len(validFlist) == 1:
for uname in list(unionSdList):
try:
unionSdList[uname] = bootStat[uname][sortStd]
Expand All @@ -116316,7 +116317,7 @@ def _getProcName(pinfo):
sys.exit(0)
except:
pass
elif idx == nrFiles - 1:
else:
if prevSdList.get("activating"):
unionSdList[unit] = bootStat[unit][sortStd]
else:
Expand Down Expand Up @@ -116911,12 +116912,14 @@ def _printer(string):
continue

actDiff = (
("%5.1f" % float(sdList[pname])) if sdList[pname] else "-"
convNum(float(sdList[pname]), True, 1)
if sdList[pname]
else "-"
)
if pname in prevSdList:
initDiff = float(value) - float(prevSdList[pname])
if initDiff:
initDiffStr = "%5.1f" % round(initDiff, 2)
initDiffStr = convNum(initDiff, True, 1)
if initDiff > 0:
initDiff = convColor(initDiffStr, "RED")
elif initDiff < 0:
Expand Down Expand Up @@ -116984,7 +116987,7 @@ def _printer(string):
start = sdUnitStat["activating"]
if start:
if "startDiff" in sdUnitStat:
startDiff = "%5.1f" % round(sdUnitStat["startDiff"], 2)
startDiff = convNum(sdUnitStat["startDiff"], True, 1)
if sdUnitStat["startDiff"] > 0:
startDiff = convColor(startDiff, "RED")
elif sdUnitStat["startDiff"] < 0:
Expand All @@ -116996,7 +116999,7 @@ def _printer(string):
startDiff = "-"
actDiff = sdUnitStat["actDiff"]
if "initDiff" in sdUnitStat:
initDiff = "%5.1f" % round(sdUnitStat["initDiff"], 2)
initDiff = convNum(sdUnitStat["initDiff"], True, 1)
if sdUnitStat["initDiff"] > 0:
initDiff = convColor(initDiff, "RED")
elif sdUnitStat["initDiff"] < 0:
Expand All @@ -117006,10 +117009,10 @@ def _printer(string):
totalerr += abs(sdUnitStat["initDiff"])
else:
initDiff = "-"
diff = "%5.1f(%5s)/%5.1f(%5s) |" % (
start,
diff = "%5s(%5s)/%5s(%5s) |" % (
convNum(start, True, 1),
startDiff,
actDiff,
convNum(actDiff, True, 1),
initDiff,
)
else:
Expand Down Expand Up @@ -133405,7 +133408,7 @@ def _initData():
_printMenu(" Leak Hint ")
TaskAnalyzer.printLeakHint()

# print D-Bus info #
# print systemd info using D-Bus #
if "PRINTSYSTEMD" in SysMgr.environList:
origJsonEnable = SysMgr.jsonEnable
SysMgr.jsonEnable = True
Expand Down

0 comments on commit 25d1a81

Please sign in to comment.