Skip to content

Commit

Permalink
All: Add USEREPFILENAME option
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <[email protected]>
  • Loading branch information
iipeace committed Dec 10, 2024
1 parent 0118941 commit 90eaf39
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 67 deletions.
58 changes: 44 additions & 14 deletions guider/guider.conf
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,25 @@
"COMMAND": {

"CMD_NOTIFY_WARN": "GUIDER cli upstream:notify:WARN",
"CMD_TOP": "GUIDER top -o OUTDIR/guider_top_EVTNAME_EVTTIME.out -R 10 -Y c:15",
"CMD_TOP": "GUIDER top -o OUTDIR/ -R 10 -Y c:15 -q USEREPFILENAME",
"CMD_FTOP": "GUIDER ftop -o OUTDIR/guider_top_EVTNAME_EVTTIME.out -a -R 1 -Y c:15",
"CMD_FTOP_PROC": "GUIDER ftop -o OUTDIR/guider_top_EVTNAME_EVTTIME.out -a -g EVTPID -R 1 -Y c:15",
"CMD_MTOP": "GUIDER mtop -o OUTDIR/guider_top_EVTNAME_EVTTIME.out -R 3 -Y c:15",
"CMD_FUNCREC": "GUIDER funcrec -s OUTDIR/guider_funcrec_EVTNAME_EVTTIME.dat -R 3",
"CMD_DISKTOP": "GUIDER disktop -R 3 -a -o OUTDIR/guider_block_EVTNAME_EVTTIME.out -Y c:15",
"CMD_DISKTOP_TOTAL": "GUIDER disktop -e T -R 3 -a -o OUTDIR/block_EVTNAME_EVTTIME.out -Y c:15",
"CMD_NETTOP": "GUIDER ntop -R 3 -o OUTDIR/guider_task_EVTNAME_EVTTIME.out -Y c:15",
"CMD_TTOP_PROC": "GUIDER ttop -g EVTPID -P -R 3 -o OUTDIR/guider_task_EVTNAME_EVTTIME.out -Y c:15",
"CMD_TTOP_CTX": "GUIDER ttop -S C:1 -R 2 -o OUTDIR/guider_task_EVTNAME_EVTTIME.out -Y c:15",
"CMD_TTOP_UTOP_ALL": "GUIDER ttop -g EVTPID -P -S c:1 -e E -R 1 -Q -c \"GUIDER utop -g PID -H -o OUTDIR/guider_utop_EVTNAME_EVTTIME_COMM_PID.out -R 5 -q LAZYCACHE\"",
"CMD_TTOP_UTOP_2": "GUIDER ttop -g EVTPID -P -S c:1 -e E -R 1 -Q -q NRTOPRANK:2 -c \"GUIDER utop -g PID -H -o OUTDIR/guider_utop_EVTNAME_EVTTIME_COMM_PID.out -R 5 -q LAZYCACHE\"",
"CMD_UTOP": "GUIDER utop -g EVTPID -H -o OUTDIR/guider_utop_EVTNAME_EVTTIME_COMM_PID.out -R 3",
"CMD_LEAK_1G": "GUIDER leaktrace -g EVTPID -T OUTDIR/libleaktracer.so -o OUTDIR/guider_leak_EVTNAME_EVTTIME.out -c 1g",
"CMD_LEAK_+200M": "GUIDER leaktrace -g EVTPID -T OUTDIR/libleaktracer.so -o OUTDIR/guider_leak_EVTNAME_EVTTIME.out -c +200m"
"CMD_MTOP": "GUIDER mtop -o OUTDIR/ -R 3 -Y c:15 -q USEREPFILENAME",
"CMD_FUNCREC": "GUIDER funcrec -s OUTDIR/ -R 3 -q USEREPFILENAME",
"CMD_DISKTOP": "GUIDER disktop -R 3 -a -o OUTDIR/ -Y c:15 -q USEREPFILENAME",
"CMD_DISKTOP_TOTAL": "GUIDER disktop -e T -R 3 -a -o OUTDIR/ -Y c:15 -q USEREPFILENAME",
"CMD_NETTOP": "GUIDER ntop -R 3 -o OUTDIR/ -Y c:15 -q USEREPFILENAME",
"CMD_TTOP_PROC": "GUIDER ttop -g EVTPID -P -R 3 -o OUTDIR/ -Y c:15 -q USEREPFILENAME",
"CMD_TTOP_CTX": "GUIDER ttop -S C:1 -R 2 -o OUTDIR/ -Y c:15 -q USEREPFILENAME",
"CMD_TTOP_UTOP_ALL": "GUIDER ttop -g EVTPID -P -S c:1 -e E -R 1 -Q -c \"GUIDER utop -g PID -H -o OUTDIR/ -R 5 -q LAZYCACHE, USEREPFILENAME\"",
"CMD_TTOP_UTOP_2": "GUIDER ttop -g EVTPID -P -S c:1 -e E -R 1 -Q -q NRTOPRANK:2 -c \"GUIDER utop -g PID -H -o OUTDIR/ -R 5 -q LAZYCACHE, USEREPFILENAME\"",
"CMD_UTOP": "GUIDER utop -g EVTPID -H -o OUTDIR/ -R 3 -q USEREPFILENAME",
"CMD_LEAK_1G": "GUIDER leaktrace -g EVTPID -T OUTDIR/libleaktracer.so -o OUTDIR/ -c 1g -q USEREPFILENAME",
"CMD_LEAK_+200M": "GUIDER leaktrace -g EVTPID -T OUTDIR/libleaktracer.so -o OUTDIR/ -c +200m -q USEREPFILENAME",
"CMD_SPERF": "GUIDER sperf -o OUTDIR -R 2 -q USEREPFILENAME",
"CMD_SPERF_PROC": "GUIDER sperf -g EVTPID -o OUTDIR -R 2 -q USEREPFILENAME",
"CMD_HPROF_PROC": "GUIDER sperf -g EVTPID -o OUTDIR -R 10 -q USEREPFILENAME",
"CMD_HPROF_PROC_+50M": "GUIDER sperf -g EVTPID -o OUTDIR -q STOPRSS:+50M, USEREPFILENAME"

},

Expand Down Expand Up @@ -368,7 +372,7 @@
"comp": "big",
"perm": "root",
"signal": "3:SIGINT",
"command": ["simpleperf record -g -o /data/perf.dat"],
"command": ["CMD_SPERF"],
"message": "system CPU usage is high",
"explain": "send SIGINT to the command process after 3 seconds"
},
Expand Down Expand Up @@ -413,6 +417,20 @@
"explain": "monitor CPU usage for all processes except for b.out"
},

{
"apply": "false",
"total": 95,
"interval": 3,
"comp": "big",
"oneshot": "true",
"refresh": 60,
"lock": "true",
"perm": "root",
"exceptOR": ["b.out"],
"command": ["CMD_SPERF_PROC"],
"explain": "monitor CPU usage for all processes except for b.out"
},

{
"apply": "false",
"pri": "R90",
Expand Down Expand Up @@ -523,6 +541,18 @@
"explain": "monitor RSS for all processes"
},

"*": {
"apply": "false",
"rss": 500,
"comp": "big",
"perm": "root",
"oneshot": "true",
"lock": "true",
"exceptOR": ["b.out"],
"command": ["CMD_HPROF_PROC"],
"explain": "monitor RSS for all processes"
},

"a.out*": {
"apply": "false",
"rss": 10,
Expand Down
142 changes: 89 additions & 53 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__ = "241209"
__revision__ = "241210"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand All @@ -32,13 +32,13 @@
err = sys.exc_info()[1]
sys.exit("[ERROR] failed to import essential package: %s" % err.args[0])

# handle backward compatibility between Python 2 and 3
# handle backward compatibility between python 2 and 3
try:
long # pylint: disable=used-before-assignment
except:
long = int

# python 2's xrange is equivalent to range in Python 3
# python 2's xrange is equivalent to range in python 3
try:
xrange # pylint: disable=used-before-assignment
except:
Expand Down Expand Up @@ -33216,19 +33216,17 @@ def updateBatInfo():
):
stats[sub] = "+"

capacity = stats["capacity"]
energy = stats["energy_now"]
power = stats["power_now"]

# check capacity #
if stats["capacity"] == 0:
if capacity == 0:
return

SysMgr.battery = (
stats["capacity"],
(
long(
stats["energy_now"] / float(stats["power_now"]) * 3600
)
if stats["power_now"]
else 0
),
capacity,
(long(energy / float(power) * 3600) if power else 0),
stats["status"],
)
except SystemExit:
Expand Down Expand Up @@ -37270,7 +37268,7 @@ def convMemStat(mlist):
@staticmethod
def getMemStatList(pid):
try:
mlist = SysMgr.getMemStat(SysMgr.pid)
mlist = SysMgr.getMemStat(pid)
return SysMgr.convMemStat(mlist)
except SystemExit:
sys.exit(0)
Expand Down Expand Up @@ -43288,6 +43286,9 @@ def _getDesc(s, t=0):
# {0:1} {1:1} -q DRAWFLAME, ALLOCCNT
# {0:1} {1:1} -q DRAWFLAME, ALLOCSIZE

- {2:1} using report file naming format
# {0:1} {1:1} -q USEREPFILENAME

- Report from perfetto data
# {0:1} {1:1} -I prof.data

Expand Down Expand Up @@ -43423,6 +43424,9 @@ def _getDesc(s, t=0):
- {2:1} and report the flame graph to a specific file
# {0:1} {1:1} -q DRAWFLAME

- {2:1} using report file naming format
# {0:1} {1:1} -q USEREPFILENAME

- Report from perf data
# {0:1} {1:1} -I perf.data

Expand Down Expand Up @@ -50812,19 +50816,12 @@ def _handleCmd(connObj, cmd, cliProc):
mainCmd = cmdList[0].lower()
cmdOpt = cmdList[1:] if len(cmdList) > 1 else []

# check save mode #
isSaveMode = mainCmd in ("save", "saveraw", "savemin")

# handle watch event #
if mainCmd == "watch":
SysMgr.printInfo("registered %s for event watch" % cliProc)
SysMgr.eventSubList.append([cliProc, connObj])
return

# backup items for worker task #
localServObj = SysMgr.localServObj
eventCommandList = SysMgr.eventCommandList

# check the maximum number of jobs #
nrMaxJob = UtilMgr.getEnvironNum("NRMAXJOB", False, 0, False)
if nrMaxJob:
Expand All @@ -50839,6 +50836,13 @@ def _handleCmd(connObj, cmd, cliProc):
)
return

# backup items before worker task creation #
localServObj = SysMgr.localServObj
eventCommandList = SysMgr.eventCommandList

# check save mode #
isSaveMode = mainCmd in ("save", "saveraw", "savemin")

# create a new worker process and parent return #
pid = SysMgr.createProcess()
if pid > 0:
Expand Down Expand Up @@ -50912,7 +50916,7 @@ def _monitorConn(connObj):
True,
)

# create a socket monitor task for disconnection #
# create a socket monitor task for handling disconnection #
threadObj = SysMgr.getPkg("threading")
tobj = threadObj.Thread(target=_monitorConn, args=[connObj])
tobj.daemon = True
Expand Down Expand Up @@ -54261,8 +54265,18 @@ def updateTimer(interval=None):
def makeOutPath(func):
if not SysMgr.outPath:
SysMgr.outPath = "."
SysMgr.updateOutPath()
SysMgr.outPath = SysMgr.inputFile

# use report file naming #
if "USEREPFILENAME" in SysMgr.environList and os.path.isdir(
SysMgr.outPath
):
SysMgr.updateNrRun(SysMgr.outPath)
cmd = sys.argv[1] if len(sys.argv) > 1 else None
SysMgr.setReportPath(SysMgr.outPath, sys.argv[1], "PROF")
else:
SysMgr.updateOutPath()
SysMgr.outPath = SysMgr.inputFile

if SysMgr.inputParam:
return SysMgr.inputParam
else:
Expand All @@ -54283,24 +54297,23 @@ def setReportPath(outPath, cmd, event="CUSTOM"):
for p in pathList[1:]:
SysMgr.addEnvironVar("DUPOUTPATH", p.strip())

isTargetDir = True

# fixed path #
if outPath:
isdir = os.path.isdir(outPath)
outPathStr = outPath.rstrip("(") + "/" if isdir else ""
outPathStr = outPath.rstrip("/") + "/" if isdir else ""
SysMgr.printInfo("set output path to '%s'" % outPathStr)

# dir #
if isdir:
targetDir = outPath
# file #
else:
isTargetDir = False
targetDir = "."
SysMgr.outPath = outPath
return
# no output #
elif not SysMgr.outPath:
SysMgr.printErr("no output path")
SysMgr.printErr("no output path for report")
return
# /tmp #
elif SysMgr.outPath == SysMgr.nullPath:
Expand All @@ -54313,15 +54326,14 @@ def setReportPath(outPath, cmd, event="CUSTOM"):
targetDir = os.path.dirname(SysMgr.outPath)

# set output path #
if isTargetDir:
SysMgr.outPath = "%s/guider_%08d_%08d_%s_%s_%s.out" % (
targetDir,
SysMgr.nrRun,
SysMgr.nrReport,
event,
cmd,
timeinfo,
)
SysMgr.outPath = "%s/guider_%08d_%08d_%s_%s_%s.out" % (
targetDir,
SysMgr.nrRun,
SysMgr.nrReport,
event,
cmd,
timeinfo,
)

@staticmethod
def updateOutPath():
Expand Down Expand Up @@ -56719,7 +56731,14 @@ def parseCommonOption(option, value):
)
sys.exit(-1)

SysMgr.origOutPath = SysMgr.outPath = os.path.normpath(value)
# use report file naming #
if "USEREPFILENAME" in SysMgr.environList and os.path.isdir(value):
SysMgr.updateNrRun(value)
cmd = sys.argv[1] if len(sys.argv) > 1 else None
SysMgr.setReportPath(value, sys.argv[1])
else:
SysMgr.outPath = os.path.normpath(value)
SysMgr.origOutPath = SysMgr.outPath

elif option == "s":
if not SysMgr.isKillMode():
Expand Down Expand Up @@ -59719,10 +59738,22 @@ def _waitThreshold(pids, cond, timing, target, sig=False):
sys.exit(-1)
pid = pids[0]

# convert threshold #
if cond.startswith("+"):
rss = SysMgr.getMemStatList(pid)["rss"]
cond = UtilMgr.convUnit2Size(cond[1:]) + rss
else:
cond = UtilMgr.convUnit2Size(cond)

# wait for threshold #
SysMgr.waitThreshold(
pid, rss=True, cond=cond, bt=True, purpose=timing
)
try:
SysMgr.waitThreshold(
pid, rss=True, cond=cond, bt=True, purpose=timing
)
except SystemExit:
sys.exit(0)
except:
SysMgr.printErr("canceled to wait for threshold", True)

# recover variables #
SysMgr.environList.pop("TARGETCMD")
Expand Down Expand Up @@ -60043,17 +60074,16 @@ def _waitThreshold(pids, cond, timing, target, sig=False):
startRss = SysMgr.environList.get("STARTRSS")
if startRss:
try:
startRss = UtilMgr.convUnit2Size(startRss[0])
_waitThreshold(pids, startRss[0], "START", target, True)
except SystemExit:
sys.exit(0)
except:
_printErr(
"failed to get RSS(%s) for start" % startRss[0], True
"failed to wait for RSS(%s) for start" % startRss[0],
True,
)
sys.exit(-1)

_waitThreshold(pids, startRss, "START", target, True)

# set timer #
try:
timer = SysMgr.getOption("R")
Expand Down Expand Up @@ -60135,17 +60165,16 @@ def _waitTask(pid):
stopRss = SysMgr.environList.get("STOPRSS")
if stopRss:
try:
stopRss = UtilMgr.convUnit2Size(stopRss[0])
_waitThreshold(pids, stopRss[0], "STOP", target)
except SystemExit:
sys.exit(0)
except:
_printErr(
"failed to get RSS(%s) for stop" % stopRss[0], True
"failed to wait for RSS(%s) for stop" % stopRss[0],
True,
)
sys.exit(-1)

_waitThreshold(pids, stopRss, "STOP", target)

# wait for events #
if javaTarget:
# wait for task termination #
Expand Down Expand Up @@ -60392,9 +60421,14 @@ def _waitThreshold(pids, cond, timing, sig=False):
pid = pids[0]

# wait for threshold #
SysMgr.waitThreshold(
pid, cpu=True, cond=cond, bt=True, purpose=timing
)
try:
SysMgr.waitThreshold(
pid, cpu=True, cond=cond, bt=True, purpose=timing
)
except SystemExit:
sys.exit(0)
except:
SysMgr.printErr("canceled to wait for threshold", True)

# set normal handler for profiling #
if sig:
Expand Down Expand Up @@ -156851,7 +156885,9 @@ def _checkResource(item):
# send events to watching tasks #
eventSubList = list(SysMgr.eventSubList)
SysMgr.eventSubList = []
pubInfo = UtilMgr.convDict2Str({ename: comval}, pretty=False).rstrip()
pubInfo = UtilMgr.convDict2Str({ename: comval}, pretty=False)
if pubInfo:
pubInfo = pubInfo.rstrip()
for winfo in eventSubList:
cliProc, netObj = winfo
ret = SysMgr.sendEvents(
Expand Down

0 comments on commit 90eaf39

Please sign in to comment.