|
1 // Copyright (c) 2002-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 the License "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 #include <e32test.h> |
|
17 |
|
18 #include "bm_suite.h" |
|
19 |
|
20 class Overhead : public BMProgram |
|
21 { |
|
22 typedef void (*MeasurementFunc)(TBMResult*, TBMUInt64 aIter); |
|
23 struct Measurement |
|
24 { |
|
25 MeasurementFunc iFunc; |
|
26 TPtrC iName; |
|
27 |
|
28 Measurement(MeasurementFunc aFunc, const TDesC& aName) : iFunc(aFunc), iName(aName) {} |
|
29 }; |
|
30 public : |
|
31 Overhead() : BMProgram(_L("Overhead")) |
|
32 {} |
|
33 virtual TBMResult* Run(TBMUInt64 aIter, TInt* aCount); |
|
34 private: |
|
35 static TBMResult iResults[]; |
|
36 static Measurement iMeasurements[]; |
|
37 |
|
38 static void TimerStampOverhead(TBMResult*, TBMUInt64 aIter); |
|
39 }; |
|
40 |
|
41 Overhead::Measurement Overhead::iMeasurements[] = |
|
42 { |
|
43 Measurement(&Overhead::TimerStampOverhead, _L("Getting Timer Stamp Overhead")) |
|
44 }; |
|
45 TBMResult Overhead::iResults[sizeof(Overhead::iMeasurements)/sizeof(Overhead::iMeasurements[0])]; |
|
46 |
|
47 static Overhead overhead; |
|
48 |
|
49 void Overhead::TimerStampOverhead(TBMResult* aResult, TBMUInt64 aIter) |
|
50 { |
|
51 for (TBMUInt64 i = 0; i < aIter; ++i) |
|
52 { |
|
53 TBMTicks t1, t2; |
|
54 ::bmTimer.Stamp(&t1); |
|
55 ::bmTimer.Stamp(&t2); |
|
56 aResult->Cumulate(TBMTicksDelta(t1, t2)); |
|
57 // |
|
58 // Enable other threads to run |
|
59 // |
|
60 TInt prio = BMProgram::SetAbsPriority(RThread(), overhead.iOrigAbsPriority); |
|
61 BMProgram::SetAbsPriority(RThread(), prio); |
|
62 } |
|
63 } |
|
64 |
|
65 TBMResult* Overhead::Run(TBMUInt64 aIter, TInt* aCount) |
|
66 { |
|
67 TInt count = sizeof(iResults)/sizeof(iResults[0]); |
|
68 |
|
69 for (TInt i = 0; i < count; ++i) |
|
70 { |
|
71 iResults[i].Reset(iMeasurements[i].iName); |
|
72 iMeasurements[i].iFunc(&iResults[i], aIter); |
|
73 iResults[i].Update(); |
|
74 } |
|
75 |
|
76 *aCount = count; |
|
77 return iResults; |
|
78 } |
|
79 |
|
80 void AddOverhead() |
|
81 { |
|
82 BMProgram* next = bmSuite; |
|
83 bmSuite=(BMProgram*)&overhead; |
|
84 bmSuite->Next()=next; |
|
85 } |