dol: initial dol commit
[jump.git] / dol / src / dol / helper / profiler / ProcessProfile.java
1 /* $Id: ProcessProfile.java 203 2010-10-11 08:59:47Z dchokshi $ */\r
2 package dol.helper.profiler;\r
3 \r
4 import java.util.HashMap;\r
5 import java.util.Iterator;\r
6 \r
7 /**\r
8  * Functional simulation profile information for a process.\r
9  */\r
10 public class ProcessProfile {\r
11 \r
12     /** \r
13      * Constructor.\r
14      * \r
15      * @param name name of the process this profile belongs to \r
16      */\r
17     public ProcessProfile(String name) {\r
18         _name = name;\r
19         _portProfiles = new HashMap<String, PortProfile>();\r
20     }\r
21 \r
22     /**\r
23      * Indicate that the process has entered fire().\r
24      */\r
25     public void start() {\r
26         _started = true;\r
27         _numOfFires++;\r
28     }\r
29     \r
30     /**\r
31      * Indicate that the process has leaved fire().\r
32      */\r
33     public void stop() {\r
34         if (!_started) {\r
35             return;\r
36         }\r
37         \r
38         _started = false;\r
39 \r
40         Iterator<String> iterator = _portProfiles.keySet().iterator();\r
41 \r
42         while (iterator.hasNext()) {\r
43             PortProfile profile = _portProfiles.get(iterator.next());\r
44             profile.update();\r
45         }\r
46     }\r
47    \r
48     /**\r
49      * Indicate a read or write access to a port.\r
50      * \r
51      * @param port the accessed port\r
52      * @param amount number of bytes communicated\r
53      */\r
54     public void portAccess(String port, int amount) {\r
55         if (_portProfiles.get(port) == null) {\r
56             PortProfile profile = new PortProfile(port, this);\r
57             _portProfiles.put(port, profile);\r
58         }\r
59         if (_started) {\r
60             _portProfiles.get(port).addAccess(amount);\r
61         } else {\r
62             _portProfiles.get(port).addInitialAccess(amount);\r
63         }\r
64     }\r
65     \r
66     /**\r
67      * Return the number of firings.\r
68      *\r
69      * @return the number of fire() calls of a process.\r
70      **/\r
71     public int getNumOfFires() {\r
72         return _numOfFires;\r
73     }\r
74     \r
75     /**\r
76      * Return the name of the process this profile belongs to.\r
77      * \r
78      * @return name of the process this profile belongs to\r
79      */\r
80     public String getName() {\r
81         return _name;\r
82     }\r
83 \r
84     /**\r
85      * Return the profiles of all ports.\r
86      * \r
87      * @return profile of all ports\r
88      */\r
89     public HashMap<String, PortProfile> getPortProfiles() {\r
90         return _portProfiles;\r
91     }\r
92     \r
93     protected String _name;\r
94     boolean _started = false;\r
95     protected int _numOfFires = 0;\r
96     HashMap<String, PortProfile> _portProfiles;\r
97 }\r