15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 package com.nokia.carbide.cpp.pi.peccommon; |
18 package com.nokia.carbide.cpp.pi.peccommon; |
19 |
19 |
|
20 import java.util.ArrayList; |
20 import java.util.Arrays; |
21 import java.util.Arrays; |
|
22 import java.util.List; |
21 import java.util.Vector; |
23 import java.util.Vector; |
22 |
24 |
23 import com.nokia.carbide.cpp.internal.pi.model.GenericSample; |
25 import com.nokia.carbide.cpp.internal.pi.model.GenericSample; |
24 import com.nokia.carbide.cpp.internal.pi.model.GenericSampledTrace; |
26 import com.nokia.carbide.cpp.internal.pi.model.GenericSampledTrace; |
|
27 import com.nokia.carbide.cpp.internal.pi.model.ICPUScale; |
25 |
28 |
26 /** |
29 /** |
27 * The model class for Performance Counter traces. This manages the data |
30 * The model class for Performance Counter traces. This manages the data |
28 * for the IPC trace graphs, and is responsible for creating the graphs. |
31 * for the IPC trace graphs, and is responsible for creating the graphs. |
29 */ |
32 */ |
30 public class PecCommonTrace extends GenericSampledTrace { |
33 public class PecCommonTrace extends GenericSampledTrace implements ICPUScale{ |
31 private static final long serialVersionUID = 4425739452429422333L; |
34 private static final long serialVersionUID = 4425739452429422333L; |
32 |
35 |
33 private int samplingInterval; |
36 private int samplingInterval; |
34 |
37 |
35 /** |
38 /** |
42 // If this assumption ever changes, the calculations need to be moved into |
45 // If this assumption ever changes, the calculations need to be moved into |
43 // the LegendContentProvider |
46 // the LegendContentProvider |
44 private double selectionStart; |
47 private double selectionStart; |
45 private double selectionEnd; |
48 private double selectionEnd; |
46 private transient boolean needsRecalc; |
49 private transient boolean needsRecalc; |
|
50 |
|
51 private int cpuClockRate; |
47 |
52 |
48 private transient PecCommonLegendElement[] legendElements; |
53 private transient PecCommonLegendElement[] legendElements; |
49 |
54 |
50 /** |
55 /** |
51 * Constructor |
56 * Constructor |
184 les[i] = legendElement; |
189 les[i] = legendElement; |
185 shortTitle ++; |
190 shortTitle ++; |
186 } |
191 } |
187 return les; |
192 return les; |
188 } |
193 } |
|
194 |
|
195 |
|
196 /* |
|
197 * (non-Javadoc) |
|
198 * @see com.nokia.carbide.cpp.internal.pi.model.ICPUScale#calculateScale(int) |
|
199 */ |
|
200 public float calculateScale(int sampleSynchTime) { |
|
201 if (cpuClockRate <= 0) { |
|
202 return 1; |
|
203 } |
|
204 GenericSample genericSample = null; |
|
205 if((samples.size() - 1) >= sampleSynchTime){ |
|
206 genericSample = samples.get(sampleSynchTime); |
|
207 }else{ |
|
208 genericSample = samples.lastElement(); |
|
209 } |
|
210 if (genericSample instanceof PecCommonSample) { |
|
211 int[] values = ((PecCommonSample) genericSample).values; |
|
212 return (float) values[4] / cpuClockRate; |
|
213 } |
|
214 return 1; |
|
215 |
|
216 } |
|
217 |
|
218 /* |
|
219 * (non-Javadoc) |
|
220 * @see com.nokia.carbide.cpp.internal.pi.model.ICPUScale#calculateScale(int, int) |
|
221 */ |
|
222 public float calculateScale(int startSynchTime, int endSynchTime) { |
|
223 if (cpuClockRate <= 0) { |
|
224 return 1; |
|
225 } |
|
226 if(startSynchTime > endSynchTime){ |
|
227 return 1; |
|
228 } |
|
229 List<Float> sampleList = new ArrayList<Float>(); |
|
230 while(startSynchTime <= endSynchTime ){ |
|
231 GenericSample genericSample = null; |
|
232 if((samples.size() - 1) >= endSynchTime){ |
|
233 genericSample = samples.get(endSynchTime); |
|
234 }else{ |
|
235 genericSample = samples.lastElement(); |
|
236 } |
|
237 if (genericSample instanceof PecCommonSample) { |
|
238 int[] values = ((PecCommonSample) genericSample).values; |
|
239 float cpuSampleClockRate = (float) values[4] / cpuClockRate; |
|
240 sampleList.add(cpuSampleClockRate); |
|
241 } |
|
242 startSynchTime += 100; |
|
243 } |
|
244 if(sampleList.size() > 0){ |
|
245 float sum = 0; |
|
246 for(float value : sampleList){ |
|
247 sum += value; |
|
248 } |
|
249 return sum / sampleList.size(); |
|
250 }else{ |
|
251 return 1; |
|
252 } |
|
253 } |
|
254 |
|
255 /** |
|
256 * @param cpuClockRate the cpuClockRate to set |
|
257 */ |
|
258 public void setCpuClockRate(int cpuClockRate) { |
|
259 this.cpuClockRate = cpuClockRate; |
|
260 } |
|
261 |
|
262 /* |
|
263 * (non-Javadoc) |
|
264 * @see com.nokia.carbide.cpp.internal.pi.model.ICPUScale#isCpuScaleSupported() |
|
265 */ |
|
266 public boolean isCpuScaleSupported(){ |
|
267 if(cpuClockRate > 0){ |
|
268 return true; |
|
269 }else{ |
|
270 return false; |
|
271 } |
|
272 } |
|
273 |
|
274 |
189 } |
275 } |