|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include <test/TestExecuteStepBase.h> |
|
23 #include <hal.h> |
|
24 #include "tprofiler.h" |
|
25 |
|
26 |
|
27 #define PROFILER_TEST(a) (iTestStep.testBooleanTrue((a), (TText8*)__FILE__, __LINE__)) |
|
28 |
|
29 |
|
30 #define PROFILER_INFO_PRINTF1(p1) iTestStep.Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1)) |
|
31 #define PROFILER_INFO_PRINTF2(p1, p2) iTestStep.Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2)) |
|
32 #define PROFILER_INFO_PRINTF3(p1, p2, p3) iTestStep.Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3)) |
|
33 #define PROFILER_INFO_PRINTF4(p1, p2, p3, p4) iTestStep.Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4)) |
|
34 #define PROFILER_INFO_PRINTF5(p1, p2, p3, p4, p5) iTestStep.Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5)) |
|
35 #define PROFILER_INFO_PRINTF6(p1, p2, p3, p4, p5, p6) iTestStep.Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5), (p6)) |
|
36 #define PROFILER_INFO_PRINTF7(p1, p2, p3, p4, p5, p6, p7) iTestStep.Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7)) |
|
37 |
|
38 #define PROFILER_ERR_PRINTF1(p1) iTestStep.Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, (p1)) |
|
39 #define PROFILER_ERR_PRINTF2(p1, p2) iTestStep.Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2)) |
|
40 #define PROFILER_ERR_PRINTF3(p1, p2, p3) iTestStep.Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3)) ; |
|
41 #define PROFILER_ERR_PRINTF4(p1, p2, p3, p4) iTestStep.Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3), (p4)) |
|
42 #define PROFILER_ERR_PRINTF5(p1, p2, p3, p4, p5) iTestStep.Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3), (p4), (p5)) |
|
43 #define PROFILER_ERR_PRINTF6(p1, p2, p3, p4, p5, p6) iTestStep.Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3), (p4), (p5), (p6)) |
|
44 #define PROFILER_ERR_PRINTF7(p1, p2, p3, p4, p5, p6, p7) iTestStep.Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3), (p4), (p5), (p6), (p7)) |
|
45 |
|
46 |
|
47 CTProfiler::CTProfiler(CTestStep& aTestStep) : |
|
48 iTestStep(aTestStep) |
|
49 { |
|
50 } |
|
51 |
|
52 EXPORT_C CTProfiler::~CTProfiler() |
|
53 { |
|
54 iResults.Reset(); |
|
55 } |
|
56 |
|
57 EXPORT_C CTProfiler* CTProfiler::NewL(CTestStep& aTestStep) |
|
58 { |
|
59 CTProfiler* profiler = new (ELeave) CTProfiler(aTestStep); |
|
60 CleanupStack::PushL(profiler); |
|
61 profiler->ConstructL(); |
|
62 CleanupStack::Pop(); |
|
63 return profiler; |
|
64 } |
|
65 |
|
66 void CTProfiler::ConstructL() |
|
67 { |
|
68 User::LeaveIfError((HAL::Get(HALData::EFastCounterFrequency, iFreq))); |
|
69 PROFILER_INFO_PRINTF2(_L("FastCounterFrequency: %i Hz"), iFreq); |
|
70 |
|
71 if(iFreq == 0) |
|
72 { |
|
73 User::Leave(KErrDivideByZero); |
|
74 } |
|
75 } |
|
76 |
|
77 EXPORT_C void CTProfiler::StartTimer() |
|
78 { |
|
79 iStart = User::FastCounter(); |
|
80 } |
|
81 |
|
82 EXPORT_C TInt64 CTProfiler::StopTimer() |
|
83 { |
|
84 iEnd = User::FastCounter(); |
|
85 // wrap around automatically dealt with by two's complement arithmetic as long as all variables are unsigned int |
|
86 iDiff += iEnd - iStart; |
|
87 TInt64 difftime = (1000000*(TInt64)iDiff) / (TInt64)iFreq; |
|
88 return difftime; |
|
89 } |
|
90 |
|
91 /** |
|
92 Initalises the results. Must be called before MarkResultSet |
|
93 */ |
|
94 EXPORT_C void CTProfiler::InitResults() |
|
95 { |
|
96 PROFILER_TEST(!iResultsInitalised); |
|
97 iResultsInitalised = ETrue; |
|
98 iDiff = 0; |
|
99 iResults.Reset(); |
|
100 |
|
101 StartTimer(); |
|
102 } |
|
103 |
|
104 /** |
|
105 Records set current time. Can be called multiple times so an average can be taken. |
|
106 */ |
|
107 EXPORT_C void CTProfiler::MarkResultSetL() |
|
108 { |
|
109 iResults.InsertInUnsignedKeyOrderAllowRepeatsL((TUint32)StopTimer()); |
|
110 iDiff = 0; |
|
111 PROFILER_TEST(iResultsInitalised); |
|
112 StartTimer(); |
|
113 } |
|
114 |
|
115 /** |
|
116 Frees all memory allocated by results capturing methods like MarkResultSetL(). |
|
117 */ |
|
118 EXPORT_C void CTProfiler::FreeResultsMemory() |
|
119 { |
|
120 iResults.Reset(); |
|
121 } |
|
122 |
|
123 /** |
|
124 Returns the trimmed mean of a set of results. i.e. Trims off the 20% smallest and the 20% largest of the data results. |
|
125 */ |
|
126 EXPORT_C TUint32 CTProfiler::GetTrimedMean() |
|
127 { |
|
128 TInt64 total = 0; |
|
129 if (iResults.Count() <= 50) |
|
130 PROFILER_ERR_PRINTF2(_L("Not enough results for trimming - need more than 50, but got %d"), iResults.Count()); |
|
131 if (iResults.Count() == 0) // If iResults is zero then do nothing |
|
132 { |
|
133 return 0; |
|
134 } |
|
135 PROFILER_TEST(iResults.Count() > 50); //Ensure we have an ability to remove some results in trimming |
|
136 TInt twentyPercentCount = iResults.Count()/5; |
|
137 for (TInt count = twentyPercentCount; count < iResults.Count()-twentyPercentCount; count++) |
|
138 { |
|
139 total += iResults[count]; |
|
140 } |
|
141 return ((TUint32)(total/(iResults.Count()-(twentyPercentCount*2)))); |
|
142 } |
|
143 |
|
144 EXPORT_C TInt CTProfiler::PercentageChange(TInt aFirstTime, TInt aSecondTime) |
|
145 { |
|
146 return ((aFirstTime - aSecondTime)*100) / aFirstTime; |
|
147 } |
|
148 |
|
149 /** |
|
150 Finds the maximum time taken |
|
151 */ |
|
152 TUint32 CTProfiler::TimeMax() |
|
153 { |
|
154 if (iResults.Count() == 0) |
|
155 { |
|
156 return 0; |
|
157 } |
|
158 TUint32 result = iResults[0]; |
|
159 for(TInt i = 0; i < iResults.Count(); i++) |
|
160 { |
|
161 if(iResults[i] > result) |
|
162 result = iResults[i]; |
|
163 } |
|
164 return result; |
|
165 } |
|
166 |
|
167 /** |
|
168 Finds the minimum time taken |
|
169 */ |
|
170 TUint32 CTProfiler::TimeMin() |
|
171 { |
|
172 if (iResults.Count() == 0) |
|
173 { |
|
174 return 0; |
|
175 } |
|
176 TUint32 result = iResults[0]; |
|
177 for(TInt i = 0; i < iResults.Count(); i++) |
|
178 { |
|
179 if(iResults[i] < result) |
|
180 result = iResults[i]; |
|
181 } |
|
182 return result; |
|
183 } |
|
184 |
|
185 /** |
|
186 Reports analysis results |
|
187 |
|
188 @param aTestName is the name of the test case |
|
189 @param aRotation is the screen rotation being used in the test |
|
190 @param aSrcScreenMode is the source screen mode being used, |
|
191 i.e. for bitmap display conversion the source and destinations bitmaps maybe different |
|
192 @param aDstScreenMode is the destination screen mode (usually the display screen mode) |
|
193 @param aIters is the number of iterations used in the test |
|
194 */ |
|
195 EXPORT_C void CTProfiler::ResultsAnalysis(const TDesC& aTestName, TInt aRotation, TInt aSrcScreenMode, TInt aDstScreenMode, TInt aIters) |
|
196 { |
|
197 PROFILER_TEST(iResultsInitalised); |
|
198 |
|
199 PROFILER_INFO_PRINTF7(_L("TID: %S Rot: %i SrcMode: %i DestMode: %i Iters: %i TrimmedMean: %i us"), &aTestName, aRotation, aSrcScreenMode, aDstScreenMode, aIters, GetTrimedMean()); |
|
200 PROFILER_INFO_PRINTF3(_L("Max: %i Min: %i "), TimeMax(), TimeMin()); |
|
201 iResultsInitalised = EFalse; |
|
202 } |
|
203 |
|
204 /** |
|
205 Reports analysis results for pixel rates |
|
206 |
|
207 @param aTestName is the name of the test case |
|
208 @param aRotation is the screen rotation being used in the test |
|
209 @param aSrcScreenMode is the source screen mode being used, |
|
210 i.e. for bitmap display conversion the source and destinations bitmaps maybe different |
|
211 @param aDstScreenMode is the destination screen mode (usually the display screen mode) |
|
212 @param aIters is the number of iterations used in the test |
|
213 @param aNumPixels is the number of pixels rendered |
|
214 */ |
|
215 EXPORT_C void CTProfiler::ResultsAnalysisPixelRate(const TDesC & aTestName, TInt aRotation, TInt aSrcScreenMode, TInt aDstScreenMode, TInt aIters, TInt aNumPixelsPerIteration) |
|
216 { |
|
217 PROFILER_TEST(iResultsInitalised); |
|
218 TReal time = (TReal)iResults[0] / 1000000; |
|
219 TInt32 pixelRate = aNumPixelsPerIteration*aIters/time; |
|
220 PROFILER_INFO_PRINTF7(_L("TID: %S Rot: %i SrcMode: %i DestMode: %i Iters: %i TrimmedMean: %i pixels/second"), &aTestName, aRotation, aSrcScreenMode, aDstScreenMode, aIters, pixelRate); |
|
221 PROFILER_INFO_PRINTF3(_L("Max: %i Min: %i "), TimeMax(), TimeMin()); |
|
222 iResultsInitalised = EFalse; |
|
223 } |
|
224 |
|
225 /** |
|
226 Reports analysis results for character rates |
|
227 |
|
228 @param aTestName is the name of the test case |
|
229 @param aRotation is the screen rotation being used in the test |
|
230 @param aSrcScreenMode is the source screen mode being used, |
|
231 i.e. for bitmap display conversion the source and destinations bitmaps maybe different |
|
232 @param aDstScreenMode is the destination screen mode (usually the display screen mode) |
|
233 @param aIters is the number of iterations used in the test |
|
234 @param aNumChars is the number of characters rendered |
|
235 */ |
|
236 EXPORT_C void CTProfiler::ResultsAnalysisCharacterRate(const TDesC & aTestName, TInt aRotation, TInt aSrcScreenMode, TInt aDstScreenMode, TInt aIters, TInt aNumCharsPerIteration) |
|
237 { |
|
238 PROFILER_TEST(iResultsInitalised); |
|
239 TReal time = (TReal)iResults[0] / 1000000; |
|
240 TInt32 characterRate = aNumCharsPerIteration*aIters/time; |
|
241 PROFILER_INFO_PRINTF7(_L("TID: %S Rot: %i SrcMode: %i DestMode: %i Iters: %i TrimmedMean: %i characters/second"), &aTestName, aRotation, aSrcScreenMode, aDstScreenMode, aIters, characterRate); |
|
242 PROFILER_INFO_PRINTF3(_L("Max: %i Min: %i "), TimeMax(), TimeMin()); |
|
243 iResultsInitalised = EFalse; |
|
244 } |
|
245 |
|
246 /** |
|
247 Reports analysis results when there is one total result given the number of itertions |
|
248 This function should only be used if you cannot obtain the times for each iteration of |
|
249 the test and ResultsAnalysis cannot be used. |
|
250 |
|
251 @param aTestName is the name of the test case |
|
252 @param aRotation is the screen rotation being used in the test |
|
253 @param aSrcScreenMode is the source screen mode being used, |
|
254 i.e. for bitmap display conversion the source and destinations bitmaps maybe different |
|
255 @param aDstScreenMode is the destination screen mode (usually the display screen mode) |
|
256 @param aIters is the number of iterations used in the test |
|
257 */ |
|
258 EXPORT_C void CTProfiler::ResultsAnalysisAverageByIterations(const TDesC& aTestName, TInt aRotation, TInt aSrcScreenMode, TInt aDstScreenMode, TInt aIters) |
|
259 { |
|
260 PROFILER_TEST(iResultsInitalised); |
|
261 |
|
262 PROFILER_INFO_PRINTF7(_L("TID: %S Rot: %i SrcMode: %i DestMode: %i Iters: %i TrimmedMean: %i us"), &aTestName, aRotation, aSrcScreenMode, aDstScreenMode, aIters, iResults[0]/aIters); |
|
263 PROFILER_INFO_PRINTF3(_L("Max: %i Min: %i "), TimeMax(), TimeMin()); |
|
264 iResultsInitalised = EFalse; |
|
265 } |
|
266 |
|
267 |
|
268 /** |
|
269 Reports analysis results for frame rates |
|
270 |
|
271 @param aTestName is the name of the test case |
|
272 @param aRotation is the screen rotation being used in the test |
|
273 @param aSrcScreenMode is the source screen mode being used, |
|
274 i.e. for bitmap display conversion the source and destinations bitmaps maybe different |
|
275 @param aDstScreenMode is the destination screen mode (usually the display screen mode) |
|
276 @param aIters is the number of iterations used in the test |
|
277 @param aNumPixels is the number of pixels rendered |
|
278 */ |
|
279 EXPORT_C void CTProfiler::ResultsAnalysisFrameRate(const TDesC & aTestName, TInt aRotation, TInt aSrcScreenMode, TInt aDstScreenMode, TInt aIters, TInt aNumPixelsPerIteration) |
|
280 { |
|
281 PROFILER_TEST(iResultsInitalised); |
|
282 TReal time = (TReal)iResults[0] / 1000000; |
|
283 TInt32 pixelRate = aNumPixelsPerIteration * aIters / time; |
|
284 TInt32 frameRate = aIters / time; |
|
285 PROFILER_INFO_PRINTF7(_L("TID: %S Rot: %i SrcMode: %i DestMode: %i Iters: %i TrimmedMean: %i pixels/second"), &aTestName, aRotation, aSrcScreenMode, aDstScreenMode, aIters, pixelRate); |
|
286 PROFILER_INFO_PRINTF4(_L("Max: %i Min: %i Framerate: %i frames/second"), TimeMax(), TimeMin(), frameRate); |
|
287 iResultsInitalised = EFalse; |
|
288 } |
|
289 |
|
290 /** |
|
291 Reports analysis results for screen rotation rates |
|
292 |
|
293 @param aTestName is the name of the test case |
|
294 @param aRotation is the screen rotation being used in the test |
|
295 @param aSrcScreenMode is the source screen mode being used, |
|
296 i.e. for bitmap display conversion the source and destinations bitmaps maybe different |
|
297 @param aDstScreenMode is the destination screen mode (usually the display screen mode) |
|
298 @param aIters is the number of iterations used in the test |
|
299 @param aNumPixels is the number of pixels rendered |
|
300 */ |
|
301 EXPORT_C void CTProfiler::ResultsAnalysisScreenRotationRate(const TDesC & aTestName, TInt aRotation, TInt aSrcScreenMode, TInt aDstScreenMode, TInt aIters, TInt aNumPixelsPerIteration) |
|
302 { |
|
303 PROFILER_TEST(iResultsInitalised); |
|
304 TReal time = (TReal)iResults[0] / 1000000; |
|
305 TInt32 pixelRate = aNumPixelsPerIteration * aIters / time; |
|
306 TInt32 frameRate = aIters / time; |
|
307 PROFILER_INFO_PRINTF7(_L("TID: %S Rot: %i SrcMode: %i DestMode: %i Iters: %i TrimmedMean: %i pixels/second"), &aTestName, aRotation, aSrcScreenMode, aDstScreenMode, aIters, pixelRate); |
|
308 PROFILER_INFO_PRINTF4(_L("Max: %i Min: %i Framerate: %i frames/second"), TimeMax(), TimeMin(), frameRate); |
|
309 iResultsInitalised = EFalse; |
|
310 } |
|
311 |
|
312 /** |
|
313 Reports analysis results for Z Order Switching rates |
|
314 |
|
315 @param aTestName is the name of the test case |
|
316 @param aZorderSwitching is the z Order Switching being used in the test |
|
317 @param aSrcScreenMode is the source screen mode being used, |
|
318 @param aDstScreenMode is the destination screen mode (usually the display screen mode) |
|
319 @param aIters is the number of iterations used in the test |
|
320 @param aNumPixels is the number of pixels rendered |
|
321 */ |
|
322 EXPORT_C void CTProfiler::ResultsAnalysisZorderSwitchingRate(const TDesC & aTestName, TInt aZorderSwitching, TInt aSrcScreenMode, TInt aDstScreenMode, TInt aIters, TInt aNumPixelsPerIteration) |
|
323 { |
|
324 PROFILER_TEST(iResultsInitalised); |
|
325 TReal time = (TReal)iResults[0] / 1000000; |
|
326 TInt32 pixelRate = aNumPixelsPerIteration * aIters / time; |
|
327 TInt32 frameRate = aIters / time; |
|
328 PROFILER_INFO_PRINTF7(_L("TID: %S Rot: %i SrcMode: %i DestMode: %i Iters: %i TrimmedMean: %i pixels/second"), &aTestName, aZorderSwitching, aSrcScreenMode, aDstScreenMode, aIters, pixelRate); |
|
329 PROFILER_INFO_PRINTF4(_L("Max: %i Min: %i Framerate: %i frames/second"), TimeMax(), TimeMin(), frameRate); |
|
330 iResultsInitalised = EFalse; |
|
331 } |
|
332 |
|
333 /** |
|
334 This function calclulates the mean without deleting any of the values from iResults |
|
335 */ |
|
336 EXPORT_C TUint32 CTProfiler::Mean() |
|
337 { |
|
338 TInt64 total = 0; |
|
339 TInt count1 = iResults.Count(); |
|
340 for (TInt count = 0; count < iResults.Count(); count++) |
|
341 { |
|
342 total += iResults[count]; |
|
343 } |
|
344 return ((TUint32)(total/(iResults.Count()))); |
|
345 } |
|
346 |
|
347 |
|
348 /** |
|
349 Reports analysis of results when there are more then one values by calculating the average based on value of iResult.count(). |
|
350 |
|
351 @param aTestName is the name of the test case |
|
352 @param aRotation is the screen rotation being used in the test |
|
353 @param aSrcScreenMode is the source screen mode being used, |
|
354 i.e. for bitmap display conversion the source and destinations bitmaps maybe different |
|
355 @param aDstScreenMode is the destination screen mode (usually the display screen mode) |
|
356 @param aIters is the number of iterations used in the test |
|
357 */ |
|
358 EXPORT_C void CTProfiler::ResultsAnalysisAverageByNumberOfIterations(const TDesC& aTestName, TInt aRotation, TInt aSrcScreenMode, TInt aDstScreenMode,TInt aIters) |
|
359 { |
|
360 PROFILER_TEST(iResultsInitalised); |
|
361 |
|
362 PROFILER_INFO_PRINTF7(_L("TID: %S Rot: %i SrcMode: %i DestMode: %i Iters: %i TrimmedMean: %i us"), &aTestName, aRotation, aSrcScreenMode, aDstScreenMode, aIters, Mean()); |
|
363 PROFILER_INFO_PRINTF3(_L("Max: %i Min: %i "), TimeMax(), TimeMin()); |
|
364 iResultsInitalised = EFalse; |
|
365 } |