-
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.
top: Reduce CPU usage for printing cgroup stat
Signed-off-by: iipeace <[email protected]>
- Loading branch information
Showing
1 changed file
with
41 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
__credits__ = "Peace Lee" | ||
__license__ = "GPLv2" | ||
__version__ = "3.9.8" | ||
__revision__ = "230920" | ||
__revision__ = "230921" | ||
__maintainer__ = "Peace Lee" | ||
__email__ = "[email protected]" | ||
__repository__ = "https://github.com/iipeace/guider" | ||
|
@@ -873,6 +873,7 @@ class ConfigMgr(object): | |
RESSET = ( | ||
"SAVECPU", | ||
"SAVEMEM", | ||
"SAVEMEMPROC", | ||
"SAVEBLOCK", | ||
"SAVEPID", | ||
"SAVERUNTIME", | ||
|
@@ -33969,7 +33970,7 @@ def printHelp(force=False, isExit=True): | |
# {0:1} {1:1} -q PRINTCG:"cpu+cpuacct+memory+blkio" | ||
# {0:1} {1:1} -q PRINTCG:"all" | ||
# {0:1} {1:1} -q PRINTCG, MAXCGROWS:5 | ||
# {0:1} {1:1} -q PRINTCG, NOPRESSURE | ||
# {0:1} {1:1} -q PRINTCG, NOPRESSURE, SKIPNOTASK | ||
|
||
- {3:1} {2:1} with cgroup usage only for specific groups | ||
# {0:1} {1:1} -q PRINTCG, CGFILTER:"*user.slice" | ||
|
@@ -35909,6 +35910,9 @@ def printHelp(force=False, isExit=True): | |
- {2:1} except for pressure info | ||
# {0:1} {1:1} -q NOPRESSURE | ||
|
||
- {2:1} except for no task group | ||
# {0:1} {1:1} -q SKIPNOTASK | ||
|
||
- {2:1} after mounting all cgroup subsystems | ||
# {0:1} {1:1} -q MOUNTCG | ||
|
||
|
@@ -39344,8 +39348,8 @@ def printHelp(force=False, isExit=True): | |
- {2:1} with tasks | ||
# {0:1} {1:1} -a | ||
|
||
- {2:1} with only effective groups | ||
# {0:1} {1:1} -q ONLYEFFECT | ||
- {2:1} except for no task group | ||
# {0:1} {1:1} -q SKIPNOTASK | ||
|
||
- {2:1} with tasks only for specific type | ||
# {0:1} {1:1} -a -q ONLYPROC | ||
|
@@ -45662,7 +45666,7 @@ def freeDirsCnt(add=1): | |
# get file size # | ||
size = UtilMgr.getFileSize(fpath, False) | ||
|
||
msg = "'%s' [%s] to keep file count '%s' for '%s' [%s]" % ( | ||
msg = "'%s' [%s] to keep file count (%s) for '%s' [%s]" % ( | ||
fpath, | ||
convSize(size), | ||
limitCnt, | ||
|
@@ -65959,7 +65963,13 @@ def doDecompress(args=[], ffilter=[], verb=True): | |
|
||
# check exist file # | ||
if os.path.exists(outfile): | ||
SysMgr.backupFile(outfile) | ||
# backup file # | ||
newFile = SysMgr.backupFile(outfile) | ||
|
||
# replace input file # | ||
if os.path.realpath(outfile) == item: | ||
item = newFile | ||
|
||
newline = False | ||
else: | ||
newline = True | ||
|
@@ -72015,6 +72025,8 @@ def _updateValues(dirpath, subfiles, item): | |
|
||
def _getPaths(root, path): | ||
for dirpath, subdirs, subfiles in path: | ||
UtilMgr.printProgress() | ||
|
||
# update subdir # | ||
for item in subdirs: | ||
subdir = os.path.join(dirpath, item) | ||
|
@@ -72091,6 +72103,8 @@ def printCgroupInfo(self, printTitle=True, progress=False, cmd=False): | |
|
||
# get cgroup list # | ||
try: | ||
SysMgr.printInfo("start collecting cgroups...") | ||
|
||
cgroupTree = self.getCgroupTree() | ||
if not cgroupTree: | ||
return | ||
|
@@ -72177,7 +72191,7 @@ def _printDirTree(root, depth, totals={}, parent="", res=""): | |
|
||
# get options # | ||
repComm = "REPCOMM" in SysMgr.environList | ||
onlyEffect = "ONLYEFFECT" in SysMgr.environList | ||
skipNoTask = "SKIPNOTASK" in SysMgr.environList | ||
|
||
# sum values for subdirs # | ||
newTotals = {} | ||
|
@@ -72793,7 +72807,7 @@ def _getIoStat(pid, task): | |
# leap node # | ||
else: | ||
if ( | ||
onlyEffect | ||
skipNoTask | ||
and nrProcs in ("0", 0) | ||
and nrTasks in ("0", 0) | ||
and not tempSubdir | ||
|
@@ -103564,7 +103578,7 @@ def _addEntryOldState(cmd, args, isExtended=False): | |
# decompress gnu_debugdata section # | ||
try: | ||
if ( | ||
e_shdbgdata >= 0 | ||
e_shdbgdata < 0 | ||
or not ".gnu_debugdata" in self.attr["sectionHeader"] | ||
): | ||
raise ValueError("no .gnu_debugdata") | ||
|
@@ -125560,11 +125574,24 @@ def _getStats(root, path, sub, dftDepth, isVer2): | |
# register subsystem # | ||
root.setdefault(sub, {}) | ||
|
||
# check skip condition # | ||
skipNoTask = "SKIPNOTASK" in SysMgr.environList | ||
|
||
for dirpath, subdirs, subfiles in path: | ||
# check depth # | ||
if SysMgr.funcDepth > 0: | ||
depth = dirpath.count("/") - dftDepth | ||
if depth >= SysMgr.funcDepth: | ||
del subdirs[:] | ||
continue | ||
|
||
# check no task group # | ||
if skipNoTask and "tasks" in subfiles: | ||
taskfile = os.path.join(dirpath, "tasks") | ||
fd = SysMgr.getFd(taskfile, "r") | ||
fd.seek(0) | ||
stat = fd.read() | ||
if not stat: | ||
continue | ||
|
||
# update subfiles # | ||
|
@@ -133874,7 +133901,7 @@ def handleEventCmd(self, cmd, source, user): | |
name = "USER" if user else source | ||
|
||
# set command name # | ||
ocmd = cmd.split(":", 1)[0] | ||
ocmd = cmd.split(":", 1)[0].split("#", 1)[0] | ||
|
||
# SAVE # | ||
if ocmd in ("SAVE", "SAVERAW", "SAVEMIN") or ocmd in ConfigMgr.RESSET: | ||
|
@@ -134673,8 +134700,11 @@ def handleSaveCmd(self, cmd, event, form=None): | |
if form == "SAVECPU": | ||
SysMgr.totalEnable = True | ||
SysMgr.sort = "c" | ||
elif form == "SAVEMEM": | ||
elif form in ("SAVEMEM", "SAVEMEMPROC"): | ||
SysMgr.memEnable = True | ||
SysMgr.sort = "m" | ||
if form == "SAVEMEM": | ||
SysMgr.addEnvironVar("NOSMAPS") | ||
elif form == "SAVEBLOCK": | ||
SysMgr.sort = "b" | ||
elif form == "SAVEPID": | ||
|