Skip to content

Commit

Permalink
draw: Add ATRACE timeline segments
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <[email protected]>
  • Loading branch information
iipeace committed Sep 27, 2024
1 parent 7075816 commit 2e32559
Showing 1 changed file with 90 additions and 56 deletions.
146 changes: 90 additions & 56 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__ = "240926"
__revision__ = "240927"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -12011,7 +12011,7 @@ def _draw_segments(self, dwg, start=0):
start = float(start) / self.time_factor

for idx, segment in enumerate(
sorted(self.segments, key=lambda e: len(e.state))
sorted(self.segments, key=lambda e: (e.time_start, len(e.state)))
):
UtilMgr.printProgress(idx, len(self.segments))
self._draw_segment(segment, dwg, start)
Expand Down Expand Up @@ -12197,7 +12197,7 @@ def _draw_segment(self, segment, dwg, start=0):
)
)
# draw line for syscall status #
elif segment.state == "SYSCALL":
elif segment.state in ("SYSCALL", "ATRACE"):
g.add(
dwg.rect(
(x0, y0),
Expand Down Expand Up @@ -24901,10 +24901,17 @@ def _updateStat(statInfo, pid, diff, tm, point=None):
statInfo["point"].setdefault(point, dict(dflStat))
pointInfo = statInfo["point"][point]

if "DRAWTIME" in SysMgr.environList:
core = data.get("core")
# add timeline data #
if "TIMELINE" in SysMgr.environList:
LogMgr.timelineData.append(
[core, point, core, tm - diff, tm]
[
pid,
point,
statInfo.get("comm"),
"ATRACE",
(tm - diff) * 1000000,
tm * 1000000,
]
)

pointInfo["count"] += 1
Expand Down Expand Up @@ -25899,35 +25906,6 @@ def printTrace(console=False, targets=None, cb=None, parser=None):
# check root permission #
SysMgr.checkRootPerm()

# set atrace properties #
atraceApp = SysMgr.environList.get("ATRACE", [])
if atraceApp:
# set target app #
for i, a in enumerate(atraceApp):
a = "*" if a == "SET" else a
SysMgr.setProp("debug.atrace.app_%s" % i, a, True)

# set target app number #
SysMgr.setProp(
"debug.atrace.app_number", str(len(atraceApp)), True
)
SysMgr.addExitFunc(
SysMgr.setProp, ["debug.atrace.app_number", "0", True]
)

# enable tag flags #
SysMgr.setProp("debug.atrace.tags.enableflags", "1", True)
SysMgr.addExitFunc(
SysMgr.setProp,
["debug.atrace.tags.enableflags", "0", True],
)

# enable user initiated flag #
SysMgr.setProp("debug.atrace.user_initiated", "1", True)
SysMgr.addExitFunc(
SysMgr.setProp, ["debug.atrace.user_initiated", "0", True]
)

# validate event ##
for t in targets:
if "*" in t:
Expand Down Expand Up @@ -26476,8 +26454,6 @@ def printAndLog(console=False):
if "TIMELINE" in SysMgr.environList:
# create a task object #
taskObj = TaskAnalyzer(onlyInstance=True)
taskObj.timelineIdx = {}
taskObj.timelineData = {"time_unit": "us", "segments": []}
else:
taskObj = None

Expand Down Expand Up @@ -31204,6 +31180,36 @@ def splitFile(
)
return pathList

@staticmethod
def enableAtrace():
atraceApp = SysMgr.environList.get("ATRACE", [])
if atraceApp:
# set target app #
for i, a in enumerate(atraceApp):
a = "*" if a == "SET" else a
SysMgr.setProp("debug.atrace.app_%s" % i, a, True)

# set target app number #
SysMgr.setProp(
"debug.atrace.app_number", str(len(atraceApp)), True
)
SysMgr.addExitFunc(
SysMgr.setProp, ["debug.atrace.app_number", "0", True]
)

# enable tag flags #
SysMgr.setProp("debug.atrace.tags.enableflags", "1", True)
SysMgr.addExitFunc(
SysMgr.setProp,
["debug.atrace.tags.enableflags", "0", True],
)

# enable user initiated flag #
SysMgr.setProp("debug.atrace.user_initiated", "1", True)
SysMgr.addExitFunc(
SysMgr.setProp, ["debug.atrace.user_initiated", "0", True]
)

@staticmethod
def doLess(inputArg=None):
pipeInput = None
Expand Down Expand Up @@ -38849,6 +38855,13 @@ def printHelp(force=False, isExit=True):
# {0:1} {1:1} {3:1} -q STROKEINTERVAL:3000
# {0:1} {1:1} {3:1} -q STROKEDURATION:3000

- {2:1} on absolute / relative timeline
# {0:1} {1:1} {4:1} -q ABSTIME
# {0:1} {1:1} {4:1} -q RELTIME

- {2:1} for timeline segments of atrace logs
# {0:1} {1:1} {4:1} -q ATRACE, TIMELINE

- {2:1} to specific image format
# {0:1} {1:1} {4:1} -F png
# {0:1} {1:1} {4:1} -F pdf
Expand All @@ -38870,12 +38883,6 @@ def printHelp(force=False, isExit=True):
# {0:1} {1:1} {4:1} -q TRIM:11:
# {0:1} {1:1} {4:1} -q TRIM:11.9:13.5, ABSTIME

- {2:1} on absolute timeline
# {0:1} {1:1} {4:1} -q ABSTIME

- {2:1} on relative timeline
# {0:1} {1:1} {4:1} -q RELTIME

- {2:1} only having backtrace for the flame graph
# {0:1} {1:1} {4:1} -q ONLYBTSTACK

Expand Down Expand Up @@ -39988,8 +39995,8 @@ def _getDesc(s, t=0):
# {0:1} {1:1} -o . -q TRIM::9
# {0:1} {1:1} -o . -q TRIM:2:

- {3:1} based on the specific file with atrace logs and draw timeline
# {0:1} {1:1} trace.dat -q ATRACE, DRAWTIME
- {3:1} based on the specific file with atrace logs
# {0:1} {1:1} trace.dat -q ATRACE

- {3:1} {2:1} to guider.out after converting all target inodes to paths from specific directory
# {0:1} {1:1} -o . -q CONVINODE
Expand Down Expand Up @@ -78400,6 +78407,9 @@ def enableTracing():

@staticmethod
def enableEvents(targets=[], start=False):
# set atrace properties #
SysMgr.enableAtrace()

if not targets and not "ENABLETP" in SysMgr.environList:
return

Expand Down Expand Up @@ -121718,11 +121728,23 @@ def drawTimelineItems():
TaskAnalyzer.initDrawEnv()

# check absolute timeline option #
sysStart = float(SysMgr.startTime)
if "ABSTIME" in SysMgr.environList:
start = float(SysMgr.startTime)
start = sysStart
else:
start = 0

# add timeline data #
sysStartUs = sysStart * 1000000
for d in LogMgr.timelineData:
d[4] -= sysStartUs
d[5] -= sysStartUs
tobj.addTimelineData(*d)

# check timeline data #
if not hasattr(tobj, "timelineData"):
return

# minimize system info for annotation #
if SysMgr.sysinfoBuffer:
annotation = SysMgr.sysinfoBuffer
Expand Down Expand Up @@ -122022,9 +122044,11 @@ def _mergeTasks(atype):

# save max #
nstats[n].setdefault(
comm, {"average": sums, "minimum": 1}
comm,
{"average": sums, "minimum": 1, "count": 0},
)
nstats[n][comm][maxName] = maxval
nstats[n][comm]["count"] += 1

# save diff #
if atype:
Expand All @@ -122046,11 +122070,17 @@ def _mergeTasks(atype):
# save max #
statStr = " ".join(list(map(str, diffList)))
nstats[n].setdefault(
comm, {"average": sum(diffList), "minimum": 1}
comm,
{
"average": sum(diffList),
"minimum": 1,
"count": 0,
},
)
nstats[n][comm][maxName] = max(
defMax, max(diffList)
)
nstats[n][comm]["count"] += 1

# save diff #
if atype:
Expand Down Expand Up @@ -124171,18 +124201,18 @@ def _drawCpu(graphStats, xtype, pos, size, delay=False):

# get max cpu condition #
maxCpuCond = UtilMgr.getEnvironNum(
"MAXCPUCOND", False, 0, False, True
"MAXCPUCOND", False, -(SysMgr.maxSize), False, True
)

# get avg cpu condition #
avgCpuCond = UtilMgr.getEnvironNum(
"AVGCPUCOND", False, 0, False, True
"AVGCPUCOND", False, -(SysMgr.maxSize), False, True
)

# get min cpu condition #
if "MINCPUCOND" in SysMgr.environList:
minCpuCond = UtilMgr.getEnvironNum(
"MINCPUCOND", False, 0, False, True
"MINCPUCOND", False, -(SysMgr.maxSize), False, True
)
else:
minCpuCond = 0
Expand Down Expand Up @@ -127060,18 +127090,18 @@ def _drawAvgCpu(graphStats, xtype, pos, size):

# get max cpu condition #
maxCpuCond = UtilMgr.getEnvironNum(
"MAXCPUCOND", False, 0, False, True
"MAXCPUCOND", False, -(SysMgr.maxSize), False, True
)

# get avg cpu condition #
avgCpuCond = UtilMgr.getEnvironNum(
"AVGCPUCOND", False, 0, False, True
"AVGCPUCOND", False, -(SysMgr.maxSize), False, True
)

# get min cpu condition #
if "MINCPUCOND" in SysMgr.environList:
minCpuCond = UtilMgr.getEnvironNum(
"MINCPUCOND", False, 0, False, True
"MINCPUCOND", False, -(SysMgr.maxSize), False, True
)
else:
minCpuCond = 0
Expand Down Expand Up @@ -127312,7 +127342,7 @@ def __drawSystemMem(statList, color, ymax):
if SysMgr.vssEnable:
# get max vss condition #
maxVssCond = UtilMgr.getEnvironNum(
"MAXVSSCOND", False, 0, False, True
"MAXVSSCOND", False, -(SysMgr.maxSize), False, True
)

for key, item in sorted(
Expand Down Expand Up @@ -127374,7 +127404,7 @@ def __drawSystemMem(statList, color, ymax):
elif SysMgr.rssEnable or SysMgr.pssEnable or SysMgr.ussEnable:
# get max rss condition #
maxRssCond = UtilMgr.getEnvironNum(
"MAXRSSCOND", False, 0, False, True
"MAXRSSCOND", False, -(SysMgr.maxSize), False, True
)

for key, item in sorted(
Expand Down Expand Up @@ -137199,11 +137229,15 @@ def handleUserEvent(self, event, time):
def addTimelineData(self, group, text, task, state, start, end):
# convert group id from core to task #
if "PERTASK" in SysMgr.environList:
if not hasattr(self, "timelineIdx"):
self.timelineIdx = {}
if not task in self.timelineIdx:
self.timelineIdx[task] = task
group = self.timelineIdx[task]

# add timeline data #
if not hasattr(self, "timelineData"):
self.timelineData = {"time_unit": "us", "segments": []}
self.timelineData.setdefault("segments", [])
self.timelineData["segments"].append(
{
Expand Down

0 comments on commit 2e32559

Please sign in to comment.