changeset a20f46ccb9ce in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=a20f46ccb9ce
description:
        Config: Use the attribute naming and include ports in JSON

        This patch changes the organisation of the JSON output slightly to
        make it easier to traverse and use the files. Most importantly, the
        hierarchical dictionaries now use keys that correspond to the
        attribute names also in the case of VectorParams (used to be
        e.f. "cpu0 cpu1"). It also adds the name and the path to each
        SimObject directory entry. Before this patch, to get cpu0, you would
        have to query dict['system']['cpu0 cpu1'][0] and this could be a dict
        with 'cpu0' : { cpu parameters }. Now you use dict['system']['cpu'][0]
        and get { cpu parameters } (where one is "name" : "cpu0").

        Additionally this patch includes more verbose information about the
        ports, specifying their role, and using a JSON array rather than a
        concatenated string for the peer.

diffstat:

 src/python/m5/SimObject.py |  17 ++++++++++++-----
 src/python/m5/params.py    |   9 +++++++++
 2 files changed, 21 insertions(+), 5 deletions(-)

diffs (64 lines):

diff -r 18093957a102 -r a20f46ccb9ce src/python/m5/SimObject.py
--- a/src/python/m5/SimObject.py        Wed May 23 09:15:45 2012 -0400
+++ b/src/python/m5/SimObject.py        Wed May 23 09:16:39 2012 -0400
@@ -931,6 +931,10 @@
             d.type = self.type
         if hasattr(self, 'cxx_class'):
             d.cxx_class = self.cxx_class
+        # Add the name and path of this object to be able to link to
+        # the stats
+        d.name = self.get_name()
+        d.path = self.path()
 
         for param in sorted(self._params.keys()):
             value = self._values.get(param)
@@ -949,15 +953,18 @@
                     pass
 
         for n in sorted(self._children.keys()):
-            d[self._children[n].get_name()] =  
self._children[n].get_config_as_dict()
+            child = self._children[n]
+            # Use the name of the attribute (and not get_name()) as
+            # the key in the JSON dictionary to capture the hierarchy
+            # in the Python code that assembled this system
+            d[n] = child.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()
+                # Represent each port with a dictionary containing the
+                # prominent attributes
+                d[port_name] = port.get_config_as_dict()
 
         return d
 
diff -r 18093957a102 -r a20f46ccb9ce src/python/m5/params.py
--- a/src/python/m5/params.py   Wed May 23 09:15:45 2012 -0400
+++ b/src/python/m5/params.py   Wed May 23 09:16:39 2012 -0400
@@ -1363,6 +1363,10 @@
     def ini_str(self):
         return str(self.peer)
 
+    # for config.json
+    def get_config_as_dict(self):
+        return {'role' : self.role, 'peer' : str(self.peer)}
+
     def __getattr__(self, attr):
         if attr == 'peerObj':
             # shorthand for proxies
@@ -1480,6 +1484,11 @@
     def ini_str(self):
         return ' '.join([el.ini_str() for el in self.elements])
 
+    # for config.json
+    def get_config_as_dict(self):
+        return {'role' : self.role,
+                'peer' : [el.ini_str() for el in self.elements]}
+
     def __getitem__(self, key):
         if not isinstance(key, int):
             raise TypeError, "VectorPort index must be integer"
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to