-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kftop: Add sort option by average time
Signed-off-by: iipeace <[email protected]>
- Loading branch information
Showing
2 changed files
with
99 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
__credits__ = "Peace Lee" | ||
__license__ = "GPLv2" | ||
__version__ = "3.9.8" | ||
__revision__ = "231124" | ||
__revision__ = "231126" | ||
__maintainer__ = "Peace Lee" | ||
__email__ = "[email protected]" | ||
__repository__ = "https://github.com/iipeace/guider" | ||
|
@@ -26192,6 +26192,33 @@ def loadLibcObj(exit=False): | |
except: | ||
return False | ||
|
||
@staticmethod | ||
def getCpuUsageStr(obj, diff, color=True): | ||
# get CPU usage for me # | ||
if diff >= 1: | ||
cpuUsage = obj.getCpuUsage(system=True) | ||
else: | ||
cpuUsage = [0, 0, 0, 100] | ||
|
||
ttime = cpuUsage[0] / diff | ||
utime = cpuUsage[1] / diff | ||
stime = cpuUsage[2] / diff | ||
|
||
# get CPU usage for myself # | ||
mcpu = "%d%%" % ttime | ||
if color: | ||
mcpu = UtilMgr.convCpuColor(ttime, mcpu) | ||
mcpuStr = "%s(U%d%%+S%d%%)" % (mcpu, utime, stime) | ||
|
||
# get CPU usage for system # | ||
ctime = 100 - (cpuUsage[3] / diff) | ||
ctime = ctime if ctime > 0 else 0 | ||
sysCpuStr = "%d%%" % ctime | ||
if color: | ||
sysCpuStr = UtilMgr.convCpuColor(ctime, sysCpuStr) | ||
|
||
return mcpuStr, sysCpuStr | ||
|
||
@staticmethod | ||
def shrinkHeap(): | ||
if not SysMgr.isLinux: | ||
|
@@ -36372,6 +36399,7 @@ def _getDesc(s, t=0): | |
-m <ROWS:COLS:SYSTEM> set terminal size | ||
-a show all functions | ||
-g <FUNC> set function filter | ||
-c <CORE> set core filter | ||
-Q print all rows in a stream | ||
-q <NAME{:VALUE}> set environment variables | ||
-E <DIR> set cache dir path | ||
|
@@ -36386,9 +36414,16 @@ def _getDesc(s, t=0): | |
- {2:1} with function filter | ||
# {0:1} {1:1} -g "*write*, sched*" | ||
|
||
- {2:1} only for specific core | ||
# {0:1} {1:1} -c 0,1,2 | ||
|
||
- {2:1} with per-core classification | ||
# {0:1} {1:1} -q PERCORE | ||
|
||
- {2:1} after sorting | ||
# {0:1} {1:1} -q SORT:hit | ||
# {0:1} {1:1} -q SORT:total | ||
# {0:1} {1:1} -q SORT:average | ||
""".format( | ||
cmd, | ||
mode, | ||
|
@@ -59427,7 +59462,7 @@ def _applyFuncFilter(val=""): | |
# get sort attr # | ||
if "SORT" in SysMgr.environList: | ||
sortval = SysMgr.environList["SORT"][0].lower() | ||
if not sortval in ("hit", "total"): | ||
if not sortval in ("hit", "total", "average"): | ||
SysMgr.printErr("no sort value '%s'" % sortval) | ||
sys.exit(0) | ||
else: | ||
|
@@ -59466,6 +59501,11 @@ def _applyStats(node, path): | |
if not node in curCoreStat: | ||
curCoreStat[node] = {} | ||
|
||
perCoreStat = "PERCORE" in SysMgr.environList | ||
core = node.strip("function") | ||
if SysMgr.customCmd and not core in SysMgr.customCmd: | ||
return | ||
|
||
for l in statList[2:]: | ||
name, hit, total, _, avg, _, s2, _ = l.strip().split() | ||
if name == "schedule": | ||
|
@@ -59491,9 +59531,11 @@ def _applyStats(node, path): | |
if not prevCoreStat: | ||
continue | ||
|
||
tname = "[%s]%s" % (core, name) if perCoreStat else name | ||
|
||
# init total stats # | ||
if not name in totalStat: | ||
totalStat[name] = { | ||
if not tname in totalStat: | ||
totalStat[tname] = { | ||
"hit": 0, | ||
"total": 0, | ||
} | ||
|
@@ -59502,21 +59544,21 @@ def _applyStats(node, path): | |
try: | ||
# new func # | ||
if not name in prevCoreStat[node]: | ||
totalStat[name]["hit"] += hit | ||
totalStat[name]["total"] += total | ||
totalStat[tname]["hit"] += hit | ||
totalStat[tname]["total"] += total | ||
continue | ||
|
||
prevStat = prevCoreStat[node][name] | ||
curStat = curCoreStat[node][name] | ||
|
||
# no change # | ||
if curStat["hit"] == prevStat["hit"]: | ||
totalStat.pop(name, None) | ||
totalStat.pop(tname, None) | ||
continue | ||
|
||
# diff # | ||
totalStat[name]["hit"] += hit - prevStat["hit"] | ||
totalStat[name]["total"] += total - prevStat["total"] | ||
totalStat[tname]["hit"] += hit - prevStat["hit"] | ||
totalStat[tname]["total"] += total - prevStat["total"] | ||
except SystemExit: | ||
sys.exit(0) | ||
except: | ||
|
@@ -59529,31 +59571,17 @@ def _printStats(): | |
|
||
# get CPU usage # | ||
try: | ||
diff = SysMgr.uptimeDiff | ||
|
||
# get CPU usage for me # | ||
if diff >= 1: | ||
cpuUsage = TaskAnalyzer.dbgObj.getCpuUsage(system=True) | ||
else: | ||
cpuUsage = [0, 0, 0, 100] | ||
ttime = cpuUsage[0] / diff | ||
utime = cpuUsage[1] / diff | ||
stime = cpuUsage[2] / diff | ||
mcpu = "%d%%" % ttime | ||
mcpuStr = "%s(U%d%%+S%d%%)" % (mcpu, utime, stime) | ||
|
||
# get CPU usage for system # | ||
ctime = 100 - (cpuUsage[3] / diff) | ||
ctime = ctime if ctime > 0 else 0 | ||
sysCpuStr = "%d%%" % ctime | ||
|
||
# get available memory for system # | ||
sysMemStr = SysMgr.getAvailMemInfo() | ||
mcpuStr, sysCpuStr = SysMgr.getCpuUsageStr( | ||
TaskAnalyzer.dbgObj, SysMgr.uptimeDiff | ||
) | ||
except SystemExit: | ||
sys.exit(0) | ||
except: | ||
SysMgr.printErr("failed to get my CPU usage", True) | ||
mcpuStr = sysCpuStr = sysMemStr = "?" | ||
mcpuStr = sysCpuStr = "?" | ||
|
||
# get available memory for system # | ||
sysMemStr = SysMgr.getAvailMemInfo() | ||
|
||
# print header stats # | ||
SysMgr.addPrint( | ||
|
@@ -59592,13 +59620,22 @@ def _printStats(): | |
|
||
convNum = UtilMgr.convNum | ||
|
||
# get average time for each function # | ||
if sortval == "average": | ||
for n in totalStat: | ||
item = totalStat[n] | ||
item["average"] = item["total"] / item["hit"] | ||
|
||
# print stats # | ||
for name, vals in sorted( | ||
totalStat.items(), key=lambda e: e[1][sortval], reverse=True | ||
): | ||
hit = vals["hit"] | ||
total = vals["total"] | ||
avg = total / hit | ||
if "average" in vals: | ||
avg = vals["average"] | ||
else: | ||
avg = total / hit | ||
per = UtilMgr.convNum(long((total / maxTime) * 100)) | ||
|
||
ret = SysMgr.addPrint( | ||
|
@@ -77281,28 +77318,17 @@ def _checkRepeatCnt(): | |
|
||
if DbusMgr.dbgObj: | ||
# get CPU usage for myself # | ||
cpuUsage = DbusMgr.dbgObj.getCpuUsage(system=True) | ||
diff = SysMgr.uptimeDiff | ||
ttime = cpuUsage[0] / diff | ||
utime = cpuUsage[1] / diff | ||
stime = cpuUsage[2] / diff | ||
mcpu = "%d%%" % ttime | ||
mcpu = UtilMgr.convCpuColor(ttime, mcpu) | ||
mcpuStr = "%s(U%d%%+S%d%%)" % (mcpu, utime, stime) | ||
mcpuStr, sysCpuStr = SysMgr.getCpuUsageStr( | ||
DbusMgr.dbgObj, SysMgr.uptimeDiff | ||
) | ||
|
||
# get memory usage for myself # | ||
rssStr = DbusMgr.dbgObj.getMemUsage() | ||
|
||
# get CPU usage for system # | ||
ctime = 100 - (cpuUsage[3] / diff) | ||
ctime = ctime if ctime > 0 else 0 | ||
sysCpuStr = "%d%%" % ctime | ||
sysCpuStr = UtilMgr.convCpuColor(ctime, sysCpuStr) | ||
|
||
# get available memory for system # | ||
sysMemStr = SysMgr.getAvailMemInfo() | ||
else: | ||
mcpuStr = rssStr = sysCpuStr = sysMemStr = "?" | ||
mcpuStr = rssStr = sysCpuStr = "?" | ||
|
||
# get available memory for system # | ||
sysMemStr = SysMgr.getAvailMemInfo() | ||
|
||
# set error # | ||
nrErr = prevDbusData["totalErr"] | ||
|
@@ -78622,24 +78648,13 @@ def printIntervalSummary(force=False): | |
# update CPU usage # | ||
if DltAnalyzer.dbgObj: | ||
# get CPU usage for myself # | ||
cpuUsage = DltAnalyzer.dbgObj.getCpuUsage(system=True) | ||
diff = SysMgr.uptimeDiff | ||
ttime = cpuUsage[0] / diff | ||
utime = cpuUsage[1] / diff | ||
stime = cpuUsage[2] / diff | ||
mcpu = "%d%%" % ttime | ||
mcpu = UtilMgr.convCpuColor(ttime, mcpu) | ||
mcpuStr = "%s(U%d%%+S%d%%)" % (mcpu, utime, stime) | ||
mcpuStr, sysCpuStr = SysMgr.getCpuUsageStr( | ||
DltAnalyzer.dbgObj, SysMgr.uptimeDiff | ||
) | ||
|
||
# get memory usage for myself # | ||
rssStr = DltAnalyzer.dbgObj.getMemUsage() | ||
|
||
# get CPU usage for system # | ||
ctime = 100 - (cpuUsage[3] / diff) | ||
ctime = ctime if ctime > 0 else 0 | ||
sysCpuStr = "%d%%" % ctime | ||
sysCpuStr = UtilMgr.convCpuColor(ctime, sysCpuStr) | ||
|
||
# get available memory for system # | ||
sysMemStr = SysMgr.getAvailMemInfo() | ||
|
||
|
@@ -87213,15 +87228,15 @@ def _finishPrint(self, needStop=False, term=False, flush=True): | |
ttimeStr = UtilMgr.convCpuColor(ttime, "%d%%" % ttime) | ||
cpuStr = "%s(U%d%%+S%d%%)" % (ttimeStr, utime, stime) | ||
|
||
# get memory usage for target # | ||
rssStr = self.getMemUsage() | ||
|
||
# get CPU usage for system # | ||
ctime = 100 - (cpuUsage[3] / diff) | ||
ctime = ctime if ctime > 0 else 0 | ||
sysCpuStr = "%d%%" % ctime | ||
sysCpuStr = UtilMgr.convCpuColor(ctime, sysCpuStr) | ||
|
||
# get memory usage for target # | ||
rssStr = self.getMemUsage() | ||
|
||
# get available memory for system # | ||
sysMemStr = SysMgr.getAvailMemInfo() | ||
|
||
|
@@ -125732,20 +125747,9 @@ def printFileStat(self, filters): | |
diff = 0.01 | ||
|
||
# get CPU usage for myself # | ||
if diff >= 1: | ||
cpuUsage = TaskAnalyzer.dbgObj.getCpuUsage(system=True) | ||
else: | ||
cpuUsage = [0, 0, 0, 100] | ||
ttime = cpuUsage[0] / diff | ||
utime = cpuUsage[1] / diff | ||
stime = cpuUsage[2] / diff | ||
mcpu = "%d%%" % ttime | ||
mcpuStr = "%s(U%d%%+S%d%%)" % (mcpu, utime, stime) | ||
|
||
# get CPU usage for system # | ||
ctime = 100 - (cpuUsage[3] / diff) | ||
ctime = ctime if ctime > 0 else 0 | ||
sysCpuStr = "%d%%" % ctime | ||
mcpuStr, sysCpuStr = SysMgr.getCpuUsageStr( | ||
TaskAnalyzer.dbgObj, diff | ||
) | ||
|
||
# get available memory for system # | ||
sysMemStr = SysMgr.getAvailMemInfo() | ||
|
@@ -137495,14 +137499,19 @@ def checkThreshold( | |
td = SysMgr.thrData | ||
|
||
# get threshold attributes # | ||
comval = {} | ||
comval = [] | ||
if attr in td[resource]: | ||
comval = td[resource][attr] | ||
else: | ||
for val in td[resource]: | ||
if UtilMgr.isValidStr(attr, [val]): | ||
comval = td[resource][val] | ||
break | ||
if not UtilMgr.isValidStr(attr, [val]): | ||
continue | ||
if type(td[resource][val]) is list: | ||
comval += td[resource][val] | ||
else: | ||
comval.append(td[resource][val]) | ||
if not comval: | ||
return False | ||
|
||
# get previous usages # | ||
if intval: | ||
|
@@ -137606,7 +137615,7 @@ def _getTarget(addval, elist): | |
# check thresholds # | ||
if type(comval) is list: | ||
for comitem in comval: | ||
_checkThreshold(comitem) | ||
ret = _checkThreshold(comitem) | ||
else: | ||
_checkThreshold(comval) | ||
|
||
|