Skip to content

Commit

Permalink
drawtime: Refactor addTimeline
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <iipeace5@gmail.com>
  • Loading branch information
iipeace committed Sep 25, 2024
1 parent 3543749 commit 1ba6726
Showing 1 changed file with 45 additions and 87 deletions.
132 changes: 45 additions & 87 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__ = "240924"
__revision__ = "240925"
__maintainer__ = "Peace Lee"
__email__ = "iipeace5@gmail.com"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -25327,10 +25327,11 @@ def _printer(a, newline=1, force=False):
values["usage"], values["min"], values["max"], callAvg
)
callStatStr = "{0:>6}({1:3})".format(convNum(callCnt), callPer)
callStr = "{0:>32} | {1:>11} | {2:>30} |\n".format(
callStr = "{0:>32} | {1:>11} | {2:>30} | {3:1}\n".format(
taskInfo,
callStatStr,
callStat,
"<TOTAL>",
)

# print stats #
Expand Down Expand Up @@ -25421,6 +25422,7 @@ def _printer(a, newline=1, force=False):
# set stats #
totalCnt = float(sum([v["count"] for v in LogMgr.binderStat.values()]))
cliBasis = False if "SERVER" in SysMgr.environList else True
taskType = "PROCESS" if SysMgr.processEnable else "THREAD"
opposite = "server" if cliBasis else "cli"
jsonItem = jsonSubItem = {}
jsonStat = {
Expand Down Expand Up @@ -25461,18 +25463,14 @@ def _printer(a, newline=1, force=False):
"{4:>7} {5:>7} {6:>7} | {7:>38} | {8:>6} | "
"{9:>10}({10:>4}) \n{11:1}\n"
).format(
"%s(%s)"
% (
"CLIENT" if cliBasis else "SERVER",
"PROCESS" if SysMgr.processEnable else "THREAD",
),
"%s(%s)" % ("CLIENT" if cliBasis else "SERVER", taskType),
"CALL",
"%",
"TOTAL",
"MIN",
"MAX",
"AVG",
"SERVER" if cliBasis else "CLIENT",
"%s(%s)" % ("SERVER" if cliBasis else "CLIENT", taskType),
"CODE",
"COUNT",
"%",
Expand Down Expand Up @@ -25516,7 +25514,7 @@ def _printer(a, newline=1, force=False):
key=lambda x: x[1].get(sortRes, 0),
reverse=True,
):
if quitLoop or (not force and SysMgr.checkCutCond()):
if quitLoop or (not force and SysMgr.checkCutCond(1)):
break

# get comm #
Expand Down Expand Up @@ -40830,6 +40828,9 @@ def _getDesc(s, t=0):
- {2:1} with interval stats
# {0:1} {1:1} {3:1} -q PRINTSTAT

- {2:1} except for things about me
# {0:1} {1:1} {3:1} -q EXCEPTME

- {2:1} after applying filters
# {0:1} {1:1} {3:1} -q TPFILTER:"sched:common_pid==895"
# {0:1} {1:1} {3:1} -q TPFILTER:"sched/sched_switch:prev_comm==\\"yes\\""
Expand Down Expand Up @@ -100726,7 +100727,7 @@ def printBpContext(self, sym, addr, fname, checkArg, origPC):
self.addSample(sym, fname, realtime=True, bt=backtrace)

# add timeline segment #
self.addTimelineInt(sym, self.btStr)
self.addTimeline(True, sym, self.btStr)

return isRetBp

Expand Down Expand Up @@ -100857,7 +100858,9 @@ def printBpContext(self, sym, addr, fname, checkArg, origPC):

# add timeline segment #
numElapsed = float(origElapsed)
self.addTimelineRet(origSym, numElapsed, btstr)
self.addTimeline(
False, origSym, btstr, diff=numElapsed
)

# build JSON output #
elif SysMgr.jsonEnable:
Expand Down Expand Up @@ -100939,7 +100942,7 @@ def printBpContext(self, sym, addr, fname, checkArg, origPC):
)

# add timeline segment #
self.addTimelineInt(sym, btstr)
self.addTimeline(True, sym, btstr)

# check filter result #
if not filterRes:
Expand Down Expand Up @@ -101451,7 +101454,7 @@ def handleSignal(self, sig, warn=False, taskinfo=False):
SysMgr.printPipe(callString)

# add timeline segment #
self.addTimelineInt(name, callString)
self.addTimeline(True, name, callString)

# print backtrace #
if not self.isRealtime and SysMgr.funcDepth:
Expand Down Expand Up @@ -102161,7 +102164,7 @@ def handlePyTrap(self, sym, fname, addr):
):
pySym = "%s[%s]" % (self.prevPySym, self.prevPyFile)
pyBtStr = self.getBtStr(self.prevPyBt)
self.addTimelineRet(pySym, etime, pyBtStr)
self.addTimeline(False, pySym, pyBtStr, diff=etime)

# initialize previous symbol #
call = self.prevPySym
Expand Down Expand Up @@ -102211,7 +102214,7 @@ def handlePyTrap(self, sym, fname, addr):
)

# add timeline item #
self.addTimelineInt(call, btstr)
self.addTimeline(True, call, btstr)

# add backtrace #
if btstr:
Expand Down Expand Up @@ -102354,7 +102357,7 @@ def handlePycall(self, retbt=False, cur=False):
# add timeline segment #
if Debugger.envFlags["TIMELINE"] and Debugger.envFlags["INTERCALL"]:
pyBtStr = self.getBtStr(bt)
self.addTimelineInt(lastName, pyBtStr)
self.addTimeline(True, lastName, pyBtStr)

self.addSample(lastName, lastFile, realtime=True, bt=bt)

Expand Down Expand Up @@ -102604,44 +102607,7 @@ def isDeferCall(self, name):
def isDeferRetCall(self, name):
return name in ConfigMgr.SYSCALL_DEFFERABLE_RET

def addTimelineRet(self, sym, diff, bts, gid=-1, sid=-1):
if not Debugger.envFlags["TIMELINE"] or Debugger.envFlags["INTERCALL"]:
return

# get symbol id #
if sid == -1:
if not sym in self.timelineIdx:
self.timelineIdx[sym] = str(len(self.timelineIdx))
symidx = self.timelineIdx[sym]
else:
symidx = sid

# get group id #
if gid == -1:
grpidx = symidx
else:
grpidx = gid

# convert time unit to us #
startTime = self.vdiff - diff
endTime = self.vdiff
endTime *= 1000000
startTime *= 1000000

# add timeline data #
self.timelineData["segments"].append(
{
"group": grpidx,
"text": sym,
"id": symidx,
"state": "S",
"time_start": startTime,
"time_end": endTime,
"info": bts.strip() if bts else "",
}
)

def addTimelineInt(self, sym, bts, gid=-1, sid=-1):
def addTimeline(self, isIntval, sym, bts, gid=-1, sid=-1, diff=0):
# add timeline segment #
if (
not Debugger.envFlags["TIMELINE"]
Expand All @@ -102664,7 +102630,14 @@ def addTimelineInt(self, sym, bts, gid=-1, sid=-1):
grpidx = gid

# convert time unit to us #
startTime = self.vdiff * 1000000
if isIntval:
startTime = self.vdiff * 1000000
endTime = startTime + self.timeDuration
else:
startTime = self.vdiff - diff
endTime = self.vdiff
endTime *= 1000000
startTime *= 1000000

# add timeline data #
self.timelineData["segments"].append(
Expand All @@ -102674,7 +102647,7 @@ def addTimelineInt(self, sym, bts, gid=-1, sid=-1):
"id": symidx,
"state": "S",
"time_start": startTime,
"time_end": startTime + self.timeDuration,
"time_end": endTime,
"info": bts.strip() if bts else "",
}
)
Expand Down Expand Up @@ -102718,7 +102691,7 @@ def handleSyscallOutput(self, args, defer=False, ignored=False):
bts = ""

# add timeline item #
self.addTimelineInt(self.syscall, bts)
self.addTimeline(True, self.syscall, bts)

# set filter flag #
if Debugger.envFlags["ONLYOK"] or Debugger.envFlags["ONLYFAIL"]:
Expand Down Expand Up @@ -103234,7 +103207,7 @@ def _getDict(size, name):
retstr = convColor(retstr, "WARNING")

# add timeline segment #
self.addTimelineRet(name, diff, self.prevBtStr)
self.addTimeline(False, name, self.prevBtStr, diff=diff)

# update stats #
if self.isRealtime:
Expand Down Expand Up @@ -118822,15 +118795,8 @@ def __init__(self, fpath=None, onlyInstance=False):
stop_delta = long((float(self.finishTime) - stime) * 1000000)

# add timeline data #
self.timelineData["segments"].append(
{
"group": nrCore,
"text": "OFF",
"id": nrCore,
"state": "OFF",
"time_start": start_delta,
"time_end": stop_delta,
}
self.addTimelineData(
nrCore, "OFF", nrCore, "OFF", start_delta, stop_delta
)

elif self.threadData[coreId]["lastOff"] > 0:
Expand All @@ -118844,15 +118810,8 @@ def __init__(self, fpath=None, onlyInstance=False):
stop_delta = long((float(self.finishTime) - stime) * 1000000)

# add timeline data #
self.timelineData["segments"].append(
{
"group": nrCore,
"text": "OFF",
"id": nrCore,
"state": "OFF",
"time_start": start_delta,
"time_end": stop_delta,
}
self.addTimelineData(
nrCore, "OFF", nrCore, "OFF", start_delta, stop_delta
)

if self.threadData[val]["lastStatus"] == "S":
Expand Down Expand Up @@ -118976,7 +118935,14 @@ def __init__(self, fpath=None, onlyInstance=False):
continue

# add segment #
self.timelineData["segments"].append(item)
self.addTimelineData(
item["group"],
item["text"],
item["id"],
item["state"],
item["time_start"],
item["time_end"],
)

# filter thread data #
for key in list(self.threadData):
Expand All @@ -118998,16 +118964,7 @@ def __init__(self, fpath=None, onlyInstance=False):

# add empty timeline data for drawing cores #
for nrCore in SysMgr.perCoreDrawList:
self.timelineData["segments"].append(
{
"group": nrCore,
"text": "OFF",
"id": nrCore,
"state": "OFF",
"time_start": 0,
"time_end": 0,
}
)
self.addTimelineData(nrCore, "OFF", nrCore, "OFF", 0, 0)

def __del__(self):
pass
Expand Down Expand Up @@ -137230,6 +137187,7 @@ def addTimelineData(self, group, text, task, state, start, end):
group = self.timelineIdx[task]

# add timeline data #
self.timelineData.setdefault("segments", [])
self.timelineData["segments"].append(
{
"group": group,
Expand Down

0 comments on commit 1ba6726

Please sign in to comment.