sl@0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Demonstrates performance assesment of direct file store..
|
sl@0
|
15 |
// The file name, extension and path for the file store
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
_LIT(KDirectFileStoreName,"Z:\\STOR-TST\\BMDirectFileStores.dat");
|
sl@0
|
20 |
extern TFileName TheDirectStoreFilePath;
|
sl@0
|
21 |
|
sl@0
|
22 |
// Create objects externalizes them to a direct file store and then destroys the objects
|
sl@0
|
23 |
LOCAL_C void doStoreL(const TDesC& aName);
|
sl@0
|
24 |
|
sl@0
|
25 |
// Constructs "empty" CDFileStoreA, ClassB and CDFileStoreC objects and restores them from the direct file store.
|
sl@0
|
26 |
LOCAL_C void doRestoreL(const TDesC& aName);
|
sl@0
|
27 |
|
sl@0
|
28 |
#define DFSTORERUNSIZE 1000
|
sl@0
|
29 |
|
sl@0
|
30 |
class CDFileStoreA : public CBase
|
sl@0
|
31 |
{
|
sl@0
|
32 |
public :
|
sl@0
|
33 |
static CDFileStoreA* NewLC();
|
sl@0
|
34 |
~CDFileStoreA();
|
sl@0
|
35 |
void SetTextL(const TDesC& aData);
|
sl@0
|
36 |
void ExternalizeL(RWriteStream& aStream) const;
|
sl@0
|
37 |
void InternalizeL(RReadStream& aStream);
|
sl@0
|
38 |
public :
|
sl@0
|
39 |
HBufC* iVarBuffer;
|
sl@0
|
40 |
TInt iIntValue;
|
sl@0
|
41 |
TUint iUintValue;
|
sl@0
|
42 |
};
|
sl@0
|
43 |
|
sl@0
|
44 |
class CDFileStoreB : public CBase
|
sl@0
|
45 |
{
|
sl@0
|
46 |
public :
|
sl@0
|
47 |
static CDFileStoreB* NewLC();
|
sl@0
|
48 |
void ExternalizeL(RWriteStream& aStream) const;
|
sl@0
|
49 |
void InternalizeL(RReadStream& aStream);
|
sl@0
|
50 |
public :
|
sl@0
|
51 |
TBuf<32> iFixBuffer;
|
sl@0
|
52 |
TUint iUintValue;
|
sl@0
|
53 |
TInt iIntValue;
|
sl@0
|
54 |
TReal iRealValue;
|
sl@0
|
55 |
};
|
sl@0
|
56 |
|
sl@0
|
57 |
//#define KStdirectClassCGranularity 4
|
sl@0
|
58 |
|
sl@0
|
59 |
class CDFileStoreC : public CBase
|
sl@0
|
60 |
{
|
sl@0
|
61 |
public :
|
sl@0
|
62 |
static CDFileStoreC* NewLC();
|
sl@0
|
63 |
~CDFileStoreC();
|
sl@0
|
64 |
void ConstructL();
|
sl@0
|
65 |
//void AddNumberToArrayL(TInt aValue);
|
sl@0
|
66 |
void AddNumberToArrayL();
|
sl@0
|
67 |
void ExternalizeL(RWriteStream& aStream) const;
|
sl@0
|
68 |
void InternalizeL(RReadStream& aStream);
|
sl@0
|
69 |
public :
|
sl@0
|
70 |
TBuf<32> iFixBuffer;
|
sl@0
|
71 |
CArrayFixFlat<TInt>* iArray;
|
sl@0
|
72 |
CArrayFixFlat<TElement>* nArray;
|
sl@0
|
73 |
};
|
sl@0
|
74 |
|
sl@0
|
75 |
|
sl@0
|
76 |
|
sl@0
|
77 |
/**
|
sl@0
|
78 |
@SYMTestCaseID SYSLIB-STORE-PT-1362
|
sl@0
|
79 |
@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.
|
sl@0
|
80 |
@SYMTestPriority High
|
sl@0
|
81 |
@SYMTestActions The test creates a set of test objects, externalizes them DFSTORERUNSIZE times and prints the execution time. Then internalizes them DFSTORERUNSIZE times and prints the execution time. DFSTORERUNSIZE is a constant, defined in the source file.
|
sl@0
|
82 |
@SYMTestExpectedResults Test must show a performance improvement
|
sl@0
|
83 |
@SYMPREQ PREQ1132
|
sl@0
|
84 |
@SYMREQ REQ4883
|
sl@0
|
85 |
*/
|
sl@0
|
86 |
LOCAL_C void doDirectFileStoresL()
|
sl@0
|
87 |
{
|
sl@0
|
88 |
TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));
|
sl@0
|
89 |
TParse directFileStoreName;
|
sl@0
|
90 |
directFileStoreName.Set(drive.Name(), &KDirectFileStoreName, NULL);
|
sl@0
|
91 |
TheDirectStoreFilePath.Copy(directFileStoreName.FullName());
|
sl@0
|
92 |
|
sl@0
|
93 |
// make sure directory exists
|
sl@0
|
94 |
TheFs.MkDirAll(directFileStoreName.DriveAndPath());
|
sl@0
|
95 |
|
sl@0
|
96 |
TTime start;
|
sl@0
|
97 |
start.HomeTime();
|
sl@0
|
98 |
for(int i=0; i<DFSTORERUNSIZE; i++)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
doStoreL(TheDirectStoreFilePath);
|
sl@0
|
101 |
}
|
sl@0
|
102 |
TTime end;
|
sl@0
|
103 |
end.HomeTime();
|
sl@0
|
104 |
TTimeIntervalMicroSeconds us = end.MicroSecondsFrom(start);
|
sl@0
|
105 |
TheTest.Printf(_L("CDirectFileStore, %d 'write' tests. Time=%ld ms\r\n"), DFSTORERUNSIZE, us.Int64() / 1000);
|
sl@0
|
106 |
|
sl@0
|
107 |
start.HomeTime();
|
sl@0
|
108 |
for(int j=0; j<DFSTORERUNSIZE;j++)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
doRestoreL(TheDirectStoreFilePath);
|
sl@0
|
111 |
}
|
sl@0
|
112 |
end.HomeTime();
|
sl@0
|
113 |
us = end.MicroSecondsFrom(start);
|
sl@0
|
114 |
TheTest.Printf(_L("CDirectFileStore, %d 'read' tests. Time=%ld ms\r\n"), DFSTORERUNSIZE, us.Int64() / 1000);
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
LOCAL_C void doStoreL(const TDesC& aName)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
// Construct an object of type CDFileStoreA and put some data into it
|
sl@0
|
120 |
_LIT(KTxtForClassA,"Text for CDFileStoreA");
|
sl@0
|
121 |
CDFileStoreA* theA = CDFileStoreA::NewLC();
|
sl@0
|
122 |
theA->SetTextL(KTxtForClassA);
|
sl@0
|
123 |
theA->iIntValue = -1;
|
sl@0
|
124 |
theA->iUintValue = 2;
|
sl@0
|
125 |
|
sl@0
|
126 |
// Construct an object of type CDFileStoreB and put some data into it
|
sl@0
|
127 |
_LIT(KTxtForClassB,"Text for CDFileStoreB");
|
sl@0
|
128 |
CDFileStoreB* theB = CDFileStoreB::NewLC();
|
sl@0
|
129 |
theB->iFixBuffer = KTxtForClassB;
|
sl@0
|
130 |
theB->iIntValue = -3;
|
sl@0
|
131 |
theB->iUintValue = 4;
|
sl@0
|
132 |
theB->iRealValue = 5.6;
|
sl@0
|
133 |
|
sl@0
|
134 |
// Construct an object of type CDFileStoreC and put some data into it
|
sl@0
|
135 |
_LIT(KTxtForClassC,"Text for CDFileStoreC");
|
sl@0
|
136 |
CDFileStoreC* theC = CDFileStoreC::NewLC();
|
sl@0
|
137 |
theC->iFixBuffer = KTxtForClassC;
|
sl@0
|
138 |
theC->AddNumberToArrayL();
|
sl@0
|
139 |
// Create (replace) the direct file store
|
sl@0
|
140 |
CFileStore* store = CDirectFileStore::ReplaceLC(TheFs,aName,EFileWrite);
|
sl@0
|
141 |
|
sl@0
|
142 |
// Must say what kind of file store.
|
sl@0
|
143 |
store->SetTypeL(KDirectFileStoreLayoutUid);
|
sl@0
|
144 |
|
sl@0
|
145 |
// Construct the output stream.
|
sl@0
|
146 |
RStoreWriteStream outstream;
|
sl@0
|
147 |
TStreamId id = outstream.CreateLC(*store);
|
sl@0
|
148 |
|
sl@0
|
149 |
// Stream out the CDFileStoreA, CDFileStoreB, and the CDFileStoreC object
|
sl@0
|
150 |
outstream << *theA << *theB << *theC;
|
sl@0
|
151 |
|
sl@0
|
152 |
// Commit changes to the stream
|
sl@0
|
153 |
outstream.CommitL();
|
sl@0
|
154 |
|
sl@0
|
155 |
// Cleanup the stream object
|
sl@0
|
156 |
CleanupStack::PopAndDestroy();
|
sl@0
|
157 |
|
sl@0
|
158 |
// Set this stream id as the root
|
sl@0
|
159 |
store->SetRootL(id);
|
sl@0
|
160 |
|
sl@0
|
161 |
// Commit changes to the store
|
sl@0
|
162 |
store->CommitL();
|
sl@0
|
163 |
// store
|
sl@0
|
164 |
// theC
|
sl@0
|
165 |
// theB
|
sl@0
|
166 |
CleanupStack::PopAndDestroy(4); // theA
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
LOCAL_C void doRestoreL(const TDesC& aName)
|
sl@0
|
170 |
{
|
sl@0
|
171 |
CDFileStoreA* theA = CDFileStoreA::NewLC();
|
sl@0
|
172 |
CDFileStoreB* theB = CDFileStoreB::NewLC();
|
sl@0
|
173 |
CDFileStoreC* theC = CDFileStoreC::NewLC();
|
sl@0
|
174 |
|
sl@0
|
175 |
// Open the direct file store
|
sl@0
|
176 |
CFileStore* store = CDirectFileStore::OpenLC(TheFs,aName,EFileRead);
|
sl@0
|
177 |
|
sl@0
|
178 |
// Construct and open the root stream which contains the representation of our objects.
|
sl@0
|
179 |
RStoreReadStream instream;
|
sl@0
|
180 |
instream.OpenLC(*store,store->Root());
|
sl@0
|
181 |
|
sl@0
|
182 |
// Stream in the CDFileStoreA object, the CDFileStoreB object and the CDFileStoreC object
|
sl@0
|
183 |
instream >> *theA >> *theB >> *theC;
|
sl@0
|
184 |
|
sl@0
|
185 |
CleanupStack::PopAndDestroy();
|
sl@0
|
186 |
CleanupStack::PopAndDestroy(4);
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
//***************************************************************
|
sl@0
|
190 |
CDFileStoreA* CDFileStoreA::NewLC()
|
sl@0
|
191 |
{
|
sl@0
|
192 |
CDFileStoreA* self = new (ELeave) CDFileStoreA;
|
sl@0
|
193 |
CleanupStack::PushL(self);
|
sl@0
|
194 |
return self;
|
sl@0
|
195 |
}
|
sl@0
|
196 |
|
sl@0
|
197 |
CDFileStoreA::~CDFileStoreA()
|
sl@0
|
198 |
{
|
sl@0
|
199 |
delete iVarBuffer;
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
void CDFileStoreA::SetTextL(const TDesC& aData)
|
sl@0
|
203 |
{
|
sl@0
|
204 |
iVarBuffer = aData.AllocL();
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
void CDFileStoreA::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
208 |
{
|
sl@0
|
209 |
aStream.WriteInt32L(iVarBuffer->Des().MaxLength());
|
sl@0
|
210 |
aStream << *iVarBuffer;
|
sl@0
|
211 |
aStream.WriteInt32L(iIntValue);
|
sl@0
|
212 |
aStream.WriteUint32L(iUintValue);
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
void CDFileStoreA::InternalizeL(RReadStream& aStream)
|
sl@0
|
216 |
{
|
sl@0
|
217 |
TInt maxlen;
|
sl@0
|
218 |
maxlen = aStream.ReadInt32L();
|
sl@0
|
219 |
iVarBuffer = HBufC::NewL(aStream,maxlen);
|
sl@0
|
220 |
iIntValue = aStream.ReadInt32L();
|
sl@0
|
221 |
iUintValue = aStream.ReadUint32L();
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
//***************************************************************
|
sl@0
|
225 |
CDFileStoreB* CDFileStoreB::NewLC()
|
sl@0
|
226 |
{
|
sl@0
|
227 |
CDFileStoreB* self = new (ELeave) CDFileStoreB;
|
sl@0
|
228 |
CleanupStack::PushL(self);
|
sl@0
|
229 |
return self;
|
sl@0
|
230 |
}
|
sl@0
|
231 |
|
sl@0
|
232 |
void CDFileStoreB::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
233 |
{
|
sl@0
|
234 |
aStream << iFixBuffer;
|
sl@0
|
235 |
aStream.WriteInt32L(iIntValue);
|
sl@0
|
236 |
aStream.WriteUint32L(iUintValue);
|
sl@0
|
237 |
aStream.WriteReal64L(iRealValue);
|
sl@0
|
238 |
}
|
sl@0
|
239 |
|
sl@0
|
240 |
void CDFileStoreB::InternalizeL(RReadStream& aStream)
|
sl@0
|
241 |
{
|
sl@0
|
242 |
aStream >> iFixBuffer;
|
sl@0
|
243 |
iIntValue = aStream.ReadInt32L();
|
sl@0
|
244 |
iUintValue = aStream.ReadUint32L();
|
sl@0
|
245 |
iRealValue = aStream.ReadReal64L();
|
sl@0
|
246 |
}
|
sl@0
|
247 |
|
sl@0
|
248 |
//***************************************************************
|
sl@0
|
249 |
CDFileStoreC* CDFileStoreC::NewLC()
|
sl@0
|
250 |
{
|
sl@0
|
251 |
CDFileStoreC* self = new (ELeave) CDFileStoreC;
|
sl@0
|
252 |
CleanupStack::PushL(self);
|
sl@0
|
253 |
self->ConstructL();
|
sl@0
|
254 |
return self;
|
sl@0
|
255 |
}
|
sl@0
|
256 |
|
sl@0
|
257 |
void CDFileStoreC::ConstructL()
|
sl@0
|
258 |
{
|
sl@0
|
259 |
iArray = new (ELeave) CArrayFixFlat<TInt>(DFSTORERUNSIZE);
|
sl@0
|
260 |
nArray = new (ELeave) CArrayFixFlat<TElement>(DFSTORERUNSIZE);
|
sl@0
|
261 |
}
|
sl@0
|
262 |
|
sl@0
|
263 |
void CDFileStoreC::AddNumberToArrayL(/*TInt aValue*/)
|
sl@0
|
264 |
{
|
sl@0
|
265 |
TElement theElement;
|
sl@0
|
266 |
_LIT(KFormatTxt,"BenchMarkingDirectFileStore%4u");
|
sl@0
|
267 |
TBuf<256> str(KFormatTxt);
|
sl@0
|
268 |
|
sl@0
|
269 |
for (TInt index = 0; index < DFSTORERUNSIZE; index++)
|
sl@0
|
270 |
{
|
sl@0
|
271 |
iArray->AppendL((index+99999));
|
sl@0
|
272 |
theElement.iData.Format(KFormatTxt,index);
|
sl@0
|
273 |
nArray->AppendL(theElement);
|
sl@0
|
274 |
}
|
sl@0
|
275 |
}
|
sl@0
|
276 |
|
sl@0
|
277 |
CDFileStoreC::~CDFileStoreC()
|
sl@0
|
278 |
{
|
sl@0
|
279 |
delete iArray;
|
sl@0
|
280 |
delete nArray;
|
sl@0
|
281 |
}
|
sl@0
|
282 |
|
sl@0
|
283 |
void CDFileStoreC::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
284 |
{
|
sl@0
|
285 |
aStream << iFixBuffer;
|
sl@0
|
286 |
|
sl@0
|
287 |
TInt count = iArray->Count();
|
sl@0
|
288 |
aStream.WriteInt32L(count);
|
sl@0
|
289 |
TElement theElement;
|
sl@0
|
290 |
for (TInt index = 0; index < count; index++)
|
sl@0
|
291 |
{
|
sl@0
|
292 |
aStream.WriteInt32L((*iArray)[index]);
|
sl@0
|
293 |
theElement =((*nArray)[index]);
|
sl@0
|
294 |
aStream.WriteL(theElement.iData, 31);
|
sl@0
|
295 |
}
|
sl@0
|
296 |
}
|
sl@0
|
297 |
|
sl@0
|
298 |
void CDFileStoreC::InternalizeL(RReadStream& aStream)
|
sl@0
|
299 |
{
|
sl@0
|
300 |
aStream >> iFixBuffer;
|
sl@0
|
301 |
|
sl@0
|
302 |
TInt count;
|
sl@0
|
303 |
count = aStream.ReadInt32L();
|
sl@0
|
304 |
TElement theElement;
|
sl@0
|
305 |
//nArray = new (ELeave) CArrayFixFlat<TElement>(10);
|
sl@0
|
306 |
nArray->Reset();
|
sl@0
|
307 |
for (TInt index = 0; index < count; index++)
|
sl@0
|
308 |
{
|
sl@0
|
309 |
iArray->AppendL(aStream.ReadInt32L());
|
sl@0
|
310 |
aStream.ReadL(theElement.iData, 31);
|
sl@0
|
311 |
nArray->AppendL(theElement);
|
sl@0
|
312 |
}
|
sl@0
|
313 |
}
|