Skip to content

Commit

Permalink
sperf: Add ADDCOMMCALL option
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <[email protected]>
  • Loading branch information
iipeace committed Dec 6, 2024
1 parent 0860926 commit 39c530d
Showing 1 changed file with 62 additions and 28 deletions.
90 changes: 62 additions & 28 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__ = "241205"
__revision__ = "241206"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -30576,6 +30576,8 @@ def execTopCmd():
# set handler for exit #
SysMgr.setNormalSignal()

# -------------------- execute command -------------------- #

# thread #
if SysMgr.checkMode("ttop"):
SysMgr.processEnable = False
Expand Down Expand Up @@ -30816,7 +30818,7 @@ def execTopCmd():
SysMgr.dltTopEnable = True
SysMgr.dltTimeEnable = True

# ANDTOP #
# logcat #
elif SysMgr.checkMode("andtop"):
SysMgr.andTopEnable = True

Expand Down Expand Up @@ -30847,12 +30849,12 @@ def execTopCmd():

# kernelcall #
elif SysMgr.checkMode("ktop"):
SysMgr.doTrace("kernel")

# kernelfunctioncall #
elif SysMgr.checkMode("kftop"):
SysMgr.runKernelTop()

# kernel stack #
elif SysMgr.checkMode("kstop"):
SysMgr.doTrace("kernel")

# network #
elif SysMgr.checkMode("ntop"):
SysMgr.networkEnable = True
Expand Down Expand Up @@ -38391,7 +38393,7 @@ def getCmdList():
"fetop": ("File", "Linux/Android"),
"ftop": ("File", "Linux/Android/MacOS"),
"irqtop": ("IRQ", "Linux/Android"),
"kftop": ("Function", "Linux/Android"),
"kstop": ("Stack", "Linux/Android"),
"ktop": ("Function", "Linux/Android"),
"mdtop": ("Memory", "Android"),
"mtop": ("Memory", "Linux/Android"),
Expand Down Expand Up @@ -40869,6 +40871,7 @@ def _getDesc(s, t=0):

- {2:1} including specific kernel functions of all threads to guider.dat
# {0:1} {1:1} -s . -d c -K "evt1:func*"
# {0:1} {1:1} -s . -d c -K "evt1:func*" -q "INCDOTSYM"
# {0:1} {1:1} -s . -d c -K "evt1:func1:u32, evt2:0x1234:s16, evt3:func2:x16"
# {0:1} {1:1} -s . -d c -K "open:do_sys_open:dfd=%ax filename=%bx;u64 flags=%cx;s32 mode=+4(\$stack):NONE"
# {0:1} {1:1} -s . -d c -K "strace32:func1:%bp/u32.%sp/s64, strace:0x1234:\$stack:NONE"
Expand Down Expand Up @@ -41148,8 +41151,8 @@ def _getDesc(s, t=0):
+ examStr
)

# kernel function top #
elif SysMgr.checkMode("kftop"):
# kernel call top #
elif SysMgr.checkMode("ktop"):
desc = "Monitor kernel function calls"
helpStr = _getDesc(desc, t=1)

Expand Down Expand Up @@ -41191,9 +41194,9 @@ def _getDesc(s, t=0):
)

# kernel top #
elif SysMgr.checkMode("ktop"):
elif SysMgr.checkMode("kstop"):
helpStr = _getDesc(
"Monitor kernel function calls for specific threads",
"Monitor kernel stacks for specific threads",
t=1,
)

Expand Down Expand Up @@ -41221,7 +41224,7 @@ def _getDesc(s, t=0):
""".format(
cmd,
mode,
"Monitor kernel function calls",
"Monitor kernel stacks",
"for specific threads",
"from the specific binary",
)
Expand Down Expand Up @@ -41506,6 +41509,7 @@ def _getDesc(s, t=0):

- {2:1} including specific kernel functions
# {0:1} {1:1} -f -K "evt1:func*::NONE"
# {0:1} {1:1} -f -K "evt1:func*::NONE" -q INCDOTSYM
# {0:1} {1:1} -f -K "evt1:func1:u32:NONE, evt2:0x1234:s16:NONE, evt3:func2:x16:NONE"
# {0:1} {1:1} -f -K "openfile:getname::NONE, access:0x1234::NONE"

Expand Down Expand Up @@ -43348,6 +43352,9 @@ def _getDesc(s, t=0):
# {0:1} {1:1} -g a.out -q ONLYUSER
# {0:1} {1:1} -g a.out -q ONLYKERNEL

- {2:1} for specific processes with stacks including thread comm
# {0:1} {1:1} -g a.out -q ADDCOMMCALL

- {2:1} with time filter
# {0:1} {1:1} -a -q TRIM:0:1.3

Expand Down Expand Up @@ -43616,8 +43623,11 @@ def _getDesc(s, t=0):

myStr = (
"""
- {2:1} from compressed files
# {0:1} {1:1} guider.out.gz -q DECODE
- {2:1} from a compressed file
# {0:1} {1:1} guider.out.gz

- {2:1} without decoding
# {0:1} {1:1} guider.out.gz -q NODECODE

- {2:1} and save samples to the specific file
# {0:1} {1:1} guider.out.gz -q SAVESAMPLE
Expand Down Expand Up @@ -44465,6 +44475,7 @@ def _getDesc(s, t=0):

- {2:1} including specific kernel functions
# {0:1} {1:1} -K "evt1:func*"
# {0:1} {1:1} -K "evt1:func*" -q INCDOTSYM
# {0:1} {1:1} -K "evt1:func1:u32, evt2:0x1234:s16, evt3:func2:x16"
# {0:1} {1:1} -K "open:do_sys_open:dfd=%ax filename=%bx;u64 flags=%cx;s32 mode=+4(\$stack):NONE"
# {0:1} {1:1} -K "strace32:func1:%bp/u32.%sp/s64, strace:0x1234:\$stack:NONE"
Expand Down Expand Up @@ -49580,6 +49591,9 @@ def writeKernelCmd(applyCmd=True, cmdList=[], clear=False):
if UtilMgr.isValidStr(sym, [cmd[1]])
]

if not "INCDOTSYM" in SysMgr.environList:
symList = [sym for sym in symList if not "." in sym]

for sym in symList:
newCmd = list(cmd)
if realname:
Expand Down Expand Up @@ -51062,7 +51076,7 @@ def _getPacket(fd):
raise Exception()
yield packet
except GeneratorExit:
return None
return
except SystemExit:
sys.exit(0)
except:
Expand Down Expand Up @@ -54296,6 +54310,10 @@ def sendOutput2Nodes(line, force=False):
start = end
end += udpSeg

@staticmethod
def printStr(string):
print(string)

@staticmethod
def printPipe(
line="",
Expand Down Expand Up @@ -57166,7 +57184,6 @@ def isWritable(value):
@staticmethod
def isTopMode():
if len(sys.argv) > 1 and sys.argv[1] in (
"top",
"andtop",
"atop",
"attop",
Expand All @@ -57181,7 +57198,7 @@ def isTopMode():
"fetop",
"ftop",
"irqtop",
"kftop",
"kstop",
"ktop",
"mdtop",
"mtop",
Expand All @@ -57192,6 +57209,7 @@ def isTopMode():
"slabtop",
"stacktop",
"systop",
"top",
"tptop",
"trtop",
"ttop",
Expand Down Expand Up @@ -58030,13 +58048,15 @@ def checkBgTopCond():
tmpPath = os.path.realpath(".")

# apply output dir #
if os.path.isdir(logPath) and os.access(logPath, os.W_OK):
SysMgr.outPath = logPath
elif os.path.isdir(tmpPath) and os.access(tmpPath, os.W_OK):
SysMgr.outPath = tmpPath
else:
SysMgr.printErr("failed to get path to save output, use -o option")
return False
for d in (logPath, tmpPath, None):
if d is None:
SysMgr.printErr(
"failed to get path to save output, use -o option"
)
return False
elif os.path.isdir(d) and os.access(d, os.W_OK):
SysMgr.outPath = d
break

SysMgr.printInfo("save reporting files to '%s'" % SysMgr.outPath)
return True
Expand Down Expand Up @@ -59536,7 +59556,7 @@ def _printRes(statusDict):
if SysMgr.hasEnvironVar(["GETPKGLIST", "GETPROCLIST"]):
printFunc = SysMgr.printPipe
else:
printFunc = print
printFunc = SysMgr.printStr
printFunc(UtilMgr.convDict2Str(statusDict, pretty=False))

SysMgr.addExitFunc(_printRes, [statusDict])
Expand Down Expand Up @@ -60704,7 +60724,7 @@ def _getLine(scripts):
yield idx, line.rstrip("\n")
idx += 1
except GeneratorExit:
return idx, None
return
except SystemExit:
sys.exit(0)
except:
Expand Down Expand Up @@ -61266,6 +61286,7 @@ def _getSym(call):
hasStackFilter = targetKernel or exceptKernel
taskFilter = SysMgr.environList.get("TASKFILTER", [])
procGroup = "PROCGROUP" in SysMgr.environList
addCommCall = "ADDCOMMCALL" in SysMgr.environList

# get time filter #
try:
Expand All @@ -61282,6 +61303,7 @@ def _getSym(call):
)

# parse lines #
comm = None
current = 0
totalCnt = 0
totalSize = 0
Expand Down Expand Up @@ -61312,6 +61334,18 @@ def _getSym(call):
if not sample:
continue

# add comm to callchain #
if addCommCall and callchain:
try:
lastcall = callchain[-1]
lastcall[1] = ("<%s>" % comm) + lastcall[1]
except SystemExit:
sys.exit(0)
except:
SysMgr.printWarn(
"failed to add comm to callchain", True, True
)

# save previous sample #
sample["backtrace"] = callchain

Expand Down Expand Up @@ -68208,7 +68242,7 @@ def _getPage(fd):
raise Exception()
yield page
except GeneratorExit:
return None
return
except SystemExit:
sys.exit(0)
except:
Expand Down Expand Up @@ -100044,7 +100078,7 @@ def getCallStatsFile(logFile, verb=False):

# check backtrace stacks #
onlybt = "ONLYBTSTACK" in SysMgr.environList
needDecode = "DECODE" in SysMgr.environList
needDecode = False if "NODECODE" in SysMgr.environList else True

for line in fd:
# check encoding type ##
Expand Down

0 comments on commit 39c530d

Please sign in to comment.