|
1 // Copyright (c) 2010 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 // @file |
|
15 // |
|
16 // |
|
17 // |
|
18 |
|
19 |
|
20 class TF32TestTimer |
|
21 { |
|
22 public: |
|
23 TF32TestTimer(); |
|
24 |
|
25 void Start(); |
|
26 void Stop(); |
|
27 |
|
28 TInt64 TimeTaken() const; |
|
29 TTimeIntervalMicroSeconds Time() const; |
|
30 TTimeIntervalMicroSeconds32 Time32() const; |
|
31 int TimeInMicroSeconds() const; |
|
32 int TimeInMilliSeconds() const; |
|
33 |
|
34 static TInt TimeInMilliSeconds(TTimeIntervalMicroSeconds aTime); |
|
35 static TInt TimeInMilliSeconds(TTimeIntervalMicroSeconds32 aTime); |
|
36 |
|
37 protected: |
|
38 TInt64 Diff(TUint32 aTicks) const; |
|
39 |
|
40 protected: |
|
41 TInt iFastCounterFreq; |
|
42 TUint32 startTicks; |
|
43 TUint32 endTicks; |
|
44 }; |
|
45 |
|
46 |
|
47 class TF32TestTimer2: public TF32TestTimer |
|
48 { |
|
49 public: |
|
50 void Stop2(); |
|
51 |
|
52 TInt64 TimeTaken2() const; |
|
53 TTimeIntervalMicroSeconds32 Time2() const; |
|
54 int Time2InMicroSeconds() const; |
|
55 |
|
56 private: |
|
57 TUint32 endTicks2; |
|
58 }; |
|
59 |
|
60 inline TF32TestTimer::TF32TestTimer() |
|
61 { |
|
62 TInt r = HAL::Get(HAL::EFastCounterFrequency, iFastCounterFreq); |
|
63 test_KErrNone(r); |
|
64 } |
|
65 |
|
66 inline void TF32TestTimer::Start() |
|
67 { |
|
68 startTicks = User::FastCounter(); |
|
69 } |
|
70 |
|
71 inline void TF32TestTimer::Stop() |
|
72 { |
|
73 endTicks = User::FastCounter();; |
|
74 } |
|
75 |
|
76 inline void TF32TestTimer2::Stop2() |
|
77 { |
|
78 endTicks2 = User::FastCounter();; |
|
79 } |
|
80 |
|
81 inline TInt64 TF32TestTimer::Diff(TUint32 aTicks) const |
|
82 { |
|
83 if (aTicks == startTicks) |
|
84 { |
|
85 test.Printf(_L("Warning: tick not advanced")); |
|
86 } |
|
87 |
|
88 TInt64 diff; |
|
89 if (aTicks > startTicks) |
|
90 { |
|
91 diff = static_cast<TInt64>(aTicks) - static_cast<TInt64>(startTicks); |
|
92 } |
|
93 else |
|
94 { |
|
95 // handle counter rollover |
|
96 diff = ((static_cast<TInt64>(KMaxTUint32) + 1 + aTicks) - static_cast<TInt64>(startTicks)); |
|
97 } |
|
98 //RDebug::Printf("%x %x %ld", aTicks, startTicks, diff); |
|
99 diff *= TInt64(1000000); |
|
100 diff /= TInt64(iFastCounterFreq); |
|
101 |
|
102 return diff; |
|
103 } |
|
104 |
|
105 inline TInt64 TF32TestTimer::TimeTaken() const |
|
106 { |
|
107 return Diff(endTicks); |
|
108 } |
|
109 |
|
110 inline TInt64 TF32TestTimer2::TimeTaken2() const |
|
111 { |
|
112 return Diff(endTicks2); |
|
113 } |
|
114 |
|
115 inline int TF32TestTimer::TimeInMicroSeconds() const |
|
116 { |
|
117 return static_cast <int>(TimeTaken()); |
|
118 } |
|
119 |
|
120 inline int TF32TestTimer2::Time2InMicroSeconds() const |
|
121 { |
|
122 return static_cast <int>(TimeTaken2()); |
|
123 } |
|
124 |
|
125 inline TTimeIntervalMicroSeconds TF32TestTimer::Time() const |
|
126 { |
|
127 return TimeTaken(); |
|
128 } |
|
129 |
|
130 inline TTimeIntervalMicroSeconds32 TF32TestTimer2::Time2() const |
|
131 { |
|
132 return static_cast <int>(TimeTaken2()); |
|
133 } |
|
134 |
|
135 inline TTimeIntervalMicroSeconds32 TF32TestTimer::Time32() const |
|
136 { |
|
137 return static_cast <int>(TimeTaken()); |
|
138 } |
|
139 |
|
140 inline int TF32TestTimer::TimeInMilliSeconds() const |
|
141 { |
|
142 return static_cast <int>(TimeTaken() / 1000); |
|
143 } |
|
144 |
|
145 TInt TF32TestTimer::TimeInMilliSeconds(TTimeIntervalMicroSeconds aTime) |
|
146 { |
|
147 return static_cast <int>(aTime.Int64()/static_cast<TInt64>(1000)); |
|
148 } |
|
149 |
|
150 TInt TF32TestTimer::TimeInMilliSeconds(TTimeIntervalMicroSeconds32 aTime) |
|
151 { |
|
152 return static_cast <int>(aTime.Int()/1000); |
|
153 } |
|
154 |