Skip to content

Commit

Permalink
top: Add dynamic options
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <iipeace5@gmail.com>
  • Loading branch information
iipeace committed Sep 17, 2024
1 parent f0fc940 commit 7fb353a
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion 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__ = "240916"
__revision__ = "240917"
__maintainer__ = "Peace Lee"
__email__ = "iipeace5@gmail.com"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -27549,6 +27549,8 @@ class SysMgr(object):
overlayfsCache = {}
vmflagList = []
requestQueue = []
runtimeOption = []
uptimeOption = []

# threshold #
thrData = {}
Expand Down Expand Up @@ -38136,6 +38138,10 @@ def printHelp(force=False, isExit=True):
- {3:1} {2:1} and execute special commands
# {0:1} {1:1} -w AFTER:/tmp/touched:1, AFTER:ls

- {3:1} {2:1} and update options with specific conditions
# {0:1} {1:1} -q DYNUPTIMEOPT:1m:"-i 3 -a"
# {0:1} {1:1} -q DYNRUNTIMEOPT:2m:"-i 3 -a"

- {3:1} {2:1} through the local server having 5555 port
# {0:1} {1:1} -X 5555
# {0:1} {1:1} -X PRINT@5555
Expand Down Expand Up @@ -54120,6 +54126,7 @@ def _setLogger(options):
"limit the size of '%s' to [%s]"
% (path, convSize2Unit(size))
)

# get limited report dir info #
if "LIMITREPDIR" in SysMgr.environList:
try:
Expand Down Expand Up @@ -54176,6 +54183,7 @@ def _setLogger(options):
"limit the count of files in '%s' to [%s]"
% (path, convSize2Unit(cnt))
)

# register exit commands #
if "EXITCMD" in SysMgr.environList:
SysMgr.addExitFunc(
Expand All @@ -54187,6 +54195,26 @@ def _setLogger(options):
% ", ".join(SysMgr.environList["EXITCMD"])
)

# register dynamic option #
for name, env, optList in (
("runtime", "DYNRUNTIMEOPT", SysMgr.runtimeOption),
("uptime", "DYNUPTIMEOPT", SysMgr.uptimeOption),
):
for opt in SysMgr.environList.get(env, []):
items = opt.split(":", 1)
errStr = "failed to recognize dynamic %s option '%s'" % (
name,
opt,
)
if len(items) == 1:
SysMgr.printErr(errStr)
sys.exit(-1)
when, opt = items
when = UtilMgr.convUnit2Time(when)
if not when:
SysMgr.printErr(errStr)
optList.append([when, opt])

# ignore signals #
SysMgr.applyIgnoreSignals()

Expand Down Expand Up @@ -57126,6 +57154,26 @@ def updateUptime():
if SysMgr.dltTimeEnable:
SysMgr.dltTime = UtilMgr.getClockTime(dlt=True)

# check dynamic options #
for optList in ("uptimeOption", "runtimeOption"):
targetList = getattr(SysMgr, optList)
if not targetList:
continue

if optList == "uptimeOption":
stand = SysMgr.uptime
else:
stand = SysMgr.getRuntime(sec=True)

newList = []
for cond, opts in targetList:
if cond < stand:
SysMgr.printInfo("apply '%s' option" % opts)
SysMgr.parseAnalOption(opts)
else:
newList.append([cond, opts])
setattr(SysMgr, optList, newList)

return SysMgr.uptime

@staticmethod
Expand Down

0 comments on commit 7fb353a

Please sign in to comment.