|
1 // Copyright (c) 2005-2010 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 // Trace Data parser |
|
15 // |
|
16 |
|
17 #ifndef __TRACEDATAPARSER_H__ |
|
18 #define __TRACEDATAPARSER_H__ |
|
19 |
|
20 #include <e32base.h> |
|
21 #include <opensystemtrace.h> |
|
22 #include <bautils.h> |
|
23 |
|
24 // Constants |
|
25 const TUint32 KHeaderVersion = 0x01; |
|
26 const TUint32 KProtocolIdAscii = 0x02; |
|
27 const TUint32 KProtocolIdSimpleTrace = 0x03; |
|
28 const TUint32 KXtiHeaderVersion = 0x1D; |
|
29 const TUint32 KXtiProtocolIdSimpleTrace = 0x08; |
|
30 const TInt KXtiTraceTypeIndex = 20; |
|
31 const TInt KXtiLengthIndex = 5; |
|
32 const TInt KMinimumPrimingTracesInBatch = 2; |
|
33 const TInt KMinMilliSecondsBatchGap = 10; |
|
34 const TInt KExpectedPrintfMaxLength = 32; |
|
35 const TInt KFileBufferSize = 1024*10; |
|
36 const TInt KMaxNumberBufferLength = 8; |
|
37 const TInt KMinSizeOstHeader = 3; |
|
38 const TInt KMinSizeOstBinaryHeader = 8; |
|
39 const TInt KMinSizeOstAsciiHeader = 8; |
|
40 const TInt KMinSizeBinaryHeader = 12; |
|
41 const TInt KMinSizeXtiHeader = 20; |
|
42 |
|
43 // Literals |
|
44 _LIT8(KDroppedTrace, "* Dropped Trace"); |
|
45 _LIT8(KFastMutexNameSystemLock, "System Lock"); |
|
46 _LIT8(KFastMutexNameMsgLock, "MsgLock"); |
|
47 _LIT8(KFastMutexNameObjLock, "ObjLock"); |
|
48 _LIT8(KFastMutexNameLogonLock, "LogonLock"); |
|
49 _LIT8(KCodeSegsName1, "EKern.exe"); |
|
50 _LIT8(KCodeSegsName2, "EFile.exe"); |
|
51 |
|
52 |
|
53 // Class containing trace header settings |
|
54 class TTraceHeaderSettings |
|
55 { |
|
56 public: |
|
57 TUint8 iCategory; |
|
58 TUint8 iSubCategory; |
|
59 TComponentId iComponentID; |
|
60 TUint32 iTraceWord; |
|
61 TUint32 iTimestamp; |
|
62 TInt iLengthOfPayload; |
|
63 TUint8 iHeaderFlags; |
|
64 TInt iMultiPartType; |
|
65 TBool iPrintfTrace; |
|
66 TBool iFromTestWriter; |
|
67 TUint32 iMultiPartTraceID; |
|
68 }; |
|
69 |
|
70 /* |
|
71 * Trace Data Parser class of static parsing functions |
|
72 * |
|
73 * The following trace types are supported: |
|
74 * OST traces (ascii and binary) |
|
75 * XTIv3 traces (ascii and binary) |
|
76 * Traces from the Test Writer (ascii and binary) |
|
77 */ |
|
78 class TTraceDataParser |
|
79 { |
|
80 public: |
|
81 |
|
82 IMPORT_C static TUint32 Swap(TUint32 x); |
|
83 IMPORT_C static TUint32 ReadUint32FromBuf(TUint8*& aBuf, TBool aFromTestWriter = EFalse); |
|
84 IMPORT_C static TUint16 ReadUint16FromBuf(TUint8*& aBuf); |
|
85 |
|
86 |
|
87 /* |
|
88 * Validate the trace data in buffer |
|
89 * |
|
90 * @param aBuffer the buffer containing the trace data |
|
91 * @param aExpectedNum expected number of traces |
|
92 * @param aComponentID component ID of traces |
|
93 * @param aGroupID group ID of traces |
|
94 * @param aData expected trace data |
|
95 * @param aTraceWord trace word of traces |
|
96 * @param aIdentical indicates that the payload of each trace packet should be identical |
|
97 * @param aBufferMode The mode of the trace buffer.. 0=straight, 1=circular. |
|
98 * @param aOrdinalData indicates whether the payload data reflects its position in the stream of trace packets |
|
99 * @param aNumTraces number of traces written to circular buffer |
|
100 * @param aMaxTraces maximum number of traces circular buffer can hold |
|
101 * @return Standard Symbian error code |
|
102 */ |
|
103 IMPORT_C static TInt ValidatePayload(TDesC8& aBuffer, |
|
104 TInt aExpectedNum, |
|
105 TComponentId aComponentID, |
|
106 TGroupId aGroupID, |
|
107 TUint32 aData, |
|
108 TUint32 aTraceWord, |
|
109 TBool aIdentical =EFalse, |
|
110 TInt aBufferMode =0, |
|
111 TBool aOrdinalData =EFalse, |
|
112 TInt aNumTraces =0, |
|
113 TInt aMaxTraces =0); |
|
114 |
|
115 /* |
|
116 * Validate the single trace data in buffer |
|
117 * |
|
118 * @param aBuffer the buffer containing the trace data |
|
119 * @param aTracePresent determines if trace data should be present or not |
|
120 * @param aGroupID expected GID |
|
121 * @param aComponentID expected CID |
|
122 * @param aData expected trace data |
|
123 * @param aPrintfTrace determines if trace data should be printf data or not |
|
124 * @param aMissingTrace determines if trace data should indicate missing data or not |
|
125 * @param aExpectedPrintfTrace expected printf trace data |
|
126 * @return Standard Symbian error code |
|
127 */ |
|
128 IMPORT_C static TInt ValidatePayload(TDesC8& aBuffer, |
|
129 TBool aTracePresent, |
|
130 TGroupId aGroupID, |
|
131 TComponentId aComponentID, |
|
132 TUint32 aData, |
|
133 TBool aPrintfTrace =EFalse, |
|
134 TBool aMissingTrace =EFalse, |
|
135 TDesC8* aExpectedPrintfTrace =NULL); |
|
136 |
|
137 /* |
|
138 * Parse trace data for kernel priming data |
|
139 * |
|
140 * Note that this function can only verify priming data if the group ID is EThreadIdentification, EFastMutex or ECodeSegs, |
|
141 * otherwise KErrNotSupported is returned if aVerifyData is ETrue |
|
142 * |
|
143 * @param aBuffer Buffer containing the trace data |
|
144 * @param aGroupId Group ID of traces to parse |
|
145 * @param aNumPrimingTraces Output parameter set to number of priming traces found for given group ID |
|
146 * @param aNumTraces Output parameter set to total number of traces found for given group ID |
|
147 * @param aVerifyData Flag indicating if priming data should be verified |
|
148 * @param aVerificationData1 Optional first data required for verifying priming data |
|
149 * @param aVerificationData1 Optional second data required for verifying priming data |
|
150 * @return Standard Symbian error code |
|
151 */ |
|
152 IMPORT_C static TInt ParsePrimingDataL(TDesC8& aBuffer, |
|
153 TGroupId aGroupId, |
|
154 TInt& aNumPrimingTraces, |
|
155 TInt& aNumTraces, |
|
156 TBool aVerifyData = EFalse, |
|
157 TUint32 aVerificationData1 = 0, |
|
158 TUint32 aVerificationData2 = 0); |
|
159 |
|
160 /* |
|
161 * Parse trace data for kernel priming data |
|
162 * |
|
163 * Note that this function can only verify priming data if the group ID is EThreadIdentification, EFastMutex or ECodeSegs, |
|
164 * otherwise KErrNotSupported is returned if aVerifyData is ETrue |
|
165 * |
|
166 * @param aFilePath Full path of file containing the trace data |
|
167 * @param aFs File system object |
|
168 * @param aGroupId Group ID of traces to parse |
|
169 * @param aNumPrimingTraces Output parameter set to number of priming traces found for given group ID |
|
170 * @param aNumTraces Output parameter set to total number of traces found for given group ID |
|
171 * @param aVerifyData Flag indicating if priming data should be verified |
|
172 * @param aVerificationData1 Optional first data required for verifying priming data |
|
173 * @param aVerificationData1 Optional second data required for verifying priming data |
|
174 * @return Standard Symbian error code |
|
175 */ |
|
176 IMPORT_C static TInt ParsePrimingDataL(const TDesC& aFilePath, |
|
177 RFs& aFs, |
|
178 TGroupId aGroupId, |
|
179 TInt& aNumPrimingTraces, |
|
180 TInt& aNumTraces, |
|
181 TBool aVerifyData = EFalse, |
|
182 TUint32 aVerificationData1 = 0, |
|
183 TUint32 aVerificationData2 = 0); |
|
184 |
|
185 /* |
|
186 * Parse trace data for Printf data, returning the number of occurances of a given string |
|
187 * |
|
188 * @param aBuffer Buffer containing the trace data |
|
189 * @param aFindString String to search for |
|
190 * @param aNumFound Output parameter set to number of occurances of given string |
|
191 * @return Standard Symbian error code |
|
192 */ |
|
193 IMPORT_C static TInt DataHasPrintfString(TDesC8& aBuffer, |
|
194 const TDesC8& aFindString, |
|
195 TInt& aNumFound); |
|
196 |
|
197 |
|
198 /* |
|
199 * Parse trace data file for Printf data, returning the number of occurances of a given string |
|
200 * |
|
201 * @param aFilePath Full path of file containing the trace data |
|
202 * @param aFs File system object |
|
203 * @param aFindString String to search for |
|
204 * @param aNumFound Output parameter set to number of occurances of given string |
|
205 * @return Standard Symbian error code |
|
206 */ |
|
207 IMPORT_C static TInt DataHasPrintfStringL(const TDesC& aFilePath, |
|
208 RFs& aFs, |
|
209 const TDesC8& aFindString, |
|
210 TInt& aNumFound); |
|
211 |
|
212 |
|
213 /* |
|
214 * Parse trace data file for a sequence of traces |
|
215 * |
|
216 * @param aFilePath Full path of file containing the trace data |
|
217 * @param aFs File system object |
|
218 * @param aLastNumberFound Output parameter set to number in last occurances of given string |
|
219 * @param aNumDroppedTraces Output parameter set to number of dropped traces |
|
220 * @param aFindPrintfPattern Pattern that indicates where in the printf string the number will be, using an asterisk |
|
221 * This is only used if aGroupId = BTrace::ERDebugPrintf |
|
222 * @param aGroupId Group ID of traces to parse |
|
223 * @param aComponentID Component ID of traces to parse |
|
224 * @return Standard Symbian error code |
|
225 */ |
|
226 IMPORT_C static TInt DataHasTraceSequenceL(const TDesC& aFilePath, |
|
227 RFs& aFs, |
|
228 TInt& aLastNumberFound, |
|
229 TInt& aNumDroppedTraces, |
|
230 TDesC8* aFindPrintfPattern, |
|
231 TGroupId aGroupId = BTrace::ERDebugPrintf, |
|
232 TComponentId aComponentID = 0); |
|
233 |
|
234 /* |
|
235 * Get Printf string from single trace data |
|
236 * |
|
237 * @param aBuffer Buffer containing the trace data |
|
238 * @param aPrintfString Output parameter set to the print string in the trace data |
|
239 * @return Standard Symbian error code |
|
240 */ |
|
241 IMPORT_C static TInt GetPrintfFromTrace(TDesC8& aBuffer, TDes8& aPrintfString); |
|
242 |
|
243 /* |
|
244 * Parse trace data for multipart data, returning the number of traces found and total size of trace data |
|
245 * The data is expected to contain a sequence of integers, starting at 0 |
|
246 * |
|
247 * @param aBuffer Buffer containing the trace data |
|
248 * @param aGroupId Group ID of traces to parse |
|
249 * @param aComponentID Component ID of traces to parse |
|
250 * @param aMultipartDataSize Output parameter set to total size of data in multipart trace |
|
251 * @param aNumMultipartTraces Output parameter set to number of traces that make up multipart trace |
|
252 * @return Standard Symbian error code |
|
253 */ |
|
254 IMPORT_C static TInt ValidateMultipartTraces(TDesC8& aBuffer, |
|
255 TGroupId aGroupID, |
|
256 TComponentId aComponentID, |
|
257 TInt& aMultipartDataSize, |
|
258 TInt& aNumMultipartTraces); |
|
259 |
|
260 private: |
|
261 |
|
262 static TBool IsStartOfKernelPrimingBatch(TUint8* aBuffer, TGroupId aGroupId, TUint8 aCategory, TUint8 aSubCategory); |
|
263 static TInt IsPotentialPrimingTrace(TUint8 aCategory, TUint8 aSubCategory, TBool& aIsPotentialPrimingTrace); |
|
264 static TBool StringsMatch(const TDesC8& aString1, const TDesC8& aString2); |
|
265 static TPtr8 ReadTracePrintf(TUint8* aData, TInt aSize); |
|
266 static TInt ParseStringForNumber(const TDesC8& aBuffer, const TDesC8& aFindStringPattern, TInt& aNumberFound); |
|
267 |
|
268 static TInt ParseHeader(TUint8*& aData, |
|
269 TInt aSize, |
|
270 TTraceHeaderSettings& aTraceHeaderSettings); |
|
271 |
|
272 static TInt IsInPrimingBatch(TUint8 aCategory, |
|
273 TUint8 aSubCategory, |
|
274 TUint32 aTimeDifference, |
|
275 TBool& aIsInPrimingBatch, |
|
276 TBool& aFirstTrace, |
|
277 TBool& aStartOfBatch); |
|
278 |
|
279 static TInt GetPrimingVerificationDataL(TUint8* aBuffer, |
|
280 TInt aSize, |
|
281 TGroupId aGroupId, |
|
282 TUint32& aVerificationData1, |
|
283 TUint32& aVerificationData2, |
|
284 RFile* aFile = NULL); |
|
285 |
|
286 static TInt GetThreadPrimingVerificationDataL(TUint8* aBuffer, |
|
287 TInt aSize, |
|
288 TUint32& aThreadAddr, |
|
289 TUint32& aProcessAddr, |
|
290 RFile* aFile = NULL); |
|
291 |
|
292 static TInt GetCodeSegsVerificationDataL(TUint8* aBuffer, |
|
293 TInt aSize, |
|
294 TUint32& aSegAddr1, |
|
295 TUint32& aSegAddr2, |
|
296 RFile* aFile = NULL); |
|
297 |
|
298 static TInt VerifyPrimingData(TUint8* aBuffer, |
|
299 TInt aSize, |
|
300 TUint8 aCategory, |
|
301 TUint8 aSubCategory, |
|
302 TInt& aElementsFound, |
|
303 TBool aFromTestWriter, |
|
304 TUint32 aVerificationData1, |
|
305 TUint32 aVerificationData2); |
|
306 |
|
307 static TInt VerifyThreadPrimingData(TUint8* aBuffer, |
|
308 TInt aSize, |
|
309 TUint8 aSubCategory, |
|
310 TInt& aElementsFound, |
|
311 TBool aFromTestWriter, |
|
312 TUint32 aThreadAddr, |
|
313 TUint32 aProcessAddr); |
|
314 |
|
315 static TInt VerifyFastMutexPrimingData(TUint8* aBuffer, |
|
316 TInt aSize, |
|
317 TUint8 aSubCategory, |
|
318 TInt& aElementsFound, |
|
319 TBool aFromTestWriter); |
|
320 |
|
321 static TInt VerifyCodeSegsPrimingData(TUint8* aBuffer, |
|
322 TInt aSize, |
|
323 TUint8 aSubCategory, |
|
324 TInt& aElementsFound, |
|
325 TBool aFromTestWriter, |
|
326 TUint32 aSegAddr1, |
|
327 TUint32 aSegAddr2); |
|
328 |
|
329 static TInt ReadNextChunkFromFile(TDes8& aFileBuffer, |
|
330 RFile& aFile, |
|
331 TInt& aFilePosition, |
|
332 TUint8*& aData, |
|
333 TUint8*& aStartOfData, |
|
334 TUint8*& aEndOfData); |
|
335 |
|
336 static TInt CreateFileBuffer(RBuf8& aFileBuffer, |
|
337 RFile& aFile); |
|
338 |
|
339 }; |
|
340 |
|
341 #endif // __TRACEDATAPARSER_H__ |
|
342 |