diff --git a/src/gallium/tools/trace/dump_state.py b/src/gallium/tools/trace/dump_state.py index 5683034a14d..366637b5678 100755 --- a/src/gallium/tools/trace/dump_state.py +++ b/src/gallium/tools/trace/dump_state.py @@ -789,6 +789,18 @@ class Interpreter(parser.SimpleTraceDumper): return self.options.verbosity >= level +class DumpStateOptions(parser.ParseOptions): + + def __init__(self, args=None): + + # These will get initialized in ModelOptions.__init__() + self.verbosity = None + self.call = None + self.draw = None + + parser.ParseOptions.__init__(self, args) + + class Main(parser.Main): def get_optparser(self): @@ -804,6 +816,9 @@ class Main(parser.Main): optparser.add_argument("-d", "--draw", action="store", type=int, dest="draw", default=0xffffffff, help="dump on this draw") return optparser + def make_options(self, args): + return DumpStateOptions(args) + def process_arg(self, stream, options): formatter = format.Formatter(sys.stderr) parser = Interpreter(stream, options, formatter) diff --git a/src/gallium/tools/trace/model.py b/src/gallium/tools/trace/model.py index 8350daf744b..943f97b8c1a 100755 --- a/src/gallium/tools/trace/model.py +++ b/src/gallium/tools/trace/model.py @@ -37,6 +37,25 @@ from io import StringIO import format +class ModelOptions: + + def __init__(self, args=None): + # Initialize the options we need to exist, + # with some reasonable defaults + self.plain = False + self.suppress_variants = False + self.named_ptrs = False + self.method_only = False + + # If args is specified, we assume it is the result object + # from ArgumentParser.parse_args(). Copy the attribute values + # we have from it, if they exist. + if args is not None: + for var in self.__dict__: + if var in args.__dict__: + self.__dict__[var] = args.__dict__[var] + + class Node: def visit(self, visitor): @@ -238,7 +257,7 @@ class PrettyPrinter: self.formatter.text('}') def visit_pointer(self, node): - if "named_ptrs" in self.options and self.options.named_ptrs: + if self.options.named_ptrs: self.formatter.address(node.ptr_list[node.address]) else: self.formatter.address(node.address) diff --git a/src/gallium/tools/trace/parse.py b/src/gallium/tools/trace/parse.py index cbf6896f9df..8afba7c51a4 100755 --- a/src/gallium/tools/trace/parse.py +++ b/src/gallium/tools/trace/parse.py @@ -382,7 +382,16 @@ class TraceDumper(SimpleTraceDumper): for call in self.call_stack: call.visit(self.pretty_printer) self.formatter.newline() - + + +class ParseOptions(ModelOptions): + + def __init__(self, args=None): + # Initialize options local to this module + self.plain = False + + ModelOptions.__init__(self, args) + class Main: '''Common main class for all retrace command line utilities.''' @@ -393,6 +402,7 @@ class Main: def main(self): optparser = self.get_optparser() args = optparser.parse_args() + options = self.make_options(args) for fname in args.filename: try: @@ -408,7 +418,10 @@ class Main: print("ERROR: {}".format(str(e))) sys.exit(1) - self.process_arg(stream, args) + self.process_arg(stream, options) + + def make_options(self, args): + return ParseOptions(args) def get_optparser(self): optparser = argparse.ArgumentParser(