branch | RCL_3 |
changeset 14 | 04ec7606545c |
parent 9 | 667e88a979d7 |
child 15 | fcc16690f446 |
12:6b6fd149daa2 | 14:04ec7606545c |
---|---|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
20 |
20 |
21 #ifdef _SQLPROFILER |
21 #ifdef _SQLPROFILER |
22 |
22 |
23 extern TBool TheOsCallTimeDetailedProfileEnabled;//If true, the OS porting layer call details are enabled and for each call an entry will be added to the log file (epocwind.out). |
23 extern TBool TheOsCallTimeDetailedProfileEnabled;//If true, the OS porting layer call details are enabled and for each call an entry will be added to the log file (epocwind.out). |
24 |
24 |
25 #define PROFILE_READ(pos,amount) \ |
25 #define PROFILE_READ(pos, amount, err) \ |
26 do \ |
26 do \ |
27 { \ |
27 { \ |
28 if(TheOsCallTimeDetailedProfileEnabled) \ |
28 if(TheOsCallTimeDetailedProfileEnabled) \ |
29 { \ |
29 { \ |
30 ++iFileReadCount; iFileReadAmount += (amount); \ |
30 ++iFileReadCount; iFileReadAmount += (amount); \ |
31 RDebug::Print(_L(" -- FRead this=%X, Cnt=%d, Pos=%ld, Amt=%d, Ttl=%ld\r\n"), (TUint32)this, iFileReadCount, pos, amount, iFileReadAmount); \ |
31 RDebug::Print(_L("[SQL-FBUF]¬RD¬%X¬%d¬%ld¬%d¬%ld¬%d\r\n"), (TUint32)this, iFileReadCount, pos, amount, iFileReadAmount, err); \ |
32 } \ |
32 } \ |
33 } while(0) |
33 } while(0) |
34 |
34 |
35 #define PROFILE_WRITE(pos,amount) \ |
35 #define PROFILE_WRITE(pos, amount, err) \ |
36 do \ |
36 do \ |
37 { \ |
37 { \ |
38 if(TheOsCallTimeDetailedProfileEnabled) \ |
38 if(TheOsCallTimeDetailedProfileEnabled) \ |
39 { \ |
39 { \ |
40 ++iFileWriteCount; iFileWriteAmount += (amount); \ |
40 ++iFileWriteCount; iFileWriteAmount += (amount); \ |
41 RDebug::Print(_L(" -- FWrite this=%X, Cnt=%d, Pos=%ld, Amt=%d, Ttl=%ld\r\n"), (TUint32)this, iFileWriteCount, pos, amount, iFileWriteAmount); \ |
41 RDebug::Print(_L("[SQL-FBUF]¬WR¬%X¬%d¬%ld¬%d¬%ld¬%d\r\n"), (TUint32)this, iFileWriteCount, pos, amount, iFileWriteAmount, err); \ |
42 } \ |
42 } \ |
43 } while(0) |
43 } while(0) |
44 |
44 |
45 #define PROFILE_SIZE() \ |
45 #define PROFILE_SIZE(size, err) \ |
46 do \ |
46 do \ |
47 { \ |
47 { \ |
48 if(TheOsCallTimeDetailedProfileEnabled) \ |
48 if(TheOsCallTimeDetailedProfileEnabled) \ |
49 { \ |
49 { \ |
50 ++iFileSizeCount; \ |
50 ++iFileSizeCount; \ |
51 RDebug::Print(_L(" -- FSize this=%X, Cnt=%d\r\n"), (TUint32)this, iFileSizeCount); \ |
51 RDebug::Print(_L("[SQL-FBUF]¬SZ¬%X¬%d¬%ld¬%d¬%ld¬%d\r\n"), (TUint32)this, iFileSizeCount, size, 0, 0LL, err); \ |
52 } \ |
52 } \ |
53 } while(0) |
53 } while(0) |
54 |
54 |
55 #define PROFILE_SETSIZE() \ |
55 #define PROFILE_SETSIZE(size, err) \ |
56 do \ |
56 do \ |
57 { \ |
57 { \ |
58 if(TheOsCallTimeDetailedProfileEnabled) \ |
58 if(TheOsCallTimeDetailedProfileEnabled) \ |
59 { \ |
59 { \ |
60 ++iFileSetSizeCount; \ |
60 ++iFileSetSizeCount; \ |
61 RDebug::Print(_L(" -- FSetSize this=%X, Cnt=%d\r\n"), (TUint32)this, iFileSetSizeCount); \ |
61 RDebug::Print(_L("[SQL-FBUF]¬SS¬%X¬%d¬%ld¬%d¬%ld¬%d\r\n"), (TUint32)this, iFileSetSizeCount, size, 0, 0LL, err); \ |
62 } \ |
62 } \ |
63 } while(0) |
63 } while(0) |
64 |
64 |
65 #define PROFILE_FLUSH() \ |
65 #define PROFILE_FLUSH(err) \ |
66 do \ |
66 do \ |
67 { \ |
67 { \ |
68 if(TheOsCallTimeDetailedProfileEnabled) \ |
68 if(TheOsCallTimeDetailedProfileEnabled) \ |
69 { \ |
69 { \ |
70 ++iFileFlushCount; \ |
70 ++iFileFlushCount; \ |
71 RDebug::Print(_L(" -- FFlush this=%X, Cnt=%d\r\n"), (TUint32)this, iFileFlushCount); \ |
71 RDebug::Print(_L("[SQL-FBUF]¬SY¬%X¬%d¬%ld¬%d¬%ld¬%d\r\n"), (TUint32)this, iFileFlushCount, 0LL, 0, 0LL, err); \ |
72 } \ |
72 } \ |
73 } while(0) |
73 } while(0) |
74 |
74 |
75 #define PROFILE_CREATE(fname, err) \ |
|
76 do \ |
|
77 { \ |
|
78 if(TheOsCallTimeDetailedProfileEnabled) \ |
|
79 { \ |
|
80 RDebug::Print(_L("[SQL-FBUF]¬CR¬%X¬%S¬%d\r\n"), (TUint32)this, &fname, err); \ |
|
81 } \ |
|
82 } while(0) |
|
83 |
|
84 #define PROFILE_OPEN(fname, err) \ |
|
85 do \ |
|
86 { \ |
|
87 if(TheOsCallTimeDetailedProfileEnabled) \ |
|
88 { \ |
|
89 RDebug::Print(_L("[SQL-FBUF]¬OP¬%X¬%S¬%d\r\n"), (TUint32)this, &fname, err); \ |
|
90 } \ |
|
91 } while(0) |
|
92 |
|
93 #define PROFILE_TEMP(fname, err) \ |
|
94 do \ |
|
95 { \ |
|
96 if(TheOsCallTimeDetailedProfileEnabled) \ |
|
97 { \ |
|
98 RDebug::Print(_L("[SQL-FBUF]¬TP¬%X¬%S¬%d\r\n"), (TUint32)this, &fname, err); \ |
|
99 } \ |
|
100 } while(0) |
|
101 |
|
102 #define PROFILE_ADOPT(fname, err) \ |
|
103 do \ |
|
104 { \ |
|
105 if(TheOsCallTimeDetailedProfileEnabled) \ |
|
106 { \ |
|
107 RDebug::Print(_L("[SQL-FBUF]¬AT¬%X¬%S¬%d\r\n"), (TUint32)this, &fname, err); \ |
|
108 } \ |
|
109 } while(0) |
|
110 |
|
111 #define PROFILE_CLOSE() \ |
|
112 do \ |
|
113 { \ |
|
114 if(TheOsCallTimeDetailedProfileEnabled) \ |
|
115 { \ |
|
116 RDebug::Print(_L("[SQL-FBUF]¬CL¬%X\r\n"), (TUint32)this); \ |
|
117 } \ |
|
118 } while(0) |
|
119 |
|
75 //Resets the profiler counters |
120 //Resets the profiler counters |
76 void RFileBuf64::ProfilerReset() |
121 void RFileBuf64::ProfilerReset() |
77 { |
122 { |
78 iFileReadCount = 0; iFileReadAmount = 0; iFileWriteCount = 0; iFileWriteAmount = 0; iFileSizeCount = 0; iFileSetSizeCount = 0; iFileFlushCount = 0; |
123 iFileReadCount = 0; iFileReadAmount = 0; iFileWriteCount = 0; iFileWriteAmount = 0; iFileSizeCount = 0; iFileSetSizeCount = 0; iFileFlushCount = 0; |
79 } |
124 } |
80 |
125 |
81 #else |
126 #else |
82 |
127 |
83 #define PROFILE_READ(pos,amount) void(0) |
128 #define PROFILE_READ(pos,amount, err) void(0) |
84 #define PROFILE_WRITE(pos,amount) void(0) |
129 #define PROFILE_WRITE(pos,amount, err) void(0) |
85 |
130 |
86 #define PROFILE_SIZE() void(0) |
131 #define PROFILE_SIZE(size, err) void(0) |
87 #define PROFILE_SETSIZE() void(0) |
132 #define PROFILE_SETSIZE(size, err) void(0) |
88 #define PROFILE_FLUSH() void(0) |
133 #define PROFILE_FLUSH(err) void(0) |
134 |
|
135 #define PROFILE_CREATE(fname, err) void(0) |
|
136 #define PROFILE_OPEN(fname, err) void(0) |
|
137 #define PROFILE_TEMP(fname, err) void(0) |
|
138 #define PROFILE_ADOPT(fname, err) void(0) |
|
139 #define PROFILE_CLOSE() void(0) |
|
89 |
140 |
90 #endif//_SQLPROFILER |
141 #endif//_SQLPROFILER |
91 |
142 |
92 /** |
143 /** |
93 This constant is used for initializing the RFileBuf64::iFileSize data member and means that |
144 This constant is used for initializing the RFileBuf64::iFileSize data member and means that |
236 TInt err = DoPreInit(); |
287 TInt err = DoPreInit(); |
237 if(err == KErrNone) |
288 if(err == KErrNone) |
238 { |
289 { |
239 err = iFile.Create(aFs, aFileName, aFileMode); |
290 err = iFile.Create(aFs, aFileName, aFileMode); |
240 } |
291 } |
292 PROFILE_CREATE(aFileName, err); |
|
241 return DoPostInit(err); |
293 return DoPostInit(err); |
242 } |
294 } |
243 |
295 |
244 /** |
296 /** |
245 Initializes the RFileBuf64 object and opens an existing file that will be accessed through RFileBuf64 public interface. |
297 Initializes the RFileBuf64 object and opens an existing file that will be accessed through RFileBuf64 public interface. |
267 TInt err = DoPreInit(); |
319 TInt err = DoPreInit(); |
268 if(err == KErrNone) |
320 if(err == KErrNone) |
269 { |
321 { |
270 err = iFile.Open(aFs, aFileName, aFileMode); |
322 err = iFile.Open(aFs, aFileName, aFileMode); |
271 } |
323 } |
324 PROFILE_OPEN(aFileName, err); |
|
272 return DoPostInit(err); |
325 return DoPostInit(err); |
273 } |
326 } |
274 |
327 |
275 /** |
328 /** |
276 Initializes the RFileBuf64 object and creates and opens a temporary file with unique name that will be accessed through |
329 Initializes the RFileBuf64 object and creates and opens a temporary file with unique name that will be accessed through |
298 TInt err = DoPreInit(); |
351 TInt err = DoPreInit(); |
299 if(err == KErrNone) |
352 if(err == KErrNone) |
300 { |
353 { |
301 err = iFile.Temp(aFs, aPath, aFileName, aFileMode); |
354 err = iFile.Temp(aFs, aPath, aFileName, aFileMode); |
302 } |
355 } |
356 PROFILE_TEMP(aFileName, err); |
|
303 return DoPostInit(err); |
357 return DoPostInit(err); |
304 } |
358 } |
305 |
359 |
306 /** |
360 /** |
307 Initializes the RFileBuf64 object and creates and adopts an already open file from a client that will be accessed through |
361 Initializes the RFileBuf64 object and creates and adopts an already open file from a client that will be accessed through |
334 TInt err = DoPreInit(); |
388 TInt err = DoPreInit(); |
335 if(err == KErrNone) |
389 if(err == KErrNone) |
336 { |
390 { |
337 err = iFile.AdoptFromClient(aMsg, aFsIndex, aFileIndex); |
391 err = iFile.AdoptFromClient(aMsg, aFsIndex, aFileIndex); |
338 } |
392 } |
393 PROFILE_ADOPT(KNullDesC, err); |
|
339 return DoPostInit(err); |
394 return DoPostInit(err); |
340 } |
395 } |
341 |
396 |
342 /** |
397 /** |
343 Writes to the file the pending data (if the buffer contains pending data), closes the file and releases |
398 Writes to the file the pending data (if the buffer contains pending data), closes the file and releases |
354 (void)DoFileWrite2(); |
409 (void)DoFileWrite2(); |
355 } |
410 } |
356 iFile.Close(); |
411 iFile.Close(); |
357 User::Free(iBase); |
412 User::Free(iBase); |
358 iBase = 0; |
413 iBase = 0; |
414 PROFILE_CLOSE(); |
|
359 } |
415 } |
360 |
416 |
361 /** |
417 /** |
362 Calculates and sets optimal read-ahead buffer size. |
418 Calculates and sets optimal read-ahead buffer size. |
363 aBlockSize and aReadRecBufSize values are retrieved by the caller from the file system. |
419 aBlockSize and aReadRecBufSize values are retrieved by the caller from the file system. |
439 err = DoFileWrite1(aFilePos); |
495 err = DoFileWrite1(aFilePos); |
440 } |
496 } |
441 if(err == KErrNone) |
497 if(err == KErrNone) |
442 { |
498 { |
443 err = iFile.Read(aFilePos, aDes); |
499 err = iFile.Read(aFilePos, aDes); |
444 PROFILE_READ(aFilePos, aDes.Size()); |
500 PROFILE_READ(aFilePos, aDes.Size(), err); |
445 } |
501 } |
446 __FILEBUF64_INVARIANT(); |
502 __FILEBUF64_INVARIANT(); |
447 return err; |
503 return err; |
448 } |
504 } |
449 //4. The requested data size is smaller than the buffer capacity |
505 //4. The requested data size is smaller than the buffer capacity |
470 if(iNextReadFilePos != aFilePos) |
526 if(iNextReadFilePos != aFilePos) |
471 {//Guessed read ahead was wrong. Direct "file read" operation |
527 {//Guessed read ahead was wrong. Direct "file read" operation |
472 iNextReadFilePosHits = 0; |
528 iNextReadFilePosHits = 0; |
473 TPtr8 ptr2(outptr, len); |
529 TPtr8 ptr2(outptr, len); |
474 err = iFile.Read(aFilePos, ptr2); |
530 err = iFile.Read(aFilePos, ptr2); |
475 PROFILE_READ(aFilePos, ptr2.Size()); |
531 PROFILE_READ(aFilePos, ptr2.Size(), err); |
476 if(err == KErrNone) |
532 if(err == KErrNone) |
477 { |
533 { |
478 iNextReadFilePos = aFilePos + len; |
534 iNextReadFilePos = aFilePos + len; |
479 len -= ptr2.Length(); |
535 len -= ptr2.Length(); |
480 } |
536 } |
494 // if read-ahead doesn't cross block boundary do it all |
550 // if read-ahead doesn't cross block boundary do it all |
495 readahead = maxReadAhead; |
551 readahead = maxReadAhead; |
496 } |
552 } |
497 TPtr8 ptr(iBase, Min(iCapacity, (len + readahead))); |
553 TPtr8 ptr(iBase, Min(iCapacity, (len + readahead))); |
498 err = iFile.Read(aFilePos, ptr); |
554 err = iFile.Read(aFilePos, ptr); |
499 PROFILE_READ(aFilePos, ptr.Size()); |
555 PROFILE_READ(aFilePos, ptr.Size(), err); |
500 if(err == KErrNone) |
556 if(err == KErrNone) |
501 { |
557 { |
502 iFilePos = aFilePos; |
558 iFilePos = aFilePos; |
503 iLength = ptr.Length(); |
559 iLength = ptr.Length(); |
504 iNextReadFilePos = iFilePos + iLength; |
560 iNextReadFilePos = iFilePos + iLength; |
785 if(iFileSize != KFileSizeNotSet) |
841 if(iFileSize != KFileSizeNotSet) |
786 { |
842 { |
787 __FILEBUF64_INVARIANT(); |
843 __FILEBUF64_INVARIANT(); |
788 return KErrNone; |
844 return KErrNone; |
789 } |
845 } |
790 PROFILE_SIZE(); |
|
791 TInt err = iFile.Size(iFileSize); |
846 TInt err = iFile.Size(iFileSize); |
847 PROFILE_SIZE(iFileSize, err); |
|
792 if(err != KErrNone) |
848 if(err != KErrNone) |
793 { |
849 { |
794 DoDiscard(); |
850 DoDiscard(); |
795 } |
851 } |
796 __FILEBUF64_INVARIANT(); |
852 __FILEBUF64_INVARIANT(); |
823 //If the new file size is "in" the buffer then change the "iLength" |
879 //If the new file size is "in" the buffer then change the "iLength" |
824 else if(aFileSize < (iFilePos + iLength)) |
880 else if(aFileSize < (iFilePos + iLength)) |
825 { |
881 { |
826 iLength = aFileSize - iFilePos; |
882 iLength = aFileSize - iFilePos; |
827 } |
883 } |
828 PROFILE_SETSIZE(); |
|
829 TInt err = iFile.SetSize(aFileSize); |
884 TInt err = iFile.SetSize(aFileSize); |
885 PROFILE_SETSIZE(aFileSize, err); |
|
830 if(err != KErrNone) |
886 if(err != KErrNone) |
831 { |
887 { |
832 DoDiscard(); |
888 DoDiscard(); |
833 } |
889 } |
834 else |
890 else |
855 if(err != KErrNone) |
911 if(err != KErrNone) |
856 { |
912 { |
857 __FILEBUF64_INVARIANT(); |
913 __FILEBUF64_INVARIANT(); |
858 return err; |
914 return err; |
859 } |
915 } |
860 PROFILE_FLUSH(); |
|
861 err = iFile.Flush(); |
916 err = iFile.Flush(); |
917 PROFILE_FLUSH(err); |
|
862 if(err != KErrNone) |
918 if(err != KErrNone) |
863 { |
919 { |
864 DoDiscard(); |
920 DoDiscard(); |
865 } |
921 } |
866 iLength = 0; |
922 iLength = 0; |
887 if(iLength == 0) |
943 if(iLength == 0) |
888 { |
944 { |
889 __FILEBUF64_INVARIANT(); |
945 __FILEBUF64_INVARIANT(); |
890 return KErrNone; |
946 return KErrNone; |
891 } |
947 } |
892 PROFILE_WRITE(iFilePos, iLength); |
|
893 TPtrC8 data(iBase, iLength); |
948 TPtrC8 data(iBase, iLength); |
894 TInt err = iFile.Write(iFilePos, data); |
949 TInt err = iFile.Write(iFilePos, data); |
950 PROFILE_WRITE(iFilePos, iLength, err); |
|
895 if(err == KErrNone) |
951 if(err == KErrNone) |
896 { |
952 { |
897 iFileSize = Max(iFileSize, (iFilePos + iLength)); |
953 iFileSize = Max(iFileSize, (iFilePos + iLength)); |
898 } |
954 } |
899 else |
955 else |