|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32debug.h> // RDebug |
|
19 #include <analyzetool/analyzetooltraceconstants.h> |
|
20 #include "analyzetoolfastlog.h" |
|
21 #include "atlog.h" |
|
22 |
|
23 // Local time function. |
|
24 TInt64 CurrentTime() |
|
25 { |
|
26 LOGSTR1( "ATFL CurrentTime()" ); |
|
27 TTime time; |
|
28 time.UniversalTime(); |
|
29 return time.Int64() - KMicroSecondsAt1970; |
|
30 } |
|
31 |
|
32 TInt ATFastLogProcessStarted( const TDesC8& aProcessName, |
|
33 TUint aProcessId, |
|
34 TUint32 aIsDebug, |
|
35 const TDesC8& aAtoolVersion, |
|
36 const TDesC8& aApiVersion ) |
|
37 { |
|
38 LOGSTR1( "ATFL ATFastLogProcessStarted()" ); |
|
39 |
|
40 // PCS <Process name> <Process ID> <Time stamp> <Udeb> <Version> |
|
41 |
|
42 //Buffer to trace |
|
43 TBuf8<KProcessStartBufLength> buffer; |
|
44 |
|
45 // AT indentifier |
|
46 buffer.Append( KATIdentifier ); |
|
47 // process id |
|
48 buffer.AppendNum( aProcessId, EHex ); |
|
49 buffer.Append( KSpace ); |
|
50 |
|
51 // PCS |
|
52 buffer.Append( KProcessStart ); |
|
53 // process name |
|
54 buffer.Append( aProcessName ); |
|
55 buffer.Append( KSpace ); |
|
56 // process id |
|
57 buffer.AppendNum( aProcessId, EHex ); |
|
58 buffer.Append( KSpace ); |
|
59 // time stamp |
|
60 buffer.AppendNum( CurrentTime(), EHex ) ; |
|
61 buffer.Append( KSpace ); |
|
62 // urel/udeb |
|
63 buffer.AppendNum( aIsDebug, EHex ); |
|
64 buffer.Append( KSpace ); |
|
65 // version |
|
66 buffer.AppendNum( KATTraceVersion, EHex ); |
|
67 buffer.Append( KSpace ); |
|
68 // atool version |
|
69 buffer.Append( aAtoolVersion ); |
|
70 buffer.Append( KSpace ); |
|
71 // ATAPI version |
|
72 buffer.Append( aApiVersion ); |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 RDebug::RawPrint( buffer ); |
|
78 |
|
79 return KErrNone; |
|
80 } |
|
81 |
|
82 TInt ATFastLogProcessEnded( TUint aProcessId, |
|
83 TUint aHandleLeakCount ) |
|
84 { |
|
85 LOGSTR1( "ATFL ATFastLogProcessEnded()" ); |
|
86 |
|
87 // PCE |
|
88 |
|
89 if ( aHandleLeakCount > 0 ) |
|
90 { |
|
91 // HDL <Handle count> |
|
92 |
|
93 // Buffer to trace. |
|
94 TBuf8<KHandleLeakBufLength> buffer2; |
|
95 |
|
96 // AT indentifier |
|
97 buffer2.Append( KATIdentifier ); |
|
98 // process id |
|
99 buffer2.AppendNum( aProcessId, EHex ); |
|
100 buffer2.Append( KSpace ); |
|
101 |
|
102 // HDL |
|
103 buffer2.Append( KHandleLeak ); |
|
104 // leak count |
|
105 buffer2.AppendNum( aHandleLeakCount ); |
|
106 |
|
107 RDebug::RawPrint( buffer2 ); |
|
108 } |
|
109 |
|
110 // Buffer to trace. |
|
111 TBuf8<KProcessEndBufLength> buffer; |
|
112 |
|
113 // AT indentifier |
|
114 buffer.Append( KATIdentifier ); |
|
115 // process id |
|
116 buffer.AppendNum( aProcessId, EHex ); |
|
117 buffer.Append( KSpace ); |
|
118 |
|
119 // PCE |
|
120 buffer.Append( KProcessEnd ); |
|
121 RDebug::RawPrint( buffer ); |
|
122 |
|
123 |
|
124 return KErrNone; |
|
125 } |
|
126 |
|
127 TInt ATFastLogDllLoaded( TUint aProcessId, |
|
128 const TDesC8& aDllName, |
|
129 TUint32 aStartAddress, |
|
130 TUint32 aEndAddress ) |
|
131 { |
|
132 LOGSTR1( "ATFL ATFastLogDllLoaded()" ); |
|
133 |
|
134 // DLL <DLL name> <Memory start address> <Memory end address> |
|
135 |
|
136 // Buffer to trace. |
|
137 TBuf8<KDllLoadBufLength> buffer; |
|
138 |
|
139 // AT indentifier |
|
140 buffer.Append( KATIdentifier ); |
|
141 // process id |
|
142 buffer.AppendNum( aProcessId, EHex ); |
|
143 buffer.Append( KSpace ); |
|
144 |
|
145 // DLL |
|
146 buffer.Append( KDllLoad ); |
|
147 // dll name |
|
148 buffer.Append( aDllName ); |
|
149 buffer.Append( KSpace ); |
|
150 // start adress |
|
151 buffer.AppendNum( aStartAddress, EHex ); |
|
152 buffer.Append( KSpace ); |
|
153 //end adress |
|
154 buffer.AppendNum( aEndAddress, EHex ); |
|
155 |
|
156 RDebug::RawPrint( buffer ); |
|
157 |
|
158 return KErrNone; |
|
159 } |
|
160 |
|
161 TInt ATFastLogDllUnloaded( TUint aProcessId, const TDesC8& aDllName, TUint32 aStartAddress, |
|
162 TUint32 aEndAddress ) |
|
163 { |
|
164 LOGSTR1( "ATFL ATFastLogDllUnloaded()" ); |
|
165 |
|
166 // DLU <DLL name> <Memory start address> <Memory end address> |
|
167 |
|
168 // Buffer to trace. |
|
169 TBuf8<KDllUnloadBufLength> buffer; |
|
170 |
|
171 // AT indentifier |
|
172 buffer.Append( KATIdentifier ); |
|
173 // process id |
|
174 buffer.AppendNum( aProcessId, EHex ); |
|
175 buffer.Append( KSpace ); |
|
176 |
|
177 // DLU |
|
178 buffer.Append( KDllUnload ); |
|
179 // dll name |
|
180 buffer.Append( aDllName ); |
|
181 buffer.Append( KSpace ); |
|
182 // start adress |
|
183 buffer.AppendNum( aStartAddress, EHex ); |
|
184 buffer.Append( KSpace ); |
|
185 //end adress |
|
186 buffer.AppendNum( aEndAddress, EHex ); |
|
187 |
|
188 RDebug::RawPrint( buffer ); |
|
189 |
|
190 return KErrNone; |
|
191 } |
|
192 |
|
193 TInt ATFastLogMemoryAllocated( TUint aProcessId, TUint32 aMemAddress, |
|
194 TFixedArray<TUint32, KATMaxCallstackLength>& aCallstack, |
|
195 TInt aSize, TUint aThreadId ) |
|
196 { |
|
197 LOGSTR1( "ATFL ATFastLogMemoryAllocated()" ); |
|
198 |
|
199 // ALH <Memory address> <Allocation size> <Thread ID> |
|
200 // <Call stack address count> <Call stack address> <Call stack address> ... |
|
201 |
|
202 // Buffer to trace. |
|
203 TBuf8<KMemAllocBufLength> buffer; |
|
204 |
|
205 // AT indentifier |
|
206 buffer.Append( KATIdentifier ); |
|
207 // process id |
|
208 buffer.AppendNum( aProcessId, EHex ); |
|
209 buffer.Append( KSpace ); |
|
210 |
|
211 // ALH |
|
212 buffer.Append( KMemoryAllocHeader ); |
|
213 // memory adress |
|
214 buffer.AppendNum( aMemAddress, EHex ); |
|
215 buffer.Append( KSpace ); |
|
216 // allocation size |
|
217 buffer.AppendNum( aSize, EHex ); |
|
218 buffer.Append( KSpace ); |
|
219 // thread ID |
|
220 buffer.AppendNum( aThreadId, EHex ); |
|
221 buffer.Append( KSpace ); |
|
222 |
|
223 // Search call stack for address count. |
|
224 TInt addrCount(0); |
|
225 for ( TInt j = 0; j < aCallstack.Count() ; j++ ) |
|
226 { |
|
227 if ( aCallstack.At(j) == 0 ) |
|
228 break; |
|
229 addrCount++; |
|
230 } |
|
231 // Current position in call stack. |
|
232 TInt addrPos( 0 ); |
|
233 |
|
234 // address count |
|
235 buffer.AppendNum( addrCount, EHex ); |
|
236 |
|
237 TUint packetNumber( 1 ); |
|
238 |
|
239 // Go through all call stack's memory addresses associated with |
|
240 // this memory allocation |
|
241 for ( TInt j = 0; j < addrCount; j++ ) |
|
242 { |
|
243 // ALF <Memory address> <Packet number> <Call stack address> <Call stack address> ... |
|
244 if ( buffer.Length() <= 0 ) |
|
245 { |
|
246 // AT indentifier |
|
247 buffer.Append( KATIdentifier ); |
|
248 // process id |
|
249 buffer.AppendNum( aProcessId, EHex ); |
|
250 buffer.Append( KSpace ); |
|
251 |
|
252 // Create alloc fragment message header |
|
253 buffer.Append( KMemoryAllocFragment ); |
|
254 buffer.AppendNum( aMemAddress, EHex ); |
|
255 buffer.Append( KSpace ); |
|
256 buffer.AppendNum( packetNumber, EHex ); |
|
257 // Increase packet number |
|
258 packetNumber++; |
|
259 } |
|
260 |
|
261 // Append call stack address. |
|
262 buffer.Append( KSpace ); |
|
263 buffer.AppendNum( aCallstack.At( addrPos ), EHex ); |
|
264 |
|
265 // Move the call stack position. |
|
266 addrPos++; |
|
267 |
|
268 // Check if buffer max length exceed |
|
269 if ( KLastItemLength + buffer.Length() >= KMemAllocBufLength ) |
|
270 { |
|
271 // Log through debug channel |
|
272 RDebug::RawPrint( buffer ); |
|
273 // Empty trace buffer |
|
274 buffer.Delete( 0, buffer.MaxLength() ); |
|
275 } |
|
276 } |
|
277 // Send last message if exists. |
|
278 if ( buffer.Length() > 0 ) |
|
279 { |
|
280 RDebug::RawPrint( buffer ); |
|
281 } |
|
282 |
|
283 return KErrNone; |
|
284 } |
|
285 |
|
286 |
|
287 TInt ATFastLogMemoryFreed( TUint aProcessId, TUint32 aMemAddress, |
|
288 TFixedArray<TUint32, KATMaxFreeCallstackLength>& aFreeCallstack, |
|
289 TUint aThreadId ) |
|
290 { |
|
291 LOGSTR1( "ATFL ATFastLogMemoryFreed()" ); |
|
292 |
|
293 // FRH <Memory address> <Thread ID> <Call stack address count> |
|
294 // <Call stack address> <Call stack address> ... |
|
295 |
|
296 // Buffer to trace. |
|
297 TBuf8<KMemFreedBufLength> buffer; |
|
298 |
|
299 // AT indentifier |
|
300 buffer.Append( KATIdentifier ); |
|
301 // process id |
|
302 buffer.AppendNum( aProcessId, EHex ); |
|
303 buffer.Append( KSpace ); |
|
304 |
|
305 // FRH |
|
306 buffer.Append( KMemoryFreedHeader ); |
|
307 |
|
308 // Append the start address of this allocation in the 32-bit (max 8 characters) |
|
309 // hexadecimal text format. |
|
310 buffer.AppendNum( aMemAddress, EHex ); |
|
311 buffer.Append( KSpace ); |
|
312 |
|
313 // thread ID |
|
314 buffer.AppendNum( aThreadId, EHex ); |
|
315 buffer.Append( KSpace ); |
|
316 |
|
317 // Search call stack for address count. |
|
318 TInt addrCount(0); |
|
319 for ( TInt j = 0; j < aFreeCallstack.Count() ; j++ ) |
|
320 { |
|
321 if ( aFreeCallstack.At(j) == 0 ) |
|
322 break; |
|
323 addrCount++; |
|
324 } |
|
325 // Current position in call stack. |
|
326 TInt addrPos( 0 ); |
|
327 |
|
328 // address count. |
|
329 buffer.AppendNum( addrCount, EHex ); |
|
330 |
|
331 TUint packetNumber( 1 ); |
|
332 |
|
333 // Go through all call stack's memory addresses associated with |
|
334 // this memory allocation |
|
335 for ( TInt j = 0; j < addrCount; j++ ) |
|
336 { |
|
337 // FRF <Memory address> <Packet number> |
|
338 // <Call stack address> <Call stack address> ... |
|
339 if ( buffer.Length() <= 0 ) |
|
340 { |
|
341 // Create alloc fragment message header |
|
342 buffer.Append( KMemoryFreedFragment ); |
|
343 buffer.AppendNum( aMemAddress, EHex ); |
|
344 buffer.Append( KSpace ); |
|
345 buffer.AppendNum( packetNumber, EHex ); |
|
346 // Increase packet number |
|
347 packetNumber++; |
|
348 } |
|
349 |
|
350 // Append call stack address. |
|
351 buffer.Append( KSpace ); |
|
352 buffer.AppendNum( aFreeCallstack.At( addrPos ), EHex ); |
|
353 |
|
354 // Move the call stack position. |
|
355 addrPos++; |
|
356 |
|
357 // Check if buffer max length exceed |
|
358 if ( KLastItemLength + buffer.Length() >= KMemFreedBufLength ) |
|
359 { |
|
360 // Log through debug channel |
|
361 RDebug::RawPrint( buffer ); |
|
362 // Empty trace buffer |
|
363 buffer.Delete( 0, buffer.MaxLength() ); |
|
364 } |
|
365 } |
|
366 // Send last message if exists. |
|
367 if ( buffer.Length() > 0 ) |
|
368 { |
|
369 RDebug::RawPrint( buffer ); |
|
370 } |
|
371 |
|
372 return KErrNone; |
|
373 } |
|
374 |
|
375 TInt ATFastLogMemoryReallocated( TUint aProcessId, TUint32 aMemAddressFree, TUint32 aMemAddressAlloc, |
|
376 TFixedArray<TUint32, KATMaxCallstackLength>& aCallstack, |
|
377 TInt aSize, TUint aThreadId ) |
|
378 { |
|
379 LOGSTR1( "ATFL ATFastLogMemoryReallocated()" ); |
|
380 |
|
381 // RAH <Freed memory address> <Allocated memory address> <Allocation size> <Thread ID> |
|
382 // <Call stack address count> <Call stack address> <Call stack address> ... |
|
383 |
|
384 // Buffer to trace. |
|
385 TBuf8<KMemReallocBufLength> buffer; |
|
386 |
|
387 // AT indentifier |
|
388 buffer.Append( KATIdentifier ); |
|
389 // process id |
|
390 buffer.AppendNum( aProcessId, EHex ); |
|
391 buffer.Append( KSpace ); |
|
392 |
|
393 // RAH |
|
394 buffer.Append( KMemoryReallocHeader ); |
|
395 // memory adress freed |
|
396 buffer.AppendNum( aMemAddressFree, EHex ); |
|
397 buffer.Append( KSpace ); |
|
398 // memory adress allocated |
|
399 buffer.AppendNum( aMemAddressAlloc, EHex ); |
|
400 buffer.Append( KSpace ); |
|
401 // allocation size |
|
402 buffer.AppendNum( aSize, EHex ); |
|
403 buffer.Append( KSpace ); |
|
404 // thread ID |
|
405 buffer.AppendNum( aThreadId, EHex ); |
|
406 buffer.Append( KSpace ); |
|
407 |
|
408 // Search call stack for address count. |
|
409 TInt addrCount(0); |
|
410 for ( TInt j = 0; j < aCallstack.Count() ; j++ ) |
|
411 { |
|
412 if ( aCallstack.At(j) == 0 ) |
|
413 break; |
|
414 addrCount++; |
|
415 } |
|
416 // Current position in call stack. |
|
417 TInt addrPos( 0 ); |
|
418 |
|
419 // address count |
|
420 buffer.AppendNum( addrCount, EHex ); |
|
421 |
|
422 TUint packetNumber( 1 ); |
|
423 |
|
424 // Go through all call stack's memory addresses associated with |
|
425 // this memory allocation |
|
426 for ( TInt j = 0; j < addrCount; j++ ) |
|
427 { |
|
428 // RAF <Freed memory address> <Allocated memory address> <Packet number> |
|
429 // <Call stack address> <Call stack address> ... |
|
430 if ( buffer.Length() <= 0 ) |
|
431 { |
|
432 // AT indentifier |
|
433 buffer.Append( KATIdentifier ); |
|
434 // process id |
|
435 buffer.AppendNum( aProcessId, EHex ); |
|
436 buffer.Append( KSpace ); |
|
437 |
|
438 // Create alloc fragment message header |
|
439 buffer.Append( KMemoryReallocFragment ); |
|
440 // memory adress freed |
|
441 buffer.AppendNum( aMemAddressFree, EHex ); |
|
442 buffer.Append( KSpace ); |
|
443 // memory adress allocated |
|
444 buffer.AppendNum( aMemAddressAlloc, EHex ); |
|
445 buffer.Append( KSpace ); |
|
446 // packet number |
|
447 buffer.AppendNum( packetNumber, EHex ); |
|
448 // Increase packet number |
|
449 packetNumber++; |
|
450 } |
|
451 |
|
452 // Append call stack address. |
|
453 buffer.Append( KSpace ); |
|
454 buffer.AppendNum( aCallstack.At( addrPos ), EHex ); |
|
455 |
|
456 // Move the call stack position. |
|
457 addrPos++; |
|
458 |
|
459 // Check if buffer max length exceed |
|
460 if ( KLastItemLength + buffer.Length() >= KMemAllocBufLength ) |
|
461 { |
|
462 // Log through debug channel |
|
463 RDebug::RawPrint( buffer ); |
|
464 // Empty trace buffer |
|
465 buffer.Delete( 0, buffer.MaxLength() ); |
|
466 } |
|
467 } |
|
468 // Send last message if exists. |
|
469 if ( buffer.Length() > 0 ) |
|
470 { |
|
471 RDebug::RawPrint( buffer); |
|
472 } |
|
473 |
|
474 return KErrNone; |
|
475 } |
|
476 |
|
477 TInt ATFastLogThreadStarted( TUint aProcessId, TUint aThreadId ) |
|
478 { |
|
479 LOGSTR1( "ATFL ATFastLogThreadStarted()" ); |
|
480 |
|
481 // TDS <Thread ID> |
|
482 |
|
483 //Buffer to trace |
|
484 TBuf8<KThreadStartBufLength> buffer; |
|
485 |
|
486 // AT indentifier |
|
487 buffer.Append( KATIdentifier ); |
|
488 // process id |
|
489 buffer.AppendNum( aProcessId, EHex ); |
|
490 buffer.Append( KSpace ); |
|
491 |
|
492 // TDS |
|
493 buffer.Append( KThreadStart ); |
|
494 // thread ID |
|
495 buffer.AppendNum( aThreadId, EHex ); |
|
496 |
|
497 RDebug::RawPrint( buffer ); |
|
498 |
|
499 return KErrNone; |
|
500 } |
|
501 |
|
502 TInt ATFastLogThreadEnded( TUint aProcessId, TUint64 aThreadId ) |
|
503 { |
|
504 LOGSTR1( "ATFL ATFastLogThreadEnded()" ); |
|
505 |
|
506 // TDE <Thread ID> |
|
507 |
|
508 //Buffer to trace |
|
509 TBuf8<KThreadEndBufLength> buffer; |
|
510 |
|
511 // AT indentifier |
|
512 buffer.Append( KATIdentifier ); |
|
513 // process id |
|
514 buffer.AppendNum( aProcessId, EHex ); |
|
515 buffer.Append( KSpace ); |
|
516 |
|
517 // TDE |
|
518 buffer.Append( KThreadEnd ); |
|
519 // thread ID |
|
520 buffer.AppendNum( aThreadId, EHex ); |
|
521 |
|
522 RDebug::RawPrint( buffer ); |
|
523 |
|
524 return KErrNone; |
|
525 } |
|
526 |
|
527 TInt ATFastLogDeviceInfo( const TDesC8& aS60Version, const TDesC8& aChecksum) |
|
528 { |
|
529 LOGSTR1( "ATFL ATFastLogVersionsInfo()" ); |
|
530 |
|
531 //Buffer to trace |
|
532 TBuf8<KVersionsInfoBufLength> buffer; |
|
533 |
|
534 // AT indentifier |
|
535 buffer.Append( KATIdentifier ); |
|
536 |
|
537 // VER |
|
538 buffer.Append( KVersionsInfo ); |
|
539 |
|
540 // sw version |
|
541 buffer.Append(aS60Version); |
|
542 buffer.Append(KSpace); |
|
543 // rom checksum |
|
544 buffer.Append(aChecksum); |
|
545 |
|
546 RDebug::RawPrint( buffer ); |
|
547 |
|
548 return KErrNone; |
|
549 } |