Skip to content

Commit

Permalink
all: Enhance split performance applying maxsplit
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <iipeace5@gmail.com>
  • Loading branch information
iipeace committed Jan 19, 2025
1 parent 71a8728 commit 03a1e91
Showing 1 changed file with 52 additions and 41 deletions.
93 changes: 52 additions & 41 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__ = "250118"
__revision__ = "250119"
__maintainer__ = "Peace Lee"
__email__ = "iipeace5@gmail.com"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -6998,7 +6998,7 @@ def convxrange(targetList):

for item in targetList:
try:
nums = item.split(":")
nums = item.split(":", 2)
if len(nums) == 1:
result.append(item)
elif len(nums) == 2:
Expand Down Expand Up @@ -8530,7 +8530,7 @@ def convTime2Sec(time):
try:
sec = 0

nums = time.strip().split(":")
nums = time.strip().split(":", 5)
if len(nums) == 3:
y = d = 0
times = nums
Expand Down Expand Up @@ -10354,7 +10354,7 @@ def customBind(self):
continue

try:
start, end = item.split("-")
start, end = item.split("-", 1)
if end == "":
end = 65535
for idx in xrange(long(start), long(end) + 1):
Expand Down Expand Up @@ -11351,7 +11351,7 @@ def getDevByIp(ip):
# scan IP device and address #
for line in data:
try:
dev, stats = line.split(":")
dev, stats = line.split(":", 1)

dev = dev.strip()

Expand Down Expand Up @@ -15720,7 +15720,7 @@ def getPageInfo(
if vranges:
targetList += vranges
else:
vrange = UtilMgr.cleanItem(vaddr.split("-"), False)
vrange = UtilMgr.cleanItem(vaddr.split("-", 1), False)
if len(vrange) > 1 and vrange[1].startswith("+"):
start = UtilMgr.convInt(vrange[0])
try:
Expand Down Expand Up @@ -16295,7 +16295,7 @@ def printMemoryArea(
for line in buf:
tmplist = line.split()
vma = tmplist[0]
soffset, eoffset = vma.split("-")
soffset, eoffset = vma.split("-", 1)

soffset = long(soffset, base=16)
eoffset = long(eoffset, base=16)
Expand Down Expand Up @@ -18342,7 +18342,7 @@ def parseLines(self, lines, desc):

# make custom event table #
for cmd in SysMgr.customCmd:
cmd = cmd.split(":")
cmd = cmd.split(":", 1)

if len(cmd) > 1:
self.customEventTable[cmd[0]] = cmd[1]
Expand All @@ -18351,13 +18351,13 @@ def parseLines(self, lines, desc):

# make kernel event table #
for cmd in SysMgr.kernelCmd:
cmd = cmd.split(":")
cmd = cmd.split(":", 1)
self.customEventTable[cmd[0] + "_enter"] = None
self.customEventTable[cmd[0] + "_exit"] = None

# make user event table #
for cmd in SysMgr.userCmd:
cmd = cmd.split(":")
cmd = cmd.split(":", 1)
self.customEventTable[cmd[0] + "_enter"] = None
self.customEventTable[cmd[0] + "_exit"] = None

Expand Down Expand Up @@ -18763,7 +18763,7 @@ def parseEventInfo(self, tid, func, args, time, core):
self.heapEnabled = True

try:
size = long(b["args"].split(",")[1], 16)
size = long(b["args"].split(",", 2)[1], 16)

# just brk call to check data segment address #
if size == 0:
Expand All @@ -18787,7 +18787,7 @@ def parseEventInfo(self, tid, func, args, time, core):
self.heapEnabled = True

try:
addr = long(b["args"][1:].split(",")[0], 16)
addr = long(b["args"][1:].split(",", 1)[0], 16)
size = self.heapTable[addr]["size"]

# remove heap segment #
Expand Down Expand Up @@ -20871,7 +20871,7 @@ def printKnownMemFreeInfo(self):
kernelPages = 0

# get user alloc and free call #
allocCall, freeCall = pairId.split("#")
allocCall, freeCall = pairId.split("#", 1)

printBuf = "{0:4}+ {1:>7}({2:>6}/{3:>6}/{4:>6})| ".format(
" ",
Expand Down Expand Up @@ -20997,7 +20997,7 @@ def printKnownMemFreeInfo(self):
kernelPages = 0

# get kernel alloc and free call #
allocCall, freeCall = pairId.split("#")
allocCall, freeCall = pairId.split("#", 1)

printBuf = "{0:4}+ {1:>7}({2:>6}/{3:>6}/{4:>6})| ".format(
" ",
Expand Down Expand Up @@ -23653,7 +23653,7 @@ def makeReadaheadFile(
# apply add list #
for item in raAddList:
# parse file info #
finfo = item.split(":")
finfo = item.split(":", 3)
try:
item = finfo[0]
offset = size = 0
Expand Down Expand Up @@ -29291,7 +29291,7 @@ def getVmstat(retDict=False):

for line in vmBuf:
try:
item = line.strip().split()
item = line.strip().split(None, 1)
newDict.setdefault(item[0], long(item[1]))
except SystemExit:
sys.exit(0)
Expand Down Expand Up @@ -50397,12 +50397,10 @@ def writeCmd(path, val, append=False):
elif rCmd[0] == "#":
sCmd = "%s %s" % (sCmd, rCmd[1:])
continue
elif len(rCmd.split("/")) == 1:
sCmd = "%s %s" % (sCmd, rCmd)
continue

rVal = rCmd.split("/")
if len(rVal) < 2:
if len(rVal) == 1:
sCmd = "%s %s" % (sCmd, rCmd)
continue
elif len(rVal) > 2:
SysMgr.printErr("wrong command '%s'" % rCmd)
Expand Down Expand Up @@ -121514,14 +121512,27 @@ def _printSummary(fdata, onlyTotal, onlySummary, header, path=None):
jsonSubData = jsonData[item]
for proc, stats in jsonSubData.items():
for k in stats:
if not k in ("usage") and not k.endswith("Usage"):
if not k.endswith(("usage", "Usage")):
continue

try:
target = jsonSubData[proc][k].split("\n")
target = " ".join(target).split()
target = UtilMgr.cleanItem(target, False)
target = list(map(long, target))
if item in ("blkProcUsage",):
busage = []
for u in target:
us = u.split("/", 1)
# block time #
if len(us) == 1:
rd = wr = 0
# rw size #
else:
rd, wr = list(map(long, us))
busage.append([rd, wr])
target = busage
else:
target = list(map(long, target))
SysMgr.jsonData[item][proc][k] = target
except SystemExit:
sys.exit(0)
Expand Down Expand Up @@ -122277,18 +122288,18 @@ def _updateStats(target, usage):
else target["usage"].split()
)

if res in ("blkProcUsage"):
nusage = []
if res in ("blkProcUsage",):
busage = []
for u in targetUsage:
us = u.split("/")
us = u.split("/", 1)
# block time #
if len(us) == 1:
rd = wr = 0
# rw size #
else:
rd, wr = list(map(long, us))
nusage.append([rd, wr])
target["usage"] = nusage
busage.append([rd, wr])
target["usage"] = busage
elif res in ("cpuProcPrio"):
targetUsage = list(
map(SysMgr.convSchedPrio, targetUsage)
Expand Down Expand Up @@ -125253,7 +125264,7 @@ def getStatsFile(
cpuUsage.append(0)

try:
memStat = sline[3].split("/")
memStat = sline[3].split("/", 4)

if len(memStat) > 4:
raise Exception()
Expand Down Expand Up @@ -125286,15 +125297,15 @@ def getStatsFile(
swapUsage.append(0)

try:
reclaim = sline[7].strip().split("/")
reclaim = sline[7].strip().split("/", 1)
reclaimBg.append(long(reclaim[0]) << 2)
reclaimDr.append(long(reclaim[1]) << 2)
except:
reclaimBg.append(0)
reclaimDr.append(0)

try:
blkUsage = sline[4].split("/")
blkUsage = sline[4].split("/", 1)
blkRead.append(long(blkUsage[0]) << 10)
blkWrite.append(long(blkUsage[1]) << 10)
except:
Expand All @@ -125312,7 +125323,7 @@ def getStatsFile(
nrCore.append(0)

try:
netstat = sline[13].strip().split("/")
netstat = sline[13].strip().split("/", 1)

if netstat[0] == "-":
raise Exception()
Expand Down Expand Up @@ -125647,7 +125658,7 @@ def getStatsFile(
if item == "0":
busy = read = write = free = 0
else:
busy, read, write, free = item.split("/")
busy, read, write, free = item.split("/", 3)
busyList.append(long(busy))
readList.append(convSize(read) >> 10)
writeList.append(convSize(write) >> 10)
Expand Down Expand Up @@ -125679,7 +125690,7 @@ def getStatsFile(
if item == "0":
recv = tran = 0
else:
recv, tran = item.split("/")
recv, tran = item.split("/", 1)
recvList.append(convSize(recv) >> 10)
tranList.append(convSize(tran) >> 10)

Expand Down Expand Up @@ -125772,7 +125783,7 @@ def getStatsFile(
rlist = list(map(long, rlist))
elif context == "Cgroup.Blk":
for cidx in range(len(intervalList)):
rd, wr = intervalList[cidx].split("/")
rd, wr = intervalList[cidx].split("/", 1)
rd = convSize(rd) >> 20
wr = convSize(wr) >> 20
intervalList[idx] = "%s/%s" % (rd, wr)
Expand Down Expand Up @@ -125925,9 +125936,9 @@ def getStatsFile(
# pylint: disable-next=unsubscriptable-object
mpath = mpath[v]
elif t == "RAM":
totalRam = convSize(v.split("/")[1])
totalRam = convSize(v.split("/", 2)[1])
elif t == "Swap":
totalSwap = convSize(v.split("/")[1])
totalSwap = convSize(v.split("/", 2)[1])
elif slen == 3:
gname = sline[0].strip()
intervalList = sline[2].rstrip()
Expand Down Expand Up @@ -129779,7 +129790,7 @@ def _drawCpu(graphStats, xtype, pos, size, delay=False):
if p == "0":
some = full = 0
else:
some, full = list(map(long, p.split("/")))
some, full = list(map(long, p.split("/", 1)))
someList.append(some)
fullList.append(full)

Expand Down Expand Up @@ -130965,7 +130976,7 @@ def __drawSystemIo(

# divide I/O graph #
for item in usage:
io = item.split("/")
io = item.split("/", 1)
if len(io) == 2:
rdUsage.append(long(io[0]) << 10)
wrUsage.append(long(io[1]) << 10)
Expand Down Expand Up @@ -139350,9 +139361,9 @@ def printTimeline():
ts = val["total"]

if SysMgr.jsonEnable:
rclmBg, rclmFg = ts["rclm"].split("/")
blkRd, blkWr = ts["blk"].split("/")
netIn, netOut = ts["netIO"].split("/")
rclmBg, rclmFg = ts["rclm"].split("/", 1)
blkRd, blkWr = ts["blk"].split("/", 1)
netIn, netOut = ts["netIO"].split("/", 1)
jsonData.append(
{
"index": idx + 1,
Expand Down

0 comments on commit 03a1e91

Please sign in to comment.