if hasattr(self, 'type'):
print >>ini_file, 'type=%s' % self.type
- child_names = self._children.keys()
- child_names.sort()
- if len(child_names):
+ if len(self._children.keys()):
print >>ini_file, 'children=%s' % \
- ' '.join(self._children[n].get_name() for n in child_names)
+ ' '.join(self._children[n].get_name() \
+ for n in sorted(self._children.keys()))
- param_names = self._params.keys()
- param_names.sort()
- for param in param_names:
+ for param in sorted(self._params.keys()):
value = self._values.get(param)
if value != None:
print >>ini_file, '%s=%s' % (param,
self._values[param].ini_str())
- port_names = self._ports.keys()
- port_names.sort()
- for port_name in port_names:
+ for port_name in sorted(self._ports.keys()):
port = self._port_refs.get(port_name, None)
if port != None:
print >>ini_file, '%s=%s' % (port_name, port.ini_str())
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_config_as_dict(self):
+ d = attrdict()
+ if hasattr(self, 'type'):
+ d.type = self.type
+ if hasattr(self, 'cxx_class'):
+ d.cxx_class = self.cxx_class
+
+ for param in sorted(self._params.keys()):
+ value = self._values.get(param)
+ try:
+ d[param] = self._values[param].value
+ except AttributeError:
+ pass
+
+ for n in sorted(self._children.keys()):
+ d[self._children[n].get_name()] = self._children[n].get_config_as_dict()
+
+ for port_name in sorted(self._ports.keys()):
+ 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
group("Configuration Options")
option("--dump-config", metavar="FILE", default="config.ini",
help="Dump configuration output file [Default: %default]")
+ option("--json-config", metavar="FILE", default="config.json",
+ help="Create JSON output of the configuration [Default: %default]")
# Debugging options
group("Debugging Options")
for obj in v.descendants():
yield obj
+ def get_config_as_dict(self):
+ a = []
+ for v in self:
+ a.append(v.get_config_as_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.
def ini_str(self):
return str(self)
+ def get_config_as_dict(self):
+ return str(self)
+
# Enumerated types are a little more complex. The user specifies the
# type as Enum(foo) where foo is either a list or dictionary of
# alternatives (typically strings, but not necessarily so). (In the
import atexit
import os
import sys
+import json
# import the SWIG-wrapped main C++ functions
import internal
import ticks
import objects
from util import fatal
+from util import attrdict
# define a MaxTick parameter
MaxTick = 2**63 - 1
obj.print_ini(ini_file)
ini_file.close()
+ if options.json_config:
+ json_file = file(os.path.join(options.outdir, options.json_config), 'w')
+ d = root.get_config_as_dict()
+ json.dump(d, json_file, indent=4)
+ json_file.close()
+
+
# Initialize the global statistics
stats.initSimStats()