4de3cc77cc843d26c0d9359635b1f49bf0f3cad1
[jump.git] / dol / src / dol / helper / profiler / ChannelProfile.java
1 /* $Id: ChannelProfile.java 203 2010-10-11 08:59:47Z dchokshi $ */\r
2 package dol.helper.profiler;\r
3 \r
4 /**\r
5  * Functional simulation profile information for a channel.\r
6  */\r
7 public class ChannelProfile {\r
8 \r
9     /**\r
10      * Constructor.\r
11      *\r
12      * @param name name of the channel this profile belongs to\r
13      * @param capacity capacity of this channel\r
14      */\r
15     public ChannelProfile(String name, int capacity) {\r
16         _name = name;\r
17         _capacity = capacity;\r
18     }\r
19 \r
20     /**\r
21      * Adds a read access. Reduces the fifo fill level accordingly. If the\r
22      * amount is larger than the current fifo size, the read is blocking.\r
23      * \r
24      * @param amount The amount of data in bytes.\r
25      */\r
26     public void readAccess(int amount) {\r
27         _numOfReads++;\r
28         _totalReadData += amount;\r
29 \r
30         if (amount > _maxReadChunk)\r
31             _maxReadChunk = amount;\r
32 \r
33         if (amount < _minReadChunk)\r
34             _minReadChunk = amount;\r
35 \r
36         if (_fillLevel < amount) {\r
37             _numOfBlockingReads++;\r
38             _blockedReadSize = amount;\r
39         }\r
40         else {\r
41             _fillLevel -= amount;\r
42         }\r
43     }\r
44 \r
45     /**\r
46      * Adds a write access. Enlarges the fifo size accordingly. If the\r
47      * amount plus the current size of the fifo is larger than the\r
48      * capacity, an overflow occurs (blocking write).\r
49      *\r
50      * @param amount The amount of data in bytes.\r
51      */\r
52     public void writeAccess(int amount) {\r
53         _numOfWrites++;\r
54         if (_fillLevel + amount > _capacity) {\r
55             _numOfBlockingWrites++;\r
56         }\r
57 \r
58         _fillLevel += amount;\r
59 \r
60         if (amount > _maxWriteChunk)\r
61             _maxWriteChunk = amount;\r
62 \r
63         if (amount < _minWriteChunk)\r
64             _minWriteChunk = amount;\r
65 \r
66         if (_fillLevel > _maxFillLevel)\r
67             _maxFillLevel = _fillLevel;\r
68 \r
69 \r
70         if ((_fillLevel >= _blockedReadSize) && (_blockedReadSize != 0)) {\r
71             _fillLevel -= _blockedReadSize;\r
72             _blockedReadSize = 0;\r
73         }\r
74     }\r
75 \r
76     /**\r
77      * Returns the maximum amount of data stored in the fifo.\r
78      * \r
79      * @return Maximum fill level in bytes.\r
80      */\r
81     public int getMaxFillLevel() {\r
82         return _maxFillLevel;\r
83     }\r
84 \r
85     /**\r
86      * Returns the size of the largest chunk of data read in a single\r
87      * read access.\r
88      * \r
89      * @return Size of the largest read chunk in bytes.\r
90      */\r
91     public int getMaxReadChunk() {\r
92         return _maxReadChunk;\r
93     }\r
94 \r
95     /**\r
96      * Returns the size of the smallest chunk of data read in a single\r
97      * read access.\r
98      * \r
99      * @return Size of the smallest read chunk in bytes.\r
100      */\r
101     public int getMinReadChunk() {\r
102         return _minReadChunk;\r
103     }\r
104 \r
105     /**\r
106      * Returns the size of the largest chunk of data written in a single\r
107      * write access.\r
108      * \r
109      * @return Size of the largest written chunk in bytes.\r
110      */\r
111     public int getMaxWriteChunk() {\r
112         return _maxWriteChunk;\r
113     }\r
114 \r
115     /**\r
116      * Returns the size of the smallest chunk of data written in a single\r
117      * write access.\r
118      * \r
119      * @return Size of the smallest written chunk in bytes.\r
120      */\r
121     public int getMinWriteChunk() {\r
122         return _minWriteChunk;\r
123     }\r
124 \r
125     /**\r
126      * Returns the number of total read accesses.\r
127      * \r
128      * @return Number of total read accesses.\r
129      */\r
130     public int getNumOfReads() {\r
131         return _numOfReads;\r
132     }\r
133 \r
134     /**\r
135      * Returns the number of total blocking reads.\r
136      * A blocking read occurs whenever there is an attempt to read more\r
137      * data from the fifo than the fifo contains.\r
138      * \r
139      * @return Number of total blocking reads\r
140      */\r
141     public int getNumOfBlockingReads() {\r
142         return _numOfBlockingReads;\r
143     }\r
144 \r
145     /**\r
146      * Returns the total number of write accesses.\r
147      * \r
148      * @return Number of total write accesses.\r
149      */\r
150     public int getNumOfWrites() {\r
151         return _numOfWrites;\r
152     }\r
153 \r
154     /**\r
155      * Returns the number of total blocking writes.\r
156      * A blocking write occurs, whenever a write access tries to write\r
157      * more data into the fifo than its capacity allows.\r
158      * \r
159      * @return Number of total overflows.\r
160      */\r
161     public int getNumOfOverflows() {\r
162         return _numOfBlockingWrites;\r
163     }\r
164 \r
165     /**\r
166      * Returns the percentage of read accesses which were blocking.\r
167      * @return Percentage of blocking reads\r
168      */\r
169     public int getBlockingReadsPercentage() {\r
170         if (_numOfReads == 0)\r
171             return 0;\r
172         \r
173         return (_numOfBlockingReads * 100) / (_numOfReads);\r
174     }\r
175     /**\r
176      * Returns the percentage of write accesses, which led to an overflow.\r
177      * @return Percentage of overflows.\r
178      */\r
179     public int getBlockingWritesPercentage() {\r
180         if (_numOfWrites == 0)\r
181             return 0;\r
182         \r
183         return (_numOfBlockingWrites * 100) / (_numOfWrites);\r
184     }\r
185     \r
186     /**\r
187      * Returns the total amount of read data (in bytes).\r
188      * @return Amount in bytes.\r
189      */\r
190     public long getTotalReadData() {\r
191         return _totalReadData;\r
192     }\r
193 \r
194     /**\r
195      * Return the name of the channel this profile belongs to.\r
196      * \r
197      * @return name of the channel this profile belongs to\r
198      */\r
199     public String getName() {\r
200         return _name;\r
201     }\r
202 \r
203 \r
204     protected String _name = "";\r
205     protected int _capacity = 0;\r
206 \r
207     protected long _totalReadData = 0;\r
208     protected int _fillLevel = 0;\r
209     protected int _maxFillLevel = 0;\r
210 \r
211     protected int _numOfReads = 0;\r
212     protected int _numOfBlockingReads = 0;\r
213     protected int _maxReadChunk = 0;\r
214     protected int _minReadChunk = Integer.MAX_VALUE;\r
215     protected int _blockedReadSize = 0;\r
216 \r
217     protected int _numOfWrites = 0;\r
218     protected int _numOfBlockingWrites = 0;\r
219     protected int _maxWriteChunk = 0;\r
220     protected int _minWriteChunk = Integer.MAX_VALUE;\r
221 }\r