Mesa (main): gallium/tools: improve option handling in dump_state.py

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri May 7 15:57:51 UTC 2021


Module: Mesa
Branch: main
Commit: 0834a42773fa234f00b87151473a7b086c31e066
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0834a42773fa234f00b87151473a7b086c31e066

Author: Matti Hamalainen <ccr at tnsp.org>
Date:   Tue Apr 20 15:15:59 2021 +0300

gallium/tools: improve option handling in dump_state.py

Previously we inherited some options from parse.py, but
that made no sense for some of the options that are not
needed for dump_state.py (such as --plain, as we output
only JSON format text.)

So, remove the inherit and implement filename argument
here independantly.

Signed-off-by: Matti Hamalainen <ccr at tnsp.org>
Acked-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10648>

---

 src/gallium/tools/trace/dump_state.py | 12 ++++++++----
 src/gallium/tools/trace/model.py      |  4 ++--
 src/gallium/tools/trace/parse.py      |  2 +-
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/gallium/tools/trace/dump_state.py b/src/gallium/tools/trace/dump_state.py
index 8b68d83f9a2..b23a929e265 100755
--- a/src/gallium/tools/trace/dump_state.py
+++ b/src/gallium/tools/trace/dump_state.py
@@ -33,6 +33,7 @@ import json
 import binascii
 import re
 import copy
+import argparse
 
 import model
 import parse as parser
@@ -705,7 +706,7 @@ class Context(Dispatcher):
         return so_target
 
 
-class Interpreter(parser.TraceDumper):
+class Interpreter(parser.TraceParser):
     '''Specialization of a trace parser that interprets the calls as it goes
     along.'''
     
@@ -722,7 +723,7 @@ class Interpreter(parser.TraceDumper):
     ))
 
     def __init__(self, stream, options):
-        parser.TraceDumper.__init__(self, stream, options, sys.stderr)
+        parser.TraceParser.__init__(self, stream)
         self.options = options
         self.objects = {}
         self.result = None
@@ -791,9 +792,12 @@ class Interpreter(parser.TraceDumper):
 class Main(parser.Main):
 
     def get_optparser(self):
-        '''Custom options.'''
+        optparser = argparse.ArgumentParser(
+            description="Parse and dump Gallium trace(s) as JSON")
+
+        optparser.add_argument("filename", action="extend", nargs="+",
+            type=str, metavar="filename", help="Gallium trace filename (plain or .gz, .bz2)")
 
-        optparser = parser.Main.get_optparser(self)
         optparser.add_argument("-v", "--verbose", action="count", default=0, dest="verbosity", help="increase verbosity level")
         optparser.add_argument("-q", "--quiet", action="store_const", const=0, dest="verbosity", help="no messages")
         optparser.add_argument("-c", "--call", action="store", type=int, dest="call", default=0xffffffff, help="dump on this call")
diff --git a/src/gallium/tools/trace/model.py b/src/gallium/tools/trace/model.py
index 913a4ef13d2..1cd3c18d987 100755
--- a/src/gallium/tools/trace/model.py
+++ b/src/gallium/tools/trace/model.py
@@ -44,7 +44,7 @@ class Node:
 
     def __str__(self):
         stream = StringIO()
-        formatter = format.DefaultFormatter(stream)
+        formatter = format.Formatter(stream)
         pretty_printer = PrettyPrinter(formatter)
         self.visit(pretty_printer)
         return stream.getvalue()
@@ -206,7 +206,7 @@ class PrettyPrinter:
     
     def visit_pointer(self, node):
         self.formatter.address(node.address)
-    
+
     def visit_call(self, node):
         self.formatter.text('%s ' % node.no)
         if node.klass is not None:
diff --git a/src/gallium/tools/trace/parse.py b/src/gallium/tools/trace/parse.py
index a529f389723..d25b0b258c6 100755
--- a/src/gallium/tools/trace/parse.py
+++ b/src/gallium/tools/trace/parse.py
@@ -355,7 +355,7 @@ class TraceDumper(TraceParser):
     
     def __init__(self, fp, options, outStream = sys.stdout):
         TraceParser.__init__(self, fp)
-        if options.plain:
+        if "plain" in options and options.plain:
             self.formatter = format.Formatter(outStream)
         else:
             self.formatter = format.DefaultFormatter(outStream)



More information about the mesa-commit mailing list