Skip to content

Commit

Permalink
hprof: Fix empty line parsing bug for java dump
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <[email protected]>
  • Loading branch information
iipeace committed Nov 1, 2024
1 parent f07c03e commit f834b6f
Showing 1 changed file with 58 additions and 37 deletions.
95 changes: 58 additions & 37 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__ = "241031"
__revision__ = "241101"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -42983,9 +42983,8 @@ def _getDesc(s, t=0):
- Report from perfetto data
# {0:1} {1:1} -I prof.data

- Report from perfetto data without report
- Convert perfetto data to text
# {0:1} {1:1} -I prof.data -q FROMSAMPLE

""".format(
cmd,
mode,
Expand Down Expand Up @@ -50531,6 +50530,8 @@ def _getPacket(fd):
if packet == b"":
raise Exception()
yield packet
except GeneratorExit:
return None
except SystemExit:
sys.exit(0)
except:
Expand Down Expand Up @@ -59554,7 +59555,7 @@ def _waitTask(pid):
elif os.path.isfile("./traceconv"):
binPath = "./traceconv"
elif not UtilMgr.which("traceconv"):
_printErr("no found traceconv")
_printErr("no found traceconv, refer to help")
return -1
else:
binPath = "traceconv"
Expand Down Expand Up @@ -60040,7 +60041,12 @@ def convHeapProfSample(path, scripts=[], statusDict={}):
"profile_packet",
"interned_data",
]

# define shortcuts #
convNum = UtilMgr.convNum
convSize = UtilMgr.convSize2Unit
convColor = UtilMgr.convColor
convDict = UtilMgr.convDict2Str

# parse lines #
pid = 0
Expand Down Expand Up @@ -60077,6 +60083,8 @@ def _getLine(scripts):
line = line.decode()
yield idx, line.rstrip("\n")
idx += 1
except GeneratorExit:
return idx, None
except SystemExit:
sys.exit(0)
except:
Expand All @@ -60095,41 +60103,53 @@ def _getLine(scripts):
0 if totalLength == 0 else idx, totalLength
)
totalSize += len(l)
l = l.rstrip()

if l.startswith("packet {"):
# parse a line #
l = l.rstrip()
if not l:
continue
elif l.startswith("packet {"):
buf = ["{"]
elif l.startswith("}"):
# make JSON object #
encoded = ("".join(buf).rstrip(",") + "}").replace("\\", "\\\\")
json = UtilMgr.convStr2Dict(encoded, True, True)

# save data #
if json:
# update timestamp #
ts = json.get("timestamp")
if ts:
ts = long(ts) / 1000000000
if not start:
start = ts
else:
last = ts

# save packets #
for s in sourceList:
v = json.get(s)
if not v:
continue

# duplicated #
if s in packets:
if not isinstance(type(packets[s]), list):
packets[s] = [packets[s]]
packets[s].append(v)
else:
packets[s] = v
json = UtilMgr.convStr2Dict(encoded, False, True)

# reset buffer #
buf = []

# check object #
if not json:
SysMgr.printWarn(
"failed to make JSON object at %s line in sample"
% convNum(idx),
True
)
continue

# update timestamp #
ts = json.get("timestamp")
if ts:
ts = long(ts) / 1000000000
if not start:
start = ts
else:
last = ts

# save packets #
for s in sourceList:
v = json.get(s)
if not v:
continue

# add duplicated item to list #
if s in packets:
pitem = packets[s]
if not isinstance(type(pitem), list):
packets[s] = [pitem]
packets[s].append(v)
else:
packets[s] = v
elif l.endswith("{"):
l = '"%s": {' % l.rsplit("{", 1)[0].strip()
buf.append(l)
Expand Down Expand Up @@ -60171,7 +60191,7 @@ def _saveSysInfo(pstr):
continue

# convert meta info #
pstr = UtilMgr.convDict2Str(packets[x])
pstr = convDict(packets[x])
if not pstr:
continue

Expand Down Expand Up @@ -60273,8 +60293,9 @@ def _saveSysInfo(pstr):
# process profile samples #
# callstack_id, self_allocated, self_freed, alloc_count, free_count #
for p in profData if isinstance(profData, list) else [profData]:
# convert dict to list #
if not isinstance(p, list):
subp = [p]
p = [p]

for subp in p:
# check type #
Expand All @@ -60293,7 +60314,7 @@ def _saveSysInfo(pstr):

# print profiling info #
if pdata:
pstr = UtilMgr.convDict2Str(pdata)
pstr = convDict(pdata)
if SysMgr.warnEnable:
_printWarn("[prof_info]: " + pstr, True)
else:
Expand Down Expand Up @@ -60464,8 +60485,6 @@ def _saveSysInfo(pstr):
return -1

# print stats #
convNum = UtilMgr.convNum
convSize = UtilMgr.convSize2Unit
statStr = ""
for sn, sv in totalStats.items():
if not sv:
Expand Down Expand Up @@ -67516,6 +67535,8 @@ def _getPage(fd):
if page == b"":
raise Exception()
yield page
except GeneratorExit:
return None
except SystemExit:
sys.exit(0)
except:
Expand Down

0 comments on commit f834b6f

Please sign in to comment.