Skip to content

Commit

Permalink
topsum: Add core summary
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <[email protected]>
  • Loading branch information
iipeace committed Sep 21, 2024
1 parent ba7e392 commit ab4082c
Showing 1 changed file with 102 additions and 6 deletions.
108 changes: 102 additions & 6 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__ = "240920"
__revision__ = "240921"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -38278,6 +38278,9 @@ def printHelp(force=False, isExit=True):
# {0:1} {1:1} -o .
# {0:1} {1:1} -o . -q NOBACKUP

- {3:1} {2:1} and {5:1} {4:1} with core summary
# {0:1} {1:1} -o . -e c -q CORESUMMARY

- {3:1} {2:1} and {5:1} {4:1} with memory details of top 10 processes
# {0:1} {1:1} -o . -q NRPROCMEM:10

Expand Down Expand Up @@ -43100,6 +43103,9 @@ def _getDesc(s, t=0):
# {0:1} {1:1} output.out -g "a.out*"
# {0:1} {1:1} "output*.out" -g "*a.out*"

- {2:1} with core summary
# {0:1} {1:1} "report1.out, report2.out.gz" -q CORESUMMARY

- {2:1} with kernel memory
# {0:1} {1:1} "report1.out, report2.out.gz" -q INCKERNELMEM

Expand Down Expand Up @@ -132247,10 +132253,7 @@ def parseProcLine(index, procLine):
procIntData["total"] = dict(TA.init_procIntData)

# save CPU usage on this interval #
try:
procIntData["total"]["cpu"] = cpu
except:
procIntData["total"]["cpu"] = 0
procIntData["total"]["cpu"] = cpu

# save blkwait on this interval #
try:
Expand Down Expand Up @@ -132599,8 +132602,30 @@ def parseProcLine(index, procLine):

return

# core #
elif len(tokens) == 6 and tokens[0].startswith("Core/"):
m = re.findall(
r"Core/\s*(?P<core>\d+)\|\s*(?P<usage>\d+)\s*%", procLine
)
if not m:
return

TA.procTotData["total"].setdefault("core", {})
procIntData["total"].setdefault("core", {})

for l in m:
core, usage = l[0], long(l[1])

# sum core usage #
TA.procTotData["total"]["core"][core] = (
TA.procTotData["total"]["core"].get("core", 0) + usage
)

# save core usage on this interval #
procIntData["total"]["core"][core] = usage

# WARN: each tab's the number of tokens #
# task(10), GPU(5), storage(12), network(13), cgroup(10)
# task(10), GPU(5), storage(12), network(13), cgroup(10), core(6)

# check return condition #
if "ONLYTOTAL" in SysMgr.environList:
Expand Down Expand Up @@ -133223,6 +133248,76 @@ def printEventInterval():

_printer("%s\n" % oneLine)

@staticmethod
def printCoreInterval():
# check skip flag #
if not "CORESUMMARY" in SysMgr.environList:
return
elif not "core" in TaskAnalyzer.procTotData["total"]:
return

if SysMgr.jsonEnable:
_printer = lambda x: x
else:
_printer = SysMgr.printPipe

TA = TaskAnalyzer

# set comm and pid size #
_printer("\n[Top Core Info] (Unit: %%)\n%s\n" % twoLine)

# Print menu #
procInfo = "{0:>4} | {1:>4} |".format("Core", "Avg")
procInfoLen = len(procInfo)
maxLineLen = SysMgr.lineLength
margin = 2

# Print timeline #
TA.printTimelineInterval(margin, procInfoLen, procInfo, 1)

# Print usage of cores #
nrPrint = 0
for core, usage in sorted(
TA.procTotData["total"]["core"].items(), key=lambda e: long(e[0])
):
procInfo = "{0:>4} | {1:>4} |".format(
core, long(usage / len(TA.procIntData))
)

timeLine = ""
lineLen = len(procInfo)
total = 0
for idx in xrange(len(TA.procIntData)):
if lineLen + margin > maxLineLen:
timeLine += "\n" + (" " * (procInfoLen - 1)) + "| "
lineLen = len(procInfo)

if core in TA.procIntData[idx]["total"]["core"]:
try:
usage = TA.procIntData[idx]["total"]["core"][core]
except SystemExit:
sys.exit(0)
except:
usage = 0
total += usage
else:
usage = 0

timeLine += "{0:>3} ".format(str(usage))
lineLen += margin + 2

# skip process used no value #
if total == 0:
continue

_printer(
("{0:1} {1:1}\n{2:1}\n").format(procInfo, timeLine, oneLine)
)
nrPrint += 1

if nrPrint == 0:
_printer(" None\n%s" % oneLine)

@staticmethod
def printCpuInterval(attr="cpu"):
def _conv(val):
Expand Down Expand Up @@ -134894,6 +134989,7 @@ def _initData():
if not onlyTotal:
TaskAnalyzer.printEventInterval()
TaskAnalyzer.printCpuInterval()
TaskAnalyzer.printCoreInterval()
TaskAnalyzer.printDlyInterval()
TaskAnalyzer.printPrioInterval()
TaskAnalyzer.printGpuInterval()
Expand Down

0 comments on commit ab4082c

Please sign in to comment.