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 binascii
|
||||||
import re
|
import re
|
||||||
import copy
|
import copy
|
||||||
|
import argparse
|
||||||
|
|
||||||
import model
|
import model
|
||||||
import parse as parser
|
import parse as parser
|
||||||
|
@ -705,7 +706,7 @@ class Context(Dispatcher):
|
||||||
return so_target
|
return so_target
|
||||||
|
|
||||||
|
|
||||||
class Interpreter(parser.TraceDumper):
|
class Interpreter(parser.TraceParser):
|
||||||
'''Specialization of a trace parser that interprets the calls as it goes
|
'''Specialization of a trace parser that interprets the calls as it goes
|
||||||
along.'''
|
along.'''
|
||||||
|
|
||||||
|
@ -722,7 +723,7 @@ class Interpreter(parser.TraceDumper):
|
||||||
))
|
))
|
||||||
|
|
||||||
def __init__(self, stream, options):
|
def __init__(self, stream, options):
|
||||||
parser.TraceDumper.__init__(self, stream, options, sys.stderr)
|
parser.TraceParser.__init__(self, stream)
|
||||||
self.options = options
|
self.options = options
|
||||||
self.objects = {}
|
self.objects = {}
|
||||||
self.result = None
|
self.result = None
|
||||||
|
@ -791,9 +792,12 @@ class Interpreter(parser.TraceDumper):
|
||||||
class Main(parser.Main):
|
class Main(parser.Main):
|
||||||
|
|
||||||
def get_optparser(self):
|
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("-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("-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")
|
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):
|
def __str__(self):
|
||||||
stream = StringIO()
|
stream = StringIO()
|
||||||
formatter = format.DefaultFormatter(stream)
|
formatter = format.Formatter(stream)
|
||||||
pretty_printer = PrettyPrinter(formatter)
|
pretty_printer = PrettyPrinter(formatter)
|
||||||
self.visit(pretty_printer)
|
self.visit(pretty_printer)
|
||||||
return stream.getvalue()
|
return stream.getvalue()
|
||||||
|
|
|
@ -355,7 +355,7 @@ class TraceDumper(TraceParser):
|
||||||
|
|
||||||
def __init__(self, fp, options, outStream = sys.stdout):
|
def __init__(self, fp, options, outStream = sys.stdout):
|
||||||
TraceParser.__init__(self, fp)
|
TraceParser.__init__(self, fp)
|
||||||
if options.plain:
|
if "plain" in options and options.plain:
|
||||||
self.formatter = format.Formatter(outStream)
|
self.formatter = format.Formatter(outStream)
|
||||||
else:
|
else:
|
||||||
self.formatter = format.DefaultFormatter(outStream)
|
self.formatter = format.DefaultFormatter(outStream)
|
||||||
|
|
Loading…
Reference in New Issue