forked from vmprof/vmprof-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
51 lines (45 loc) · 1.62 KB
/
Copy pathparser.py
File metadata and controls
51 lines (45 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys
from jitlog import constants as const, marks
from jitlog.objects import TraceForest
from vmprof.binary import read_string
if sys.version_info[0] >= 3:
from io import StringIO
else:
from StringIO import StringIO
JITLOG_MIN_VERSION = 1
JITLOG_VERSION = 1
def read_jitlog_data(filename):
with open(str(filename), 'rb') as fileobj:
return fileobj.read()
def parse_jitlog(filename, data=None):
if data is None:
data = read_jitlog_data(filename)
fileobj = StringIO(data)
f = _parse_jitlog(fileobj)
f.filepath = filename
return f
def _parse_jitlog(fileobj):
is_jit_log = fileobj.read(1) == const.MARK_JITLOG_HEADER
version = ord(fileobj.read(1)) | (ord(fileobj.read(1)) << 8)
is_32bit = ord(fileobj.read(1))
machine = read_string(fileobj, True)
forest = TraceForest(version, is_32bit, machine)
assert is_jit_log, "Missing header. Data might not be a jitlog!"
assert version >= JITLOG_MIN_VERSION, \
"Version does not match. Log is version %d%d is not satisfied" % \
(version, JITLOG_VERSION)
while True:
marker = fileobj.read(1)
if len(marker) == 0:
break # end of file!
assert forest.is_jitlog_marker(marker), \
"marker unkown: 0x%x at pos 0x%x" % (ord(marker), fileobj.tell())
trace = forest.last_trace
try:
read = marks.get_reader(version, marker)
read(forest, trace, fileobj)
forest.time_tick()
except KeyError:
print("failed at", hex(fileobj.tell()), "with marker", marker)
raise
return forest