|
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 // This is the file name, extension and path specification for the file store |
|
15 // and should not be used as is |
|
16 // |
|
17 // |
|
18 |
|
19 _LIT(KStreamsName, "Z:\\STOR-TST\\BMStreams.dat"); |
|
20 extern TFileName TheStreamsFilePath; |
|
21 |
|
22 // Construct CCompound object and externalize it to a single stream |
|
23 LOCAL_C void doExternalizeL(const TDesC& aName); |
|
24 |
|
25 // Internalize CCompound object from the stream |
|
26 LOCAL_C void doInternalizeL(const TDesC& aName); |
|
27 |
|
28 #define STREAMRUNSIZE 1000 |
|
29 // Declare a class used by the example |
|
30 class CStreamA |
|
31 { |
|
32 public : |
|
33 void ExternalizeL(RWriteStream& aStream) const; |
|
34 void InternalizeL(RReadStream& aStream); |
|
35 public : |
|
36 TBuf<32> iBufferA; |
|
37 TInt iXA; |
|
38 TUint iYA; |
|
39 }; |
|
40 |
|
41 class TStream |
|
42 { |
|
43 public : |
|
44 void ExternalizeL(RWriteStream& aStream) const; |
|
45 void InternalizeL(RReadStream& aStream); |
|
46 public : |
|
47 TReal iZC; |
|
48 }; |
|
49 |
|
50 class CCompound : public CBase |
|
51 { |
|
52 public : |
|
53 ~CCompound(); |
|
54 static CCompound* NewLC(); |
|
55 static CCompound* NewLC(CStreamStore& aStore,TStreamId anId); |
|
56 static CCompound* NewL(CStreamStore& aStore,TStreamId anId); |
|
57 TStreamId StoreL(CStreamStore& store); |
|
58 void RestoreL(CStreamStore& aStore,TStreamId anId); |
|
59 void InternalizeL(RReadStream& aStream); |
|
60 void ExternalizeL(RWriteStream& aStream) const; |
|
61 private: |
|
62 void ConstructL(); |
|
63 void ConstructL(CStreamStore& aStore,TStreamId anId); |
|
64 public : |
|
65 CStreamA* iCa; |
|
66 TStream iTc; |
|
67 CArrayFixFlat<TElement>* iArray; |
|
68 }; |
|
69 |
|
70 |
|
71 /** |
|
72 @SYMTestCaseID SYSLIB-STORE-PT-1369 |
|
73 @SYMTestCaseDesc CR MRLM-6A9DF7. Tests the impact of RFileBuf cache size on CDirectFileStore performance. RFileBuf cache size must be set at a build time in EStor_Template.mmh file, DEFAULT_FILE_BUF_SIZE macro definition. |
|
74 @SYMTestPriority High |
|
75 @SYMTestActions The test creates a set of test objects, externalizes them STREAMRUNSIZE times and prints the execution time. Then internalizes them STREAMRUNSIZE times and prints the execution time. |
|
76 STREAMRUNSIZE is a constant, defined in the source file. |
|
77 @SYMTestExpectedResults Test must show a performance improvement |
|
78 @SYMPREQ PREQ1132 |
|
79 @SYMREQ REQ4883 |
|
80 */ |
|
81 LOCAL_C void doStreamingL() |
|
82 { |
|
83 TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive())); |
|
84 TParse streamsName; |
|
85 streamsName.Set(drive.Name(), &KStreamsName, NULL); |
|
86 TheStreamsFilePath.Copy(streamsName.FullName()); |
|
87 |
|
88 // make sure directory exists |
|
89 TheFs.MkDirAll(streamsName.DriveAndPath()); |
|
90 TTime start; |
|
91 start.HomeTime(); |
|
92 for(int i=0; i<STREAMRUNSIZE;i++) |
|
93 { |
|
94 doExternalizeL(TheStreamsFilePath); |
|
95 } |
|
96 TTime end; |
|
97 end.HomeTime(); |
|
98 TTimeIntervalMicroSeconds us = end.MicroSecondsFrom(start); |
|
99 TheTest.Printf(_L("CDirectFileStore, externalise %d streams. Time=%ld ms\r\n"), STREAMRUNSIZE, us.Int64() / 1000); |
|
100 |
|
101 start.HomeTime(); |
|
102 for(int j=0; j<STREAMRUNSIZE;j++) |
|
103 { |
|
104 doInternalizeL(TheStreamsFilePath); |
|
105 } |
|
106 end.HomeTime(); |
|
107 us = end.MicroSecondsFrom(start); |
|
108 TheTest.Printf(_L("CDirectFileStore, internalise %d streams. Time=%ld ms\r\n"), STREAMRUNSIZE, us.Int64() / 1000); |
|
109 } |
|
110 |
|
111 LOCAL_C void doExternalizeL(const TDesC& aName) |
|
112 { |
|
113 // construct file store object - the file to contain the store |
|
114 CFileStore* store = CDirectFileStore::ReplaceLC(TheFs,aName,EFileWrite); |
|
115 |
|
116 // Must say what kind of file store |
|
117 store->SetTypeL(KDirectFileStoreLayoutUid); |
|
118 |
|
119 // Construct an object of type CCompound and prepare some data into it |
|
120 CCompound* thecompound = CCompound::NewLC(); |
|
121 |
|
122 _LIT(KTxtClassAText,"CStreamA text"); |
|
123 |
|
124 thecompound->iCa->iBufferA = KTxtClassAText; |
|
125 thecompound->iCa->iXA = -1; |
|
126 thecompound->iCa->iYA = 2; |
|
127 thecompound->iTc.iZC = 3.456; |
|
128 |
|
129 TElement theElement; |
|
130 _LIT(KFormatTxt,"BenchMarkingTheStream%4u"); |
|
131 TBuf<256> str(KFormatTxt); |
|
132 |
|
133 for (TInt index = 0; index < STREAMRUNSIZE; index++) |
|
134 { |
|
135 theElement.iData.Format(KFormatTxt,index); |
|
136 thecompound->iArray->AppendL(theElement); |
|
137 } |
|
138 |
|
139 // Store the compound object to a single stream and save the stream id as the root id |
|
140 TStreamId id = thecompound->StoreL(*store); |
|
141 |
|
142 // Set the stream id as the root |
|
143 store->SetRootL(id); |
|
144 |
|
145 // Commit changes to the store |
|
146 store->CommitL(); |
|
147 // thecompound |
|
148 CleanupStack::PopAndDestroy(2); // store |
|
149 } |
|
150 |
|
151 LOCAL_C void doInternalizeL(const TDesC& aName) |
|
152 { |
|
153 //Create file store object - specifying the file containing the store. |
|
154 CFileStore* store = CDirectFileStore::OpenLC(TheFs,aName,EFileRead); |
|
155 |
|
156 // Construct a CCompound object from the root stream created earlier. |
|
157 CCompound* thecompound = CCompound::NewL(*store,store->Root()); |
|
158 |
|
159 // destroy the store object (this also closes the file containing the store) |
|
160 CleanupStack::PopAndDestroy(); |
|
161 // Now destroy the CCompound object |
|
162 delete thecompound; |
|
163 } |
|
164 |
|
165 //*************************************************************** |
|
166 |
|
167 // The CCompound destructor |
|
168 CCompound::~CCompound() |
|
169 { |
|
170 delete iCa; |
|
171 delete iArray; |
|
172 } |
|
173 |
|
174 CCompound* CCompound::NewLC() |
|
175 { |
|
176 CCompound* self=new (ELeave) CCompound; |
|
177 CleanupStack::PushL(self); |
|
178 self->ConstructL(); |
|
179 return self; |
|
180 } |
|
181 |
|
182 void CCompound::ConstructL() |
|
183 { |
|
184 iCa = new (ELeave) CStreamA; |
|
185 iArray = new (ELeave) CArrayFixFlat<TElement>(10); |
|
186 } |
|
187 |
|
188 // Construct a new CCompound object from the input stream. |
|
189 CCompound* CCompound::NewL(CStreamStore& aStore,TStreamId anId) |
|
190 { |
|
191 CCompound* self=CCompound::NewLC(aStore,anId); |
|
192 CleanupStack::Pop(); |
|
193 return self; |
|
194 } |
|
195 |
|
196 // Construct CCompound object from the root stream of the store |
|
197 CCompound* CCompound::NewLC(CStreamStore& aStore,TStreamId anId) |
|
198 { |
|
199 CCompound* self=new (ELeave) CCompound; |
|
200 CleanupStack::PushL(self); |
|
201 self->ConstructL(aStore,anId); |
|
202 return self; |
|
203 } |
|
204 |
|
205 void CCompound::ConstructL(CStreamStore& aStore,TStreamId anId) |
|
206 { |
|
207 iCa = new (ELeave) CStreamA; |
|
208 // Restore here at construction |
|
209 RestoreL(aStore,anId); |
|
210 } |
|
211 |
|
212 void CCompound::RestoreL(CStreamStore& aStore,TStreamId anId) |
|
213 { |
|
214 RStoreReadStream instream; |
|
215 instream.OpenLC(aStore,anId); |
|
216 InternalizeL(instream); |
|
217 // Cleanup the stream object |
|
218 CleanupStack::PopAndDestroy(); |
|
219 } |
|
220 |
|
221 // Read the components and data members of the CCompound object from stream |
|
222 void CCompound::InternalizeL(RReadStream& aStream) |
|
223 { |
|
224 aStream >> *iCa; |
|
225 aStream >> iTc; |
|
226 |
|
227 TElement theElement; |
|
228 iArray = new (ELeave) CArrayFixFlat<TElement>(STREAMRUNSIZE); |
|
229 // iArray->Count(); |
|
230 // iArray->Reset(); |
|
231 for (TInt index = 0; index < STREAMRUNSIZE ; index++) |
|
232 { |
|
233 aStream.ReadL(theElement.iData, 25); |
|
234 iArray->AppendL(theElement); |
|
235 } |
|
236 } |
|
237 |
|
238 TStreamId CCompound::StoreL(CStreamStore& aStore) |
|
239 { |
|
240 RStoreWriteStream outstream; |
|
241 TStreamId id = outstream.CreateLC(aStore); |
|
242 // Stream out this CCompound object |
|
243 ExternalizeL(outstream); |
|
244 // Commit changes to the stream |
|
245 outstream.CommitL(); |
|
246 // Cleanup the stream object. |
|
247 CleanupStack::PopAndDestroy(); |
|
248 return id; |
|
249 } |
|
250 |
|
251 // Write the components and data members of the CCompound object to stream |
|
252 void CCompound::ExternalizeL(RWriteStream& aStream) const |
|
253 { |
|
254 aStream << *iCa; |
|
255 aStream << iTc; |
|
256 |
|
257 TElement theElement; |
|
258 TInt count = iArray->Count(); |
|
259 for (TInt index = 0; index < count; index++) |
|
260 { |
|
261 theElement =((*iArray)[index]); |
|
262 aStream.WriteL(theElement.iData, 25); |
|
263 } |
|
264 } |
|
265 |
|
266 //*************************************************************** |
|
267 |
|
268 // Read the data members of the CStreamA object from the stream. |
|
269 void CStreamA::InternalizeL(RReadStream& aStream) |
|
270 { |
|
271 aStream >> iBufferA; |
|
272 iXA = aStream.ReadInt32L(); |
|
273 iYA = aStream.ReadUint32L(); |
|
274 } |
|
275 // Write the data members of the CStreamA object to the stream |
|
276 void CStreamA::ExternalizeL(RWriteStream& aStream)const |
|
277 { |
|
278 aStream << iBufferA; |
|
279 aStream.WriteInt32L(iXA); |
|
280 aStream.WriteUint32L(iYA); |
|
281 } |
|
282 |
|
283 //*************************************************************** |
|
284 |
|
285 // Write the data member(s) of the TStream object to the stream |
|
286 void TStream::ExternalizeL(RWriteStream& aStream) const |
|
287 { |
|
288 aStream.WriteReal64L(iZC); |
|
289 } |
|
290 |
|
291 // Read the data member(s) of the TStream object from the stream. |
|
292 void TStream::InternalizeL(RReadStream& aStream) |
|
293 { |
|
294 iZC = aStream.ReadReal64L(); |
|
295 } |
|
296 |