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 "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 // Contains MBufMgr Test Step 13 that measures the time spent for alloc/free methods |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 |
|
21 // Test system includes |
|
22 #ifdef SYMBIAN_OLD_EXPORT_LOCATION |
|
23 #include "networking/log.h" |
|
24 #include "networking/teststep.h" |
|
25 #else |
|
26 #include <networking/log.h> |
|
27 #include <networking/teststep.h> |
|
28 #endif |
|
29 #include "TestStepCTMbufmgr.h" |
|
30 #include "TestSuiteCTMbufmgr.h" |
|
31 |
|
32 #include "Test13Performance.h" |
|
33 |
|
34 #include <comms-infras/commsbufpond.h> |
|
35 |
|
36 // constructor |
|
37 CTest13Performance::CTest13Performance() |
|
38 { |
|
39 iTestStepName = _L("MBufMgrTest13");// Store the name of this test case |
|
40 } |
|
41 |
|
42 // destructor |
|
43 CTest13Performance::~CTest13Performance() |
|
44 { |
|
45 } |
|
46 |
|
47 |
|
48 // |
|
49 enum TVerdict CTest13Performance::doTestStepL(void) |
|
50 { |
|
51 __UHEAP_MARK; |
|
52 |
|
53 TInt aMBufNo; //Taken from the script; |
|
54 TInt aLoopNo; //Taken from the script; |
|
55 TTime aTimeStart, aTimeStop; |
|
56 //-------------- substep 0 -------------------- |
|
57 Log(_L(" 00 Read parameters from the script:")); |
|
58 TInt bRet = GetIntFromConfig(_L("MBufMgrTest13"), _L("MBufNo"), aMBufNo); |
|
59 if (!bRet) return EFail; |
|
60 bRet = GetIntFromConfig(_L("MBufMgrTest13"), _L("LoopNo"), aLoopNo); |
|
61 if (!bRet) return EFail; |
|
62 Log(_L(" Info: MBUFNO = %d, LOOPNO= %d"),aMBufNo, aLoopNo); |
|
63 |
|
64 #ifdef __CFLOG_ACTIVE |
|
65 __CFLOG_CREATEL; |
|
66 __CFLOG_OPEN; |
|
67 #endif |
|
68 |
|
69 //-------------- substep 1 -------------------- |
|
70 Log(_L(" 01 Create CMBufManager and install active scheduler:")); |
|
71 CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler ); |
|
72 CActiveScheduler::Install(iActSch); |
|
73 |
|
74 CreateInstanceMBufMgrL((TUint)(3*KMBufSmallSize*aMBufNo)); |
|
75 CleanupClosePushL(iBufPond); |
|
76 |
|
77 TInt i,j,k; //Counters |
|
78 TInt64 us; |
|
79 RMBufQ aBufList1, aBufList2; //Will contain all small buffers; |
|
80 RMBuf* aBuf=0; |
|
81 |
|
82 for (i = 0; i<aLoopNo; i++) |
|
83 { |
|
84 Log(_L(" Loop #%d"), i + 1); |
|
85 |
|
86 //-------------- substep 2 -------------------- |
|
87 Log(_L(" 02 Allocate Chain that contains RMBUFNO buffers. Free Chain.")); |
|
88 Log(_L(" ...Repeat the same 1000 times.Display the time spent:")); |
|
89 RMBufChain aChain; |
|
90 aTimeStart.UniversalTime(); |
|
91 for (j = 0;j < 1000; j++) |
|
92 { |
|
93 TRAPD(ret,aChain.AllocL(KMBufSmallSize*aMBufNo)); |
|
94 if (ret != KErrNone) |
|
95 { |
|
96 Log(_L("Error: Couldn't allocate RMBuf:")); |
|
97 |
|
98 #ifdef __CFLOG_ACTIVE |
|
99 __CFLOG_CLOSE; |
|
100 __CFLOG_DELETE; |
|
101 #endif |
|
102 User::Leave(EFail); |
|
103 } |
|
104 |
|
105 aChain.Free(); |
|
106 } |
|
107 |
|
108 aTimeStop.UniversalTime(); |
|
109 us = aTimeStop.MicroSecondsFrom(aTimeStart).Int64()/1000; |
|
110 User::After(100000); |
|
111 Log(_L(" ...Info: The time spent on 1000 alloc and free is %d mS"),us); |
|
112 |
|
113 //-------------- substep 3 -------------------- |
|
114 Log(_L(" 03 Create %d chains, each containing one RMBuf."), 2 * aMBufNo); |
|
115 Log(_L(" ...Then, free all even chains:")); |
|
116 aTimeStart.UniversalTime(); |
|
117 TInt attemptCount = 0; |
|
118 for (j = 0;j<2*aMBufNo;j++) |
|
119 { |
|
120 aBuf = static_cast<RMBuf*>(iBufPond.Alloc(KMBufSmallSize, 0, KMaxTInt)); |
|
121 if (aBuf == NULL) |
|
122 { |
|
123 ++attemptCount; |
|
124 if(attemptCount == 3) |
|
125 { |
|
126 Log(_L("Error: Couldn't allocate RMBuf number %d:"),j); |
|
127 |
|
128 #ifdef __CFLOG_ACTIVE |
|
129 __CFLOG_CLOSE; |
|
130 __CFLOG_DELETE; |
|
131 #endif |
|
132 User::Leave(EFail); |
|
133 } |
|
134 else |
|
135 { |
|
136 User::After(100000); |
|
137 } |
|
138 } |
|
139 if(aBuf) |
|
140 { |
|
141 aBufList1.Append(aBuf); |
|
142 } |
|
143 } |
|
144 |
|
145 k=0; |
|
146 while (!aBufList1.IsEmpty()) |
|
147 { |
|
148 k++; |
|
149 aBuf = aBufList1.Remove(); |
|
150 if (k%2) |
|
151 { |
|
152 aBuf->Free(); |
|
153 } |
|
154 else |
|
155 { |
|
156 aBufList2.Append(aBuf); |
|
157 } |
|
158 } |
|
159 aTimeStop.UniversalTime(); |
|
160 us = aTimeStop.MicroSecondsFrom(aTimeStart).Int64()/1000; |
|
161 Log(_L(" ...Info: The time spent is %d mS"), us); |
|
162 |
|
163 //-------------- substep 4 -------------------- |
|
164 Log(_L(" 04 Allocate Chain that contains RMBUFNO buffers. Free Chain.")); |
|
165 Log(_L(" ...Repeat the same 1000 times.Display the time spent:")); |
|
166 aTimeStart.UniversalTime(); |
|
167 for (j = 0;j < 1000; j++) |
|
168 { |
|
169 TRAPD(ret,aChain.AllocL(KMBufSmallSize*aMBufNo)); |
|
170 if (ret != KErrNone) |
|
171 { |
|
172 Log(_L("Error: Couldn't allocate RMBuf number %d:"),j); |
|
173 |
|
174 #ifdef __CFLOG_ACTIVE |
|
175 __CFLOG_CLOSE; |
|
176 __CFLOG_DELETE; |
|
177 #endif |
|
178 User::Leave(EFail); |
|
179 } |
|
180 |
|
181 aChain.Free(); |
|
182 } |
|
183 aTimeStop.UniversalTime(); |
|
184 us = aTimeStop.MicroSecondsFrom(aTimeStart).Int64()/1000; |
|
185 Log(_L(" ...Info: The time spent on 1000 alloc and free is %d mS"),us); |
|
186 |
|
187 //-------------- substep 5 -------------------- |
|
188 Log(_L(" 05 Free all remaining chains:")); |
|
189 while (!aBufList2.IsEmpty()) |
|
190 { |
|
191 aBuf = aBufList2.Remove(); |
|
192 aBuf->Free(); |
|
193 } |
|
194 } |
|
195 |
|
196 |
|
197 //-------------- substep 9 -------------------- |
|
198 Log(_L(" 09 Clean up stack:")); |
|
199 CleanupStack::PopAndDestroy(); |
|
200 CActiveScheduler::Install(NULL); |
|
201 CleanupStack::PopAndDestroy(iActSch); |
|
202 |
|
203 #ifdef __CFLOG_ACTIVE |
|
204 __CFLOG_CLOSE; |
|
205 __CFLOG_DELETE; |
|
206 #endif |
|
207 __UHEAP_MARKEND; |
|
208 return EPass; |
|
209 } |
|