python/retrace: Process the trace call-by-call (instead of reading everything into memory).
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import gallium
|
import gallium
|
||||||
import model
|
import model
|
||||||
from parser import TraceParser
|
import parser
|
||||||
|
|
||||||
|
|
||||||
def make_image(surface):
|
def make_image(surface):
|
||||||
@@ -426,9 +426,10 @@ class Context(Object):
|
|||||||
show_image(self.cbufs[0])
|
show_image(self.cbufs[0])
|
||||||
|
|
||||||
|
|
||||||
class Interpreter:
|
class Interpreter(parser.TraceParser):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, stream):
|
||||||
|
parser.TraceParser.__init__(self, stream)
|
||||||
self.objects = {}
|
self.objects = {}
|
||||||
self.result = None
|
self.result = None
|
||||||
self.globl = Global(self, None)
|
self.globl = Global(self, None)
|
||||||
@@ -447,7 +448,7 @@ class Interpreter:
|
|||||||
for call in trace.calls:
|
for call in trace.calls:
|
||||||
self.interpret_call(call)
|
self.interpret_call(call)
|
||||||
|
|
||||||
def interpret_call(self, call):
|
def handle_call(self, call):
|
||||||
sys.stderr.write("%s\n" % call)
|
sys.stderr.write("%s\n" % call)
|
||||||
|
|
||||||
args = [self.interpret_arg(arg) for name, arg in call.args]
|
args = [self.interpret_arg(arg) for name, arg in call.args]
|
||||||
@@ -469,18 +470,5 @@ class Interpreter:
|
|||||||
return translator.visit(node)
|
return translator.visit(node)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
for arg in sys.argv[1:]:
|
|
||||||
if arg.endswith('.gz'):
|
|
||||||
import gzip
|
|
||||||
stream = gzip.GzipFile(arg, 'rt')
|
|
||||||
else:
|
|
||||||
stream = open(arg, 'rt')
|
|
||||||
parser = TraceParser(stream)
|
|
||||||
trace = parser.parse()
|
|
||||||
interpreter = Interpreter()
|
|
||||||
interpreter.interpret(trace)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
parser.main(Interpreter)
|
||||||
|
@@ -183,12 +183,11 @@ class TraceParser(XmlParser):
|
|||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
self.element_start('trace')
|
self.element_start('trace')
|
||||||
calls = []
|
|
||||||
while self.token.type not in (ELEMENT_END, EOF):
|
while self.token.type not in (ELEMENT_END, EOF):
|
||||||
calls.append(self.parse_call())
|
call = self.parse_call()
|
||||||
|
self.handle_call(call)
|
||||||
if self.token.type != EOF:
|
if self.token.type != EOF:
|
||||||
self.element_end('trace')
|
self.element_end('trace')
|
||||||
return Trace(calls)
|
|
||||||
|
|
||||||
def parse_call(self):
|
def parse_call(self):
|
||||||
attrs = self.element_start('call')
|
attrs = self.element_start('call')
|
||||||
@@ -319,19 +318,28 @@ class TraceParser(XmlParser):
|
|||||||
|
|
||||||
return Pointer(address)
|
return Pointer(address)
|
||||||
|
|
||||||
|
def handle_call(self, call):
|
||||||
|
|
||||||
def main():
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TraceDumper(TraceParser):
|
||||||
|
|
||||||
|
|
||||||
|
def handle_call(self, call):
|
||||||
|
print call
|
||||||
|
|
||||||
|
|
||||||
|
def main(ParserFactory):
|
||||||
for arg in sys.argv[1:]:
|
for arg in sys.argv[1:]:
|
||||||
if arg.endswith('.gz'):
|
if arg.endswith('.gz'):
|
||||||
import gzip
|
import gzip
|
||||||
stream = gzip.GzipFile(arg, 'rt')
|
stream = gzip.GzipFile(arg, 'rt')
|
||||||
else:
|
else:
|
||||||
stream = open(arg, 'rt')
|
stream = open(arg, 'rt')
|
||||||
parser = TraceParser(stream)
|
parser = ParserFactory(stream)
|
||||||
trace = parser.parse()
|
parser.parse()
|
||||||
for call in trace.calls:
|
|
||||||
print call
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main(TraceDumper)
|
||||||
|
Reference in New Issue
Block a user