Skip to content

Commit

Permalink
topdiff: Add SYS diff table
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <[email protected]>
  • Loading branch information
iipeace committed Oct 3, 2024
1 parent c063a0f commit 0263b58
Showing 1 changed file with 89 additions and 44 deletions.
133 changes: 89 additions & 44 deletions guider/guider.py
Original file line number Diff line number Diff line change
Expand Up @@ -116857,13 +116857,37 @@ def _getEnvNum(n, v):

@staticmethod
def doDiffReports(flist):
# define inner functions #
def _getProcName(pinfo):
merge = not "NOMERGE" in SysMgr.environList
if merge:
return pinfo.rsplit("(", 1)[0]
else:
return "-".join(pinfo.rstrip(")").rsplit("(", 1))

def _getter(func, var):
return [
func([i[0] for i in var]),
func([i[1] for i in var]),
]

def _updateStats(target, usage):
target.setdefault("cnt", 0)
target["cnt"] += 1
if usage and isinstance(usage[0], list):
target["minimum"] = _getter(min, usage)
target["maximum"] = _getter(max, usage)
target["total"] = _getter(sum, usage)
target["average"] = [
target["total"][0] / float(len(usage)),
target["total"][1] / float(len(usage)),
]
else:
target["minimum"] = min(usage)
target["maximum"] = max(usage)
target["total"] = sum(usage)
target["average"] = target["total"] / float(len(usage))

# enable RSS flag #
SysMgr.rssEnable = True

Expand All @@ -116882,6 +116906,7 @@ def _getProcName(pinfo):
unionGpuList = {}
unionRssList = {}
unionBlkList = {}
unionSysList = {}
unionSdList = {}
unionSdBootList = {}
statFileList = {}
Expand Down Expand Up @@ -116936,20 +116961,46 @@ def _getProcName(pinfo):
statFileList[lfile] = gstats
idx = len(validFlist) - 1

# define proc usage #
# define task usage list #
cpuProcUsage = gstats.get("cpuProcUsage", {})
memProcUsage = gstats.get("memProcUsage", {})
gpuProcUsage = gstats.get("gpuUsage", {})
blkProcUsage = gstats.get("blkProcUsage", {})
# TODO: add system stats #
swapUsage = gstats["swapUsage"]
reclaimBg = gstats["reclaimBg"]
reclaimDr = gstats["reclaimDr"]
nrCore = gstats["nrCore"]
netReadUsage = gstats["netRead"]
netWriteUsage = gstats["netWrite"]
psiUsage = gstats["psiUsage"]
nrTask = gstats["nrTask"]
sysUsage = {}

# make system usage list #
for r in (
"netRead",
"netWrite",
"nrCore",
"nrTask",
"psiUsage",
"reclaimBg",
"reclaimDr",
"swapUsage",
):
stats = gstats.get(r, [])
if not stats:
continue
elif r in ("psiUsage"):
# TODO: handle PSI usage #
continue
elif r in ("nrTask"):
subStats = [list(map(long, x.split("/"))) for x in stats]
subStats = _getter(lambda x: x, subStats)
itemList = (
("nrProcess", subStats[0]),
("nrThread", subStats[1]),
)
else:
itemList = ((r, stats),)

# get stats #
for r, stats in itemList:
sysUsage.setdefault(r, {})
_updateStats(sysUsage[r], stats)
sysUsage[r]["usage"] = stats
gstats["sysUsage"] = sysUsage

# define systemd list #
sdUnitList = gstats.get("systemdInfo", {})
Expand Down Expand Up @@ -116983,34 +117034,12 @@ def _getProcName(pinfo):
"maxRss": max(memFree),
}

def _getter(func, var):
return [
func([i[0] for i in var]),
func([i[1] for i in var]),
]

def _updateStats(target, usage):
target.setdefault("cnt", 0)
target["cnt"] += 1
if usage and isinstance(usage[0], list):
target["minimum"] = _getter(min, usage)
target["maximum"] = _getter(max, usage)
target["total"] = _getter(sum, usage)
target["average"] = [
target["total"][0] / float(len(usage)),
target["total"][1] / float(len(usage)),
]
else:
target["minimum"] = min(usage)
target["maximum"] = max(usage)
target["total"] = sum(usage)
target["average"] = target["total"] / float(len(usage))

# -------------------- CPU/GPU/BLK -------------------- #
# -------------------- CPU/GPU/BLK/SYS -------------------- #
for res, procUsage, unionList in (
("cpuProcUsage", cpuProcUsage, unionCpuList),
("gpuUsage", gpuProcUsage, unionGpuList),
("blkProcUsage", blkProcUsage, unionBlkList),
("sysUsage", sysUsage, unionSysList),
):
# remove * characters #
for pinfo in sorted(procUsage):
Expand Down Expand Up @@ -117466,7 +117495,7 @@ def _getFileMenu(printBuf, menuBuf, menuStat, lenStat):
)
return printBuf, menuBuf

# -------------------- CPU/GPU -------------------- #
# -------------------- CPU/GPU/SYS -------------------- #

emptyCpuStat = "%7s(%2s)(%5s/%7s/%5s/%6s) |" % (
"-",
Expand All @@ -117486,9 +117515,10 @@ def _getFileMenu(printBuf, menuBuf, menuStat, lenStat):
)
lenCpuStat = len(emptyCpuStat)

for res, resName, unionList, defTask, leng in (
("cpu", "cpuProcUsage", unionCpuList, 2, 16),
("gpu", "gpuUsage", unionGpuList, 1, 24),
for res, resName, unionList, defTask, leng, unit in (
("cpu", "cpuProcUsage", unionCpuList, 2, 16, "%"),
("gpu", "gpuUsage", unionGpuList, 1, 24, "%"),
("sys", "sysUsage", unionSysList, 1, 10, ""),
):
# print file names #
totalBuf = ""
Expand All @@ -117503,6 +117533,12 @@ def _getFileMenu(printBuf, menuBuf, menuStat, lenStat):
lineLen = len(menuBuf)
oneLineStr = "-" * lineLen
twoLineStr = "=" * lineLen
if unit:
newStatStr = "%7s(%2d)(%4s%s/%6.1f%s/%4s%s/%5s%s) |"
diffStr = "{0:>6}{1:1}"
else:
newStatStr = "%7s(%2d)(%5s%s/%7.1f%s/%5s%s/%6s%s) |"
diffStr = "{0:>7}{1:0}"
jsonData[res] = {}

# print diff #
Expand Down Expand Up @@ -117559,7 +117595,10 @@ def _getFileMenu(printBuf, menuBuf, menuStat, lenStat):
# no target process in this file #
if not pname in procList:
if idx > 0 and pname in prevProcList:
diff = "%6.1f%%" % -(prevProcList[pname][item])
diff = "%6.1f%s" % (
-(prevProcList[pname][item]),
unit,
)
diff = convColor(diff, "WARNING", 6)
printBuf = "%s %6s%s" % (
printBuf,
Expand All @@ -117576,15 +117615,17 @@ def _getFileMenu(printBuf, menuBuf, menuStat, lenStat):
if not "diff" in procStat:
diff = "-"
elif procStat["diff"] > 0:
diff = "{0:>6}%".format(
"+%s" % convNum(procStat["diff"], isFloat=True)
diff = diffStr.format(
"+%s" % convNum(procStat["diff"], isFloat=True),
unit,
)
diff = convColor(diff, "RED", 6)
totalerr += procStat["diff"]
elif procStat["diff"] < 0:
diff = "{0:>6}%".format(
diff = diffStr.format(
"-%s"
% convNum(abs(procStat["diff"]), isFloat=True)
% convNum(abs(procStat["diff"]), isFloat=True),
unit,
)
diff = convColor(diff, "GREEN", 6)
totalerr += abs(procStat["diff"])
Expand All @@ -117602,13 +117643,17 @@ def _getFileMenu(printBuf, menuBuf, menuStat, lenStat):
"max": procStat["maximum"],
}

newStat = "%7s(%2d)(%4s%%/%6.1f%%/%4s%%/%5s%%) |" % (
newStat = newStatStr % (
diff,
procStat["cnt"],
procStat["minimum"],
unit,
procStat["average"],
unit,
procStat["maximum"],
unit,
total,
unit,
)

printBuf = "%s %s" % (printBuf, newStat)
Expand Down

0 comments on commit 0263b58

Please sign in to comment.