Skip to content

Commit

Permalink
sperf: Add TASKMON and PROCGROUP variables
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <[email protected]>
  • Loading branch information
iipeace committed Jul 17, 2024
1 parent 9f92a18 commit a77a58f
Showing 1 changed file with 56 additions and 16 deletions.
72 changes: 56 additions & 16 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__ = "240716"
__revision__ = "240717"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -25858,7 +25858,9 @@ def printAndLog(console=False):
datetime = SysMgr.getPkg("datetime")
epochStart = datetime.datetime(1900, 1, 1)
SysMgr.addEnvironVar("TIMEUNIT", "ms")
barLen = UtilMgr.getEnvironNum("BARLEN", False, 100, False, True)
barLen = UtilMgr.getEnvironNum(
"BARLEN", False, 100000, False, True
)

# set output path #
outFile = SysMgr.outPath if SysMgr.outPath else "guider"
Expand Down Expand Up @@ -25955,7 +25957,7 @@ def printAndLog(console=False):
start = (
datetime.datetime.strptime(items[1], "%H:%M:%S.%f")
- epochStart
).total_seconds() * 1000
).total_seconds() * 1000000
if startTime == 0:
startTime = start
start -= startTime
Expand Down Expand Up @@ -26032,7 +26034,6 @@ def printAndLog(console=False):
SysMgr.drawTimeline(
inputData=taskObj.timelineData,
outputPath=timelineOutput,
start=startTime,
)

# child #
Expand Down Expand Up @@ -41414,6 +41415,21 @@ def _getDesc(s, t=0):
- {2:1} and report to the specific output file with task filter
# {0:1} {1:1} -q TASKFILTER:"*task"

- {2:1} and report to the specific output file with process grouping
# {0:1} {1:1} -q PROCGROUP

- {2:1} with monitoring and report to the specific output file
# {0:1} {1:1} -q TASKMON
# {0:1} {1:1} -q TASKMON:3
# {0:1} {1:1} -q TASKMON -a
# {0:1} {1:1} -q TASKMON, TASKFILTER:"*a.out*"
# {0:1} {1:1} -q TASKMON, TASKFILTER:"*a.out*" -e t -P
# {0:1} {1:1} -q TASKMON, CHILDSCHED:c:0 -Y r:1
# {0:1} {1:1} -q TASKMON, EXECSCHED:c:0 -Y r:1

- {2:1} and report to the specific output file
# {0:1} {1:1} -q REPSCHED:i:0

- {2:1} and report to per-task output files
# {0:1} {1:1} -q EACHFILE

Expand Down Expand Up @@ -56512,6 +56528,12 @@ def doSimplePerfRec():
# backup an exist file #
SysMgr.backupFile(outPath)

# start monitoring #
if "TASKMON" in SysMgr.environList:
monPid = SysMgr.runTaskMonitor([""], wait=False)
else:
monPid = 0

# print record status #
SysMgr.printStat(r"start profiling... [ STOP(Ctrl+c) ]")
if SysMgr.warnEnable:
Expand All @@ -56521,9 +56543,15 @@ def doSimplePerfRec():
try:
SysMgr.executeCmdSync(cmd)
except:
recPid = set(SysMgr.getChildList()) - set([monPid])
if recPid:
recPid = recPid.pop()

SysMgr.repeatCnt = 0
SysMgr.killChildren(sig=signal.SIGINT)
SysMgr.waitChild()

if recPid:
SysMgr.waitChild(recPid)

# check record file #
if not os.path.exists(outPath):
Expand All @@ -56540,6 +56568,10 @@ def doSimplePerfRec():
# set default handler for force termination #
SysMgr.setDefaultSignal()

# apply report sched #
for cmd in SysMgr.environList.get("REPSCHED", []):
SysMgr.applyPriority("%s:%s" % (cmd, SysMgr.pid))

# print report status #
SysMgr.printStat(r"start reporting... [ STOP(Ctrl+c) ]")

Expand Down Expand Up @@ -56639,6 +56671,7 @@ def convSimplePerfSample(path, scripts=[]):
taskList = {}
totalTaskList = {}
taskObjList = {}
tgidList = {}
convNum = UtilMgr.convNum

# define _getSym #
Expand All @@ -56657,6 +56690,7 @@ def _getSym(call):
exceptKernel = "EXCEPTKERNEL" in SysMgr.environList
hasStackFilter = targetKernel or exceptKernel
taskFilter = SysMgr.environList.get("TASKFILTER", [])
procGroup = "PROCGROUP" in SysMgr.environList

# parse lines #
totalCnt = 0
Expand All @@ -56683,7 +56717,7 @@ def _getSym(call):
sample["backtrace"] = callchain

# check task object #
origTid = tid = sample.get("thread_id")
tid = sample.get("thread_id")
if not tid:
SysMgr.printErr(
"failed to get thread id info from a sample"
Expand All @@ -56695,8 +56729,17 @@ def _getSym(call):

continue

# group thread #
comm = None
if procGroup and tid != "0":
tgid = tgidList.get(tid, SysMgr.getTgid(tid))
if tgid and tgid != tid:
tid = tgidList[tid] = tgid
comm = SysMgr.getComm(tid, save=True)

# get task info #
comm = sample.get("thread_name")
if not comm:
comm = sample.get("thread_name")
current = float(sample.get("time", 0)) / 1000000000
totalTaskList[tid] = 0

Expand Down Expand Up @@ -57819,9 +57862,8 @@ def executeProcess(cmd=None, mute=False, closeFd=True):
)

# set priority #
if "EXECSCHED" in SysMgr.environList:
for cmd in SysMgr.environList["EXECSCHED"]:
SysMgr.applyPriority(cmd)
for cmd in SysMgr.environList.get("EXECSCHED", []):
SysMgr.applyPriority(cmd)

# exec #
try:
Expand Down Expand Up @@ -58399,9 +58441,8 @@ def createProcess(
SysMgr.childList[pid] = True

# set child priority #
if "CHILDSCHED" in SysMgr.environList:
for cmd in SysMgr.environList["CHILDSCHED"]:
SysMgr.applyPriority("%s:%s" % (cmd, pid))
for cmd in SysMgr.environList.get("CHILDSCHED", []):
SysMgr.applyPriority("%s:%s" % (cmd, pid))

return pid
# child #
Expand Down Expand Up @@ -70505,9 +70546,8 @@ def _exeCmd(cmd, seq=1, repeat=1):
# procObj.stdin.close()

# set priority #
if "EXECSCHED" in SysMgr.environList:
for cmd in SysMgr.environList["EXECSCHED"]:
SysMgr.applyPriority("%s:%s" % (cmd, procObj.pid))
for cmd in SysMgr.environList.get("EXECSCHED", []):
SysMgr.applyPriority("%s:%s" % (cmd, procObj.pid))

# wait for worker process #
try:
Expand Down

0 comments on commit a77a58f

Please sign in to comment.