tools/trace: Defer blob hex-decoding.
authorJosé Fonseca <jfonseca@vmware.com>
Thu, 20 Jun 2013 18:38:55 +0000 (19:38 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Fri, 21 Jun 2013 13:30:19 +0000 (14:30 +0100)
To speed up parsing.
Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/tools/trace/model.py
src/gallium/tools/trace/parse.py

index 8276a8f9c6105d52b1f3cec91b694906696fc36d..82aca6935bfd0bba9bc089bca012fc064c68339c 100755 (executable)
 
 import sys
 import string
-import format
+import binascii
 
 try:
     from cStringIO import StringIO
 except ImportError:
     from StringIO import StringIO
 
+import format
+
 
 class Node:
     
@@ -62,6 +64,22 @@ class Literal(Node):
         visitor.visit_literal(self)
 
 
+class Blob(Node):
+    
+    def __init__(self, value):
+        self._rawValue = None
+        self._hexValue = value
+
+    def getValue(self):
+        if self._rawValue is None:
+            self._rawValue = binascii.a2b_hex(self._hexValue)
+            self._hexValue = None
+        return self._rawValue
+
+    def visit(self, visitor):
+        visitor.visit_blob(self)
+
+
 class NamedConstant(Node):
     
     def __init__(self, name):
@@ -127,6 +145,9 @@ class Visitor:
     def visit_literal(self, node):
         raise NotImplementedError
     
+    def visit_blob(self, node):
+        raise NotImplementedError
+    
     def visit_named_constant(self, node):
         raise NotImplementedError
     
@@ -157,16 +178,14 @@ class PrettyPrinter:
             return
 
         if isinstance(node.value, basestring):
-            if len(node.value) >= 4096 or node.value.strip(string.printable):
-                self.formatter.address('blob(%u)' % len(node.value))
-                #self.formatter.text('...')
-                return
-
             self.formatter.literal('"' + node.value + '"')
             return
 
         self.formatter.literal(repr(node.value))
     
+    def visit_blob(self, node):
+        self.formatter.address('blob()')
+    
     def visit_named_constant(self, node):
         self.formatter.literal(node.name)
     
index 07f2d6c765965b498148e33d4d7471b7739462de..d8dce2628ab85e172c218e0429dbfc9469c84c71 100755 (executable)
@@ -29,7 +29,6 @@
 
 import sys
 import xml.parsers.expat
-import binascii
 import optparse
 
 from model import *
@@ -305,9 +304,9 @@ class TraceParser(XmlParser):
         
     def parse_bytes(self):
         self.element_start('bytes')
-        value = binascii.a2b_hex(self.character_data())
+        value = self.character_data()
         self.element_end('bytes')
-        return Literal(value)
+        return Blob(value)
         
     def parse_array(self):
         self.element_start('array')