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("[SQL-FBUF]¬RD¬%X¬%d¬%ld¬%d¬%ld¬%d\r\n"), (TUint32)this, iFileReadCount, pos, amount, iFileReadAmount, err); \ |
31 RDebug::Print(_L("[SQL-FBUF]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬Read¬%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, err) \ |
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("[SQL-FBUF]¬WR¬%X¬%d¬%ld¬%d¬%ld¬%d\r\n"), (TUint32)this, iFileWriteCount, pos, amount, iFileWriteAmount, err); \ |
41 RDebug::Print(_L("[SQL-FBUF]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬Write¬%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(size, err) \ |
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("[SQL-FBUF]¬SZ¬%X¬%d¬%ld¬%d¬%ld¬%d\r\n"), (TUint32)this, iFileSizeCount, size, 0, 0LL, err); \ |
51 RDebug::Print(_L("[SQL-FBUF]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬Size¬%d¬%ld¬¬¬%d\r\n"), (TUint32)this, iFileSizeCount, size, err); \ |
52 } \ |
52 } \ |
53 } while(0) |
53 } while(0) |
54 |
54 |
55 #define PROFILE_SETSIZE(size, err) \ |
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("[SQL-FBUF]¬SS¬%X¬%d¬%ld¬%d¬%ld¬%d\r\n"), (TUint32)this, iFileSetSizeCount, size, 0, 0LL, err); \ |
61 RDebug::Print(_L("[SQL-FBUF]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬SetSize¬%d¬%ld¬¬¬%d\r\n"), (TUint32)this, iFileSetSizeCount, size, err); \ |
62 } \ |
62 } \ |
63 } while(0) |
63 } while(0) |
64 |
64 |
65 #define PROFILE_FLUSH(err) \ |
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("[SQL-FBUF]¬SY¬%X¬%d¬%ld¬%d¬%ld¬%d\r\n"), (TUint32)this, iFileFlushCount, 0LL, 0, 0LL, err); \ |
71 RDebug::Print(_L("[SQL-FBUF]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬Flush¬%d¬¬¬¬%d\r\n"), (TUint32)this, iFileFlushCount, err); \ |
72 } \ |
72 } \ |
73 } while(0) |
73 } while(0) |
74 |
74 |
75 #define PROFILE_CREATE(fname, err) \ |
75 #define PROFILE_CREATE(fname, err) \ |
76 do \ |
76 do \ |
77 { \ |
77 { \ |
78 if(TheOsCallTimeDetailedProfileEnabled) \ |
78 if(TheOsCallTimeDetailedProfileEnabled) \ |
79 { \ |
79 { \ |
80 RDebug::Print(_L("[SQL-FBUF]¬CR¬%X¬%S¬%d\r\n"), (TUint32)this, &fname, err); \ |
80 RDebug::Print(_L("[SQL-FBUF]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬Create¬¬¬¬¬%d¬%S\r\n"), (TUint32)this, err, &fname); \ |
81 } \ |
81 } \ |
82 } while(0) |
82 } while(0) |
83 |
83 |
84 #define PROFILE_OPEN(fname, err) \ |
84 #define PROFILE_OPEN(fname, err) \ |
85 do \ |
85 do \ |
86 { \ |
86 { \ |
87 if(TheOsCallTimeDetailedProfileEnabled) \ |
87 if(TheOsCallTimeDetailedProfileEnabled) \ |
88 { \ |
88 { \ |
89 RDebug::Print(_L("[SQL-FBUF]¬OP¬%X¬%S¬%d\r\n"), (TUint32)this, &fname, err); \ |
89 RDebug::Print(_L("[SQL-FBUF]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬Open¬¬¬¬¬%d¬%S\r\n"), (TUint32)this, err, &fname); \ |
90 } \ |
90 } \ |
91 } while(0) |
91 } while(0) |
92 |
92 |
93 #define PROFILE_TEMP(fname, err) \ |
93 #define PROFILE_TEMP(fname, err) \ |
94 do \ |
94 do \ |
95 { \ |
95 { \ |
96 if(TheOsCallTimeDetailedProfileEnabled) \ |
96 if(TheOsCallTimeDetailedProfileEnabled) \ |
97 { \ |
97 { \ |
98 RDebug::Print(_L("[SQL-FBUF]¬TP¬%X¬%S¬%d\r\n"), (TUint32)this, &fname, err); \ |
98 RDebug::Print(_L("[SQL-FBUF]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬Temp¬¬¬¬¬%d¬%S\r\n"), (TUint32)this, err, &fname); \ |
99 } \ |
99 } \ |
100 } while(0) |
100 } while(0) |
101 |
101 |
102 #define PROFILE_ADOPT(fname, err) \ |
102 #define PROFILE_ADOPT(fname, err) \ |
103 do \ |
103 do \ |
104 { \ |
104 { \ |
105 if(TheOsCallTimeDetailedProfileEnabled) \ |
105 if(TheOsCallTimeDetailedProfileEnabled) \ |
106 { \ |
106 { \ |
107 RDebug::Print(_L("[SQL-FBUF]¬AT¬%X¬%S¬%d\r\n"), (TUint32)this, &fname, err); \ |
107 RDebug::Print(_L("[SQL-FBUF]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬Adopt¬¬¬¬¬%d¬%S\r\n"), (TUint32)this, err, &fname); \ |
108 } \ |
108 } \ |
109 } while(0) |
109 } while(0) |
110 |
110 |
111 #define PROFILE_CLOSE() \ |
111 #define PROFILE_CLOSE() \ |
112 do \ |
112 do \ |
113 { \ |
113 { \ |
114 if(TheOsCallTimeDetailedProfileEnabled) \ |
114 if(TheOsCallTimeDetailedProfileEnabled) \ |
115 { \ |
115 { \ |
116 RDebug::Print(_L("[SQL-FBUF]¬CL¬%X\r\n"), (TUint32)this); \ |
116 RDebug::Print(_L("[SQL-FBUF]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬Close¬¬¬¬¬¬\r\n"), (TUint32)this); \ |
117 } \ |
117 } \ |
118 } while(0) |
118 } while(0) |
119 |
119 |
120 //Resets the profiler counters |
120 //Resets the profiler counters |
121 void RFileBuf64::ProfilerReset() |
121 void RFileBuf64::ProfilerReset() |
247 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
248 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
248 |
249 |
249 /** |
250 /** |
250 Initializes RFileBuf64 data members with their default values. |
251 Initializes RFileBuf64 data members with their default values. |
251 |
252 |
252 @param aSize Max file buffer size (capacity) in bytes. |
253 @param aMinCapacity Minimal file buffer size (capacity) in bytes. |
253 |
254 |
254 @panic FBuf64 1 In _DEBUG mode - aSize is 0 or negative. |
255 @panic FBuf64 1 In _DEBUG mode - aMinCapacity is 0 or negative. |
255 */ |
256 */ |
256 RFileBuf64::RFileBuf64(TInt aSize) : |
257 RFileBuf64::RFileBuf64(TInt aMinCapacity) : |
257 iCapacity(aSize), |
258 iCapacity(aMinCapacity), |
258 iReadAheadSize(RFileBuf64::KDefaultReadAheadSize) |
259 iReadAheadSize(RFileBuf64::KDefaultReadAheadSize), |
259 { |
260 iOptimized(EFalse) |
260 __FBUF64_ASSERT(aSize > 0, EFBufPanicCapacity); |
261 { |
|
262 __FBUF64_ASSERT(aMinCapacity > 0, EFBufPanicCapacity); |
261 } |
263 } |
262 |
264 |
263 /** |
265 /** |
264 Initializes the RFileBuf64 object and creates and opens a new file that will be accessed through RFileBuf64 public interface. |
266 Initializes the RFileBuf64 object and creates and opens a new file that will be accessed through RFileBuf64 public interface. |
265 If the file already exists, an error is returned. |
267 If the file already exists, an error is returned. |
471 TInt RFileBuf64::Read(TInt64 aFilePos, TDes8& aDes) |
473 TInt RFileBuf64::Read(TInt64 aFilePos, TDes8& aDes) |
472 { |
474 { |
473 __FBUF64_ASSERT(aFilePos >= 0, EFBufPanicFilePos); |
475 __FBUF64_ASSERT(aFilePos >= 0, EFBufPanicFilePos); |
474 __FILEBUF64_INVARIANT(); |
476 __FILEBUF64_INVARIANT(); |
475 aDes.SetLength(0); |
477 aDes.SetLength(0); |
476 //1. The output buffer max len is 0 |
478 //0. The output buffer max len is 0 |
477 if(aDes.MaxLength() == 0) |
479 if(aDes.MaxLength() == 0) |
478 { |
480 { |
479 __FILEBUF64_INVARIANT(); |
481 __FILEBUF64_INVARIANT(); |
480 return KErrNone; |
482 return KErrNone; |
481 } |
483 } |
482 //2. Initialize the "iFileSize" if it is not initialized yet |
484 //1. Initialize the "iFileSize" if it is not initialized yet |
483 TInt err = DoFileSize(); |
485 TInt err = DoFileSize(); |
484 if(err != KErrNone) |
486 if(err != KErrNone) |
485 { |
487 { |
486 __FILEBUF64_INVARIANT(); |
488 __FILEBUF64_INVARIANT(); |
487 return err; |
489 return err; |
488 } |
490 } |
|
491 //2. Optimize the buffer capacity |
|
492 TInt len = aDes.MaxLength(); |
|
493 if((err = DoSetCapacity(len)) != KErrNone) |
|
494 { |
|
495 return err; |
|
496 } |
489 //3. Too big "read" request - read directly from the file |
497 //3. Too big "read" request - read directly from the file |
490 TInt len = aDes.MaxLength(); |
|
491 if(len > iCapacity) |
498 if(len > iCapacity) |
492 { |
499 { |
493 if((aFilePos + len) > iFilePos && aFilePos < (iFilePos + iLength)) |
500 if((aFilePos + len) > iFilePos && aFilePos < (iFilePos + iLength)) |
494 {//Write the pending data if the iDirty flag is set, otherwise preserve the buffer content. |
501 {//Write the pending data if the iDirty flag is set, otherwise preserve the buffer content. |
495 err = DoFileWrite1(aFilePos); |
502 err = DoFileWrite1(aFilePos); |
1076 iNextReadFilePosHits = 0; |
1087 iNextReadFilePosHits = 0; |
1077 } |
1088 } |
1078 __FILEBUF64_INVARIANT(); |
1089 __FILEBUF64_INVARIANT(); |
1079 } |
1090 } |
1080 |
1091 |
|
1092 /** |
|
1093 Sets the most appropriate buffer capacity based on the database page size. |
|
1094 The function does a lazy evaluation. The first time the function is called and |
|
1095 aRwDataLength parameter is recognized to be a database or journal page size, the new (optimal) |
|
1096 buffer capacity is calculated and set. All next DoSetCapacity() calls will detect that the new |
|
1097 capacity is already set and will return KErrNone. |
|
1098 |
|
1099 @param aRwDataLength The length of the data being read or written. |
|
1100 @return KErrNone The new capacity was set successfully, |
|
1101 KErrNoMemory Out of memory. |
|
1102 */ |
|
1103 TInt RFileBuf64::DoSetCapacity(TInt aRwDataLength) |
|
1104 { |
|
1105 const TInt KMinPageCount = 4;//the buffer capacity should be at least (KMinPageCount * page size) |
|
1106 //but not less than the original capacity. |
|
1107 const TInt KDefaultPageSize = 1024;//The journal header size is equal to 512 bytes, so it is not easy |
|
1108 //to detect the 512 bytes page size. |
|
1109 |
|
1110 __FBUF64_ASSERT(aRwDataLength >= 0, EFBufPanicRwDataLength); |
|
1111 __FILEBUF64_INVARIANT(); |
|
1112 if(iOptimized || aRwDataLength == 0) |
|
1113 { |
|
1114 __FILEBUF64_INVARIANT(); |
|
1115 return KErrNone; |
|
1116 } |
|
1117 if((aRwDataLength & (aRwDataLength - 1)) != 0 || aRwDataLength < KDefaultPageSize) |
|
1118 { |
|
1119 __FILEBUF64_INVARIANT(); |
|
1120 return KErrNone; |
|
1121 } |
|
1122 //Here: aRwDataLength is power of 2 and is bigger than the default db page size. |
|
1123 //aRwDataLength is the size of the db page. |
|
1124 const TInt pageSize = aRwDataLength; |
|
1125 TInt cnt = iCapacity / pageSize;//how many pages can fit in the buffer now |
|
1126 TInt pageCount = Max(cnt, KMinPageCount);//the number of pages that should fit in the new buffer |
|
1127 TInt newBufCapacity = pageCount * pageSize; |
|
1128 if(newBufCapacity != iCapacity) |
|
1129 { |
|
1130 TUint8* newBase = static_cast <TUint8*> (User::ReAlloc(iBase, newBufCapacity)); |
|
1131 if(!newBase) |
|
1132 { |
|
1133 __FILEBUF64_INVARIANT(); |
|
1134 return KErrNoMemory; |
|
1135 } |
|
1136 iBase = newBase; |
|
1137 iCapacity = newBufCapacity; |
|
1138 //Adjust the initial read-ahead size to be multiple of the page size. |
|
1139 if((iReadAheadSize % pageSize) != 0) |
|
1140 { |
|
1141 TInt q = iReadAheadSize / pageSize; |
|
1142 iReadAheadSize = q != 0 ? pageSize * q : pageSize; |
|
1143 } |
|
1144 } |
|
1145 iOptimized = ETrue; |
|
1146 __FILEBUF64_INVARIANT(); |
|
1147 return KErrNone; |
|
1148 } |
|
1149 |
1081 #ifdef _DEBUG |
1150 #ifdef _DEBUG |
1082 |
1151 |
1083 /** |
1152 /** |
1084 RFileBuf64 invariant. Called in _DEBUG mode at the beginning and before the end of every RFileBuf64 method |
1153 RFileBuf64 invariant. Called in _DEBUG mode at the beginning and before the end of every RFileBuf64 method |
1085 (except the init/destroy methods). |
1154 (except the init/destroy methods). |