dol: initial dol commit
[jump.git] / dol / src / dol / helper / profiler / ProcessProfile.java
diff --git a/dol/src/dol/helper/profiler/ProcessProfile.java b/dol/src/dol/helper/profiler/ProcessProfile.java
new file mode 100644 (file)
index 0000000..f8e51a8
--- /dev/null
@@ -0,0 +1,97 @@
+/* $Id: ProcessProfile.java 203 2010-10-11 08:59:47Z dchokshi $ */\r
+package dol.helper.profiler;\r
+\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+\r
+/**\r
+ * Functional simulation profile information for a process.\r
+ */\r
+public class ProcessProfile {\r
+\r
+    /** \r
+     * Constructor.\r
+     * \r
+     * @param name name of the process this profile belongs to \r
+     */\r
+    public ProcessProfile(String name) {\r
+        _name = name;\r
+        _portProfiles = new HashMap<String, PortProfile>();\r
+    }\r
+\r
+    /**\r
+     * Indicate that the process has entered fire().\r
+     */\r
+    public void start() {\r
+        _started = true;\r
+        _numOfFires++;\r
+    }\r
+    \r
+    /**\r
+     * Indicate that the process has leaved fire().\r
+     */\r
+    public void stop() {\r
+        if (!_started) {\r
+            return;\r
+        }\r
+        \r
+        _started = false;\r
+\r
+        Iterator<String> iterator = _portProfiles.keySet().iterator();\r
+\r
+        while (iterator.hasNext()) {\r
+            PortProfile profile = _portProfiles.get(iterator.next());\r
+            profile.update();\r
+        }\r
+    }\r
+   \r
+    /**\r
+     * Indicate a read or write access to a port.\r
+     * \r
+     * @param port the accessed port\r
+     * @param amount number of bytes communicated\r
+     */\r
+    public void portAccess(String port, int amount) {\r
+        if (_portProfiles.get(port) == null) {\r
+            PortProfile profile = new PortProfile(port, this);\r
+            _portProfiles.put(port, profile);\r
+        }\r
+        if (_started) {\r
+            _portProfiles.get(port).addAccess(amount);\r
+        } else {\r
+            _portProfiles.get(port).addInitialAccess(amount);\r
+        }\r
+    }\r
+    \r
+    /**\r
+     * Return the number of firings.\r
+     *\r
+     * @return the number of fire() calls of a process.\r
+     **/\r
+    public int getNumOfFires() {\r
+        return _numOfFires;\r
+    }\r
+    \r
+    /**\r
+     * Return the name of the process this profile belongs to.\r
+     * \r
+     * @return name of the process this profile belongs to\r
+     */\r
+    public String getName() {\r
+        return _name;\r
+    }\r
+\r
+    /**\r
+     * Return the profiles of all ports.\r
+     * \r
+     * @return profile of all ports\r
+     */\r
+    public HashMap<String, PortProfile> getPortProfiles() {\r
+        return _portProfiles;\r
+    }\r
+    \r
+    protected String _name;\r
+    boolean _started = false;\r
+    protected int _numOfFires = 0;\r
+    HashMap<String, PortProfile> _portProfiles;\r
+}\r