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@tnsp.org> Acked-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10648>
This commit is contained in:
parent
a6765412fe
commit
0834a42773
|
@ -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")
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue