diff -r ca98021c3f96 -r 7d60c819e420 src/python/m5/SimObject.py --- a/src/python/m5/SimObject.py Thu Dec 15 00:43:35 2011 -0500 +++ b/src/python/m5/SimObject.py Fri Dec 16 15:30:47 2011 -0600 @@ -897,6 +897,43 @@ print >>ini_file # blank line between objects + # generate a tree of dictionaries expressing all the parameters in the + # instantiated system for use by scripts that want to do power, thermal + # visualization, and other similar tasks + def get_dict(self): + d = attrdict() + if hasattr(self, 'type'): + d.type = self.type + if hasattr(self, 'cxx_class'): + d.cxx_class = self.cxx_class + + param_names = self._params.keys() + param_names.sort() + for param in param_names: + value = self._values.get(param) + try: + d[param] = self._values[param].value + except AttributeError: + pass + + child_names = self._children.keys() + child_names.sort() + for n in child_names: + d[self._children[n].get_name()] = self._children[n].get_dict() + + port_names = self._ports.keys() + port_names.sort() + for port_name in port_names: + port = self._port_refs.get(port_name, None) + if port != None: + # Might want to actually make this reference the object + # in the future, although execing the string problem would + # get some of the way there + d[port_name] = port.ini_str() + + + return d + def getCCParams(self): if self._ccParams: return self._ccParams diff -r ca98021c3f96 -r 7d60c819e420 src/python/m5/main.py --- a/src/python/m5/main.py Thu Dec 15 00:43:35 2011 -0500 +++ b/src/python/m5/main.py Fri Dec 16 15:30:47 2011 -0600 @@ -87,6 +87,8 @@ group("Configuration Options") option("--dump-config", metavar="FILE", default="config.ini", help="Dump configuration output file [Default: %default]") + option("--pkl-config", metavar="FILE", default="config.pkl", + help="Create a Python pickle of the configuration [Default: %default]") # Debugging options group("Debugging Options") diff -r ca98021c3f96 -r 7d60c819e420 src/python/m5/params.py --- a/src/python/m5/params.py Thu Dec 15 00:43:35 2011 -0500 +++ b/src/python/m5/params.py Fri Dec 16 15:30:47 2011 -0600 @@ -228,6 +228,12 @@ for obj in v.descendants(): yield obj + def get_dict(self): + a = [] + for v in self: + a.append(v.get_dict()) + return a + class VectorParamDesc(ParamDesc): # Convert assigned value to appropriate type. If the RHS is not a # list or tuple, it generates a single-element list. diff -r ca98021c3f96 -r 7d60c819e420 src/python/m5/simulate.py --- a/src/python/m5/simulate.py Thu Dec 15 00:43:35 2011 -0500 +++ b/src/python/m5/simulate.py Fri Dec 16 15:30:47 2011 -0600 @@ -31,6 +31,7 @@ import atexit import os import sys +import pickle # import the SWIG-wrapped main C++ functions import internal @@ -40,6 +41,7 @@ import ticks import objects from util import fatal +from util import attrdict # define a MaxTick parameter MaxTick = 2**63 - 1 @@ -71,6 +73,16 @@ obj.print_ini(ini_file) ini_file.close() + if options.pkl_config: + pkl_file = file(os.path.join(options.outdir, options.pkl_config), 'w') + # Print ini sections in sorted order for easier diffing + d = attrdict() + for obj in sorted(root.descendants(), key=lambda o: o.path()): + d[obj.path()] = obj.get_dict() + pickle.dump(d, pkl_file) + pkl_file.close() + + # Initialize the global statistics stats.initSimStats()