Skip to content

Commit

Permalink
printtrace: Improve parsing performance using cache
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <iipeace5@gmail.com>
  • Loading branch information
iipeace committed Sep 19, 2024
1 parent 02fda7e commit 189f833
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 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__ = "240918"
__revision__ = "240919"
__maintainer__ = "Peace Lee"
__email__ = "iipeace5@gmail.com"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -27909,18 +27909,21 @@ class SysMgr(object):
r"\(\s*(?P<tgid>\S+)\)\s+\[(?P<core>[0-9]+)\]\s+"
r"(?P<irq>(\S{5}\s)*)(?P<time>\S+):\s+(?P<func>\S+):(?P<etc>.+)"
)
traceTgidFormat1Code = None

traceTgidFormat2 = (
r"^\s*(?P<comm>\S+)-(?P<thread>[0-9]+)\s+"
r"\[(?P<core>[0-9]+)\]\s+\(\s*(?P<tgid>.+)\)\s+"
r"(?P<irq>(\S{5}\s)*)(?P<time>\S+):\s+(?P<func>\S+)(?P<etc>.+)"
)
traceTgidFormat2Code = None

traceNoTgidFormat = (
r"^\s*(?P<comm>\S+)-(?P<thread>[0-9]+)\s+"
r"\[(?P<core>[0-9]+)\]\s+(?P<irq>(\S{5}\s)*)(?P<time>\S+):\s+"
r"(?P<func>\S+):(?P<etc>.+)"
)
traceNoTgidFormatCode = None

cliCmdStr = """
Commands:
Expand Down Expand Up @@ -36432,13 +36435,23 @@ def isExceptTarget(tid, tdata, comm=None, plist=[]):
def getTraceItem(string):
if SysMgr.tgidEnable:
# record-tgid option #
m = re.match(SysMgr.traceTgidFormat2, string)
if not SysMgr.traceTgidFormat2Code:
SysMgr.traceTgidFormat2Code = re.compile(
SysMgr.traceTgidFormat2
)
m = SysMgr.traceTgidFormat2Code.match(string)
if not m:
# print-tgid option #
return re.match(SysMgr.traceTgidFormat1, string)
if not SysMgr.traceTgidFormat1Code:
SysMgr.traceTgidFormat1Code = re.compile(
SysMgr.traceTgidFormat1
)
return SysMgr.traceTgidFormat1Code.match(string)

# no tgid #
return re.match(SysMgr.traceNoTgidFormat, string)
if not SysMgr.traceNoTgidFormatCode:
SysMgr.traceNoTgidFormatCode = re.compile(SysMgr.traceNoTgidFormat)
return SysMgr.traceNoTgidFormatCode.match(string)

@staticmethod
def isValidEnableOption(options):
Expand Down Expand Up @@ -38135,6 +38148,9 @@ def printHelp(force=False, isExit=True):
# {0:1} {1:1} -q DYNUPTIMEOPT:1m:"-i 3 -a"
# {0:1} {1:1} -q DYNRUNTIMEOPT:2m:"-i 3 -a"

- {3:1} {2:1} and update options with specific conditions after clear previous environment variables
# {0:1} {1:1} -q DYNUPTIMEOPT:1m:"-i 3 -a -q CLEARENV"

- {3:1} {2:1} through the local server having 5555 port
# {0:1} {1:1} -X 5555
# {0:1} {1:1} -X PRINT@5555
Expand Down Expand Up @@ -60676,8 +60692,13 @@ def updateEnvironVars(option):
if not value:
return

# apply environment variables #
itemList = UtilMgr.splitString(value)
SysMgr.environList.update(UtilMgr.convList2Dict(itemList, cap=True))
itemDict = UtilMgr.convList2Dict(itemList, cap=True)
if "CLEARENV" in itemDict:
SysMgr.environList = itemDict
else:
SysMgr.environList.update(itemDict)

# update environment variable list #
os.environ.update(SysMgr.getEnvList())
Expand All @@ -60688,6 +60709,7 @@ def parseEnvironVars():
if not value:
return

# apply environment variables #
itemList = UtilMgr.splitString(value)
SysMgr.environList = UtilMgr.convList2Dict(itemList, cap=True)

Expand Down Expand Up @@ -83407,23 +83429,15 @@ def printMemInfo(self):
if "NOMEMINFO" in SysMgr.environList:
return

# parse previous data #
# parse previous and next data #
time = "prev"
self.memInfo[time] = {}
for l in self.memData[time]:
m = re.match(r"(?P<type>\S+):\s+(?P<size>[0-9]+)", l)
if m:
d = m.groupdict()
self.memInfo[time][d["type"]] = d["size"]

# parse current data #
time = "next"
self.memInfo[time] = {}
for l in self.memData[time]:
m = re.match(r"(?P<type>\S+):\s+(?P<size>[0-9]+)", l)
if m:
d = m.groupdict()
self.memInfo[time][d["type"]] = d["size"]
for t in ("prev", "next"):
self.memInfo[t] = {}
for l in self.memData[t]:
m = re.match(r"(?P<type>\S+):\s+(?P<size>[0-9]+)", l)
if m:
d = m.groupdict()
self.memInfo[t][d["type"]] = d["size"]

b = self.memInfo["prev"]
a = self.memInfo["next"]
Expand Down

0 comments on commit 189f833

Please sign in to comment.