|
1 /* |
|
2 * Copyright (c) 2010 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: Declaration of the class TATDriveInfo. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "analyzetoolfilelog.h" |
|
19 #include "atdriveinfo.h" |
|
20 #include "atlog.h" |
|
21 #include <analyzetool/customuser.h> |
|
22 #include <analyzetool/analyzetooltraceconstants.h> |
|
23 #include <f32file.h> //RFs |
|
24 #include <utf.h> |
|
25 |
|
26 // New file name start and end index. |
|
27 const TInt KNameIndexStart = 1; |
|
28 const TInt KNameIndexEnd = 100; |
|
29 |
|
30 RATFileLog::RATFileLog() |
|
31 { |
|
32 |
|
33 // Initialize iMicroSecondsAt1970 |
|
34 TTime time( KJanuaryFirst1970 ); |
|
35 iMicroSecondsAt1970 = time.Int64(); |
|
36 iError = KErrNone; |
|
37 } |
|
38 |
|
39 RATFileLog::~RATFileLog() |
|
40 { |
|
41 // Auto-generated destructor stub |
|
42 } |
|
43 |
|
44 |
|
45 // Local time function. |
|
46 TInt64 RATFileLog::CurrentTime() |
|
47 { |
|
48 LOGSTR1( "ATFL void CATStorageServerSession::GetTime()" ); |
|
49 |
|
50 // Get the current universal time |
|
51 TTime time; |
|
52 time.UniversalTime(); |
|
53 |
|
54 // Change the time format that tells the number of microseconds from January First, |
|
55 // 0 AD nominal Gregorian, into a format that tells the number of microseconds from |
|
56 // January First, 1970 AD nominal Gregorian. This is a more generic format and |
|
57 // can be directly exploited by the PC code parsing the data file that this |
|
58 // server generates. |
|
59 return ( time.Int64() - iMicroSecondsAt1970 ); |
|
60 } |
|
61 |
|
62 TInt RATFileLog::ATFileLogVersion() |
|
63 { |
|
64 LOGSTR1( "ATFL CATFileLog::ATFileLogVersion()" ); |
|
65 |
|
66 iFile << KDataFileVersion; |
|
67 |
|
68 iFile.CommitL(); |
|
69 return KErrNone; |
|
70 } |
|
71 |
|
72 TInt RATFileLog::ATFileLogProcessStarted( const TDesC8& aProcessName, |
|
73 TUint aProcessId, |
|
74 TUint32 aIsDebug, |
|
75 const TDesC8& aAtoolVersion, |
|
76 const TDesC8& aApiVersion ) |
|
77 { |
|
78 LOGSTR1( "ATFL CATFileLog::ATFileLogProcessStarted()" ); |
|
79 |
|
80 // log the current time |
|
81 iFile << this->CurrentTime(); |
|
82 |
|
83 // <Time stamp> PCS <Process name> <Process ID> <Udeb> <Version> |
|
84 iFile << (TUint8)EProcessStart; |
|
85 iFile << aProcessName; |
|
86 iFile << (TUint32)aProcessId; |
|
87 iFile << aIsDebug; |
|
88 iFile << aAtoolVersion; |
|
89 iFile << aApiVersion; |
|
90 |
|
91 // ensure that any buffered data is written to the stream |
|
92 iFile.CommitL(); |
|
93 |
|
94 return KErrNone; |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // RATFileLog::ATFileLogProcessEnded |
|
99 // |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 TInt RATFileLog::ATFileLogProcessEnded( TUint aHandleLeakCount ) |
|
103 { |
|
104 LOGSTR1( "ATFL CATFileLog::ATFileLogProcessEnded()" ); |
|
105 |
|
106 if ( aHandleLeakCount > 0 ) |
|
107 { |
|
108 // HDL <Handle count> |
|
109 iFile << this->CurrentTime(); |
|
110 iFile << (TUint8)EHandleLeak; |
|
111 iFile << (TUint32)aHandleLeakCount; |
|
112 } |
|
113 |
|
114 // log the current time |
|
115 iFile << this->CurrentTime(); |
|
116 |
|
117 // PCE |
|
118 iFile << (TUint8)EProcessEnd; |
|
119 |
|
120 // ensure that any buffered data is written to the stream |
|
121 iFile.CommitL(); |
|
122 |
|
123 return KErrNone; |
|
124 } |
|
125 |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // RATFileLog::ATFileLogDllLoaded |
|
129 // |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 TInt RATFileLog::ATFileLogDllLoaded( const TDesC8& aDllName, TUint32 aStartAddress, |
|
133 TUint32 aEndAddress ) |
|
134 { |
|
135 LOGSTR1( "ATFL CATFileLog::ATFileLogDllLoaded()" ); |
|
136 |
|
137 // log the current time |
|
138 iFile << this->CurrentTime(); |
|
139 |
|
140 // DLL <DLL name> <Memory start address> <Memory end address> |
|
141 |
|
142 // DLL |
|
143 iFile << (TUint8)EDllLoad; |
|
144 // dll name |
|
145 iFile << aDllName; |
|
146 // start adress |
|
147 iFile << aStartAddress; |
|
148 //end adress |
|
149 iFile << aEndAddress; |
|
150 |
|
151 // ensure that any buffered data is written to the stream |
|
152 iFile.CommitL(); |
|
153 |
|
154 return KErrNone; |
|
155 } |
|
156 |
|
157 |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // RATFileLog::ATFileLogDllUnloaded |
|
161 // |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 TInt RATFileLog::ATFileLogDllUnloaded( const TDesC8& aDllName, TUint32 aStartAddress, |
|
165 TUint32 aEndAddress ) |
|
166 { |
|
167 LOGSTR1( "ATFL CATFileLog::ATFileLogDllUnloaded()" ); |
|
168 |
|
169 // log the current time |
|
170 iFile << this->CurrentTime(); |
|
171 |
|
172 // DLU <DLL name> <Memory start address> <Memory end address> |
|
173 |
|
174 // DLU |
|
175 iFile << (TUint8)EDllUnload; |
|
176 // dll name |
|
177 iFile << aDllName; |
|
178 // start adress |
|
179 iFile << aStartAddress; |
|
180 //end adress |
|
181 iFile << aEndAddress; |
|
182 |
|
183 // ensure that any buffered data is written to the stream |
|
184 iFile.CommitL(); |
|
185 |
|
186 return KErrNone; |
|
187 |
|
188 } |
|
189 |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // RATFileLog::ATFileLogMemoryAllocated |
|
193 // |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 TInt RATFileLog::ATFileLogMemoryAllocated( TUint32 aMemAddress, |
|
197 TFixedArray<TUint32, KATMaxCallstackLength>& aCallstack, |
|
198 TInt aSize, TUint aThreadId ) |
|
199 { |
|
200 LOGSTR1( "ATFL CATFileLog::ATFileLogMemoryAllocated()" ); |
|
201 |
|
202 // ALH <Memory address> <Allocation size> <Thread ID> |
|
203 // <Call stack address count> <Call stack address> <Call stack address> ... |
|
204 |
|
205 // log the current time |
|
206 iFile << this->CurrentTime(); |
|
207 |
|
208 // ALH |
|
209 iFile << (TUint8)EAllocH; |
|
210 // memory adress |
|
211 iFile << aMemAddress; |
|
212 // allocation size |
|
213 iFile << (TUint32)aSize; |
|
214 // thread ID |
|
215 iFile << (TUint32)aThreadId; |
|
216 |
|
217 // Search call stack for address count. |
|
218 TInt addrCount(0); |
|
219 for ( TInt j = 0; j < aCallstack.Count() ; j++ ) |
|
220 { |
|
221 if ( aCallstack.At(j) == 0 ) |
|
222 break; |
|
223 addrCount++; |
|
224 } |
|
225 |
|
226 // address count |
|
227 iFile << (TUint32)addrCount; |
|
228 |
|
229 // Go through all call stack's memory addresses associated with |
|
230 // this memory allocation |
|
231 for ( TInt addrPos = 0; addrPos < addrCount; addrPos++ ) |
|
232 { |
|
233 iFile << aCallstack.At( addrPos ); |
|
234 } |
|
235 |
|
236 // ensure that any buffered data is written to the stream |
|
237 iFile.CommitL(); |
|
238 |
|
239 return KErrNone; |
|
240 } |
|
241 |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // RATFileLog::ATFileLogMemoryFreed |
|
245 // |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 TInt RATFileLog::ATFileLogMemoryFreed( TUint32 aMemAddress, |
|
249 TFixedArray<TUint32, KATMaxFreeCallstackLength>& aFreeCallstack, |
|
250 TUint aThreadId ) |
|
251 { |
|
252 LOGSTR1( "ATFL CATFileLog::ATFileLogMemoryFreed()" ); |
|
253 |
|
254 // FRH <Memory address> <Thread ID> <Call stack address count> |
|
255 // <Call stack address> <Call stack address> ... |
|
256 |
|
257 // log the current time |
|
258 iFile << this->CurrentTime(); |
|
259 |
|
260 // FRH |
|
261 iFile << (TUint8)EFreeH; |
|
262 |
|
263 // Append the start address of this allocation in the 32-bit (max 8 characters) |
|
264 // hexadecimal text format. |
|
265 iFile << aMemAddress; |
|
266 |
|
267 // thread ID |
|
268 iFile << (TUint32)aThreadId; |
|
269 |
|
270 // Search call stack for address count. |
|
271 TInt addrCount(0); |
|
272 for ( TInt j = 0; j < aFreeCallstack.Count() ; j++ ) |
|
273 { |
|
274 if ( aFreeCallstack.At(j) == 0 ) |
|
275 break; |
|
276 addrCount++; |
|
277 } |
|
278 |
|
279 // address count. |
|
280 iFile << (TUint32)addrCount; |
|
281 |
|
282 // Go through all call stack's memory addresses associated with |
|
283 // this memory allocation |
|
284 for ( TInt addrPos = 0; addrPos < addrCount; addrPos++ ) |
|
285 { |
|
286 iFile << aFreeCallstack.At( addrPos ); |
|
287 } |
|
288 |
|
289 // ensure that any buffered data is written to the stream |
|
290 iFile.CommitL(); |
|
291 |
|
292 return KErrNone; |
|
293 } |
|
294 |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // RATFileLog::ATFileLogMemoryReallocated |
|
298 // |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 TInt RATFileLog::ATFileLogMemoryReallocated( TUint32 aMemAddressFree, TUint32 aMemAddressAlloc, |
|
302 TFixedArray<TUint32, KATMaxCallstackLength>& aCallstack, |
|
303 TInt aSize, TUint aThreadId ) |
|
304 { |
|
305 LOGSTR1( "ATFL CATFileLog::ATFileLogMemoryReallocated()" ); |
|
306 |
|
307 // RAH <Freed memory address> <Allocated memory address> <Allocation size> <Thread ID> |
|
308 // <Call stack address count> <Call stack address> <Call stack address> ... |
|
309 |
|
310 // log the current time |
|
311 iFile << this->CurrentTime(); |
|
312 |
|
313 // RAH |
|
314 iFile << (TUint8)EReallocH; |
|
315 // memory adress freed |
|
316 iFile << aMemAddressFree; |
|
317 // memory adress allocated |
|
318 iFile << aMemAddressAlloc; |
|
319 // allocation size |
|
320 iFile << (TUint32)aSize; |
|
321 // thread ID |
|
322 iFile << (TUint32)aThreadId; |
|
323 |
|
324 // Search call stack for address count. |
|
325 TInt addrCount(0); |
|
326 for ( TInt j = 0; j < aCallstack.Count() ; j++ ) |
|
327 { |
|
328 if ( aCallstack.At(j) == 0 ) |
|
329 break; |
|
330 addrCount++; |
|
331 } |
|
332 |
|
333 // address count |
|
334 iFile << (TUint32)addrCount; |
|
335 |
|
336 // Go through all call stack's memory addresses associated with |
|
337 // this memory allocation |
|
338 for ( TInt addrPos = 0; addrPos < addrCount; addrPos++ ) |
|
339 { |
|
340 // Append call stack address. |
|
341 iFile << aCallstack.At( addrPos ); |
|
342 } |
|
343 |
|
344 // ensure that any buffered data is written to the stream |
|
345 iFile.CommitL(); |
|
346 |
|
347 return KErrNone; |
|
348 } |
|
349 |
|
350 |
|
351 // ----------------------------------------------------------------------------- |
|
352 // RATFileLog::ATFileLogThreadStarted |
|
353 // |
|
354 // ----------------------------------------------------------------------------- |
|
355 // |
|
356 TInt RATFileLog::ATFileLogThreadStarted( TUint aThreadId ) |
|
357 { |
|
358 LOGSTR1( "ATFL CATFileLog::ATFileLogThreadStarted()" ); |
|
359 |
|
360 // log the current time |
|
361 iFile << this->CurrentTime(); |
|
362 |
|
363 // TDS <Thread ID> |
|
364 |
|
365 // TDS |
|
366 iFile << (TUint8)EThreadStart; |
|
367 // thread ID |
|
368 iFile << (TUint32)aThreadId; |
|
369 |
|
370 // ensure that any buffered data is written to the stream |
|
371 iFile.CommitL(); |
|
372 |
|
373 return KErrNone; |
|
374 } |
|
375 |
|
376 |
|
377 // ----------------------------------------------------------------------------- |
|
378 // RATFileLog::ATFileLogThreadEnded |
|
379 // |
|
380 // ----------------------------------------------------------------------------- |
|
381 // |
|
382 TInt RATFileLog::ATFileLogThreadEnded( TUint64 aThreadId ) |
|
383 { |
|
384 LOGSTR1( "ATFL CATFileLog::ATFileLogThreadEnded()" ); |
|
385 |
|
386 // log the current time |
|
387 iFile << this->CurrentTime(); |
|
388 |
|
389 // TDE <Thread ID> |
|
390 |
|
391 // TDE |
|
392 iFile << (TUint8)EThreadEnd; |
|
393 // thread ID |
|
394 iFile << (TUint32)aThreadId; |
|
395 |
|
396 // ensure that any buffered data is written to the stream |
|
397 iFile.CommitL(); |
|
398 |
|
399 return KErrNone; |
|
400 } |
|
401 |
|
402 |
|
403 // ----------------------------------------------------------------------------- |
|
404 // RATFileLog::ATFileLogDeviceInfo |
|
405 // |
|
406 // ----------------------------------------------------------------------------- |
|
407 // |
|
408 TInt RATFileLog::ATFileLogDeviceInfo( const TDesC8& aS60Version, const TDesC8& aChecksum) |
|
409 |
|
410 { |
|
411 LOGSTR1( "ATFL CATFileLog::ATFileLogVersionsInfo()" ); |
|
412 |
|
413 // log the current time |
|
414 iFile << this->CurrentTime(); |
|
415 |
|
416 // VER |
|
417 iFile << (TUint8)EDeviceInfo; |
|
418 // sw version |
|
419 iFile << aS60Version; |
|
420 // rom checksum |
|
421 iFile << aChecksum; |
|
422 |
|
423 // ensure that any buffered data is written to the stream |
|
424 iFile.CommitL(); |
|
425 |
|
426 return KErrNone; |
|
427 } |
|
428 |
|
429 |
|
430 |
|
431 // ----------------------------------------------------------------------------- |
|
432 // RATFileLog::OpenFsAndFile |
|
433 // Internally used for opening a handle to the file server and a file |
|
434 // ----------------------------------------------------------------------------- |
|
435 // |
|
436 TInt RATFileLog::OpenFsAndFile( const TDesC& aFileName, const TDesC& aFilePath, |
|
437 const TDesC8& aProcessName ) |
|
438 { |
|
439 LOGSTR1( "ATFL TInt CATFileLog::OpenFsAndFile()" ); |
|
440 |
|
441 // Connect file server, return if error occured |
|
442 iError = iFileServer.Connect(); |
|
443 if ( iError ) |
|
444 { |
|
445 iFileServer.Close(); |
|
446 return iError; |
|
447 } |
|
448 |
|
449 iError = iFileServer.ShareAuto(); |
|
450 if( iError ) |
|
451 { |
|
452 iFileServer.Close(); |
|
453 return iError; |
|
454 } |
|
455 |
|
456 // Open a file |
|
457 TBuf<KMaxFileName> fileNameBuf; |
|
458 |
|
459 iError = TATDriveInfo::CreatePath( fileNameBuf, aFileName, aFilePath, iFileServer ); |
|
460 |
|
461 // Return, if an error occured, and it |
|
462 // is not KErrAlreadyExists |
|
463 if ( iError && iError != KErrAlreadyExists ) |
|
464 { |
|
465 iFileServer.Close(); |
|
466 return iError; |
|
467 } |
|
468 |
|
469 // if file already exist, generat new filename with index |
|
470 GenerateNewFileName( fileNameBuf, aProcessName ); |
|
471 |
|
472 // Save the file name for this session |
|
473 CnvUtfConverter::ConvertFromUnicodeToUtf8( iLogFile, fileNameBuf ); |
|
474 |
|
475 LOGSTR2( "ATFL > iError(%i)", iError ); |
|
476 |
|
477 // If the file does not exist, create it. Write also the version number of |
|
478 // the file at the beginning of the new file |
|
479 if ( iError == KErrNotFound ) |
|
480 { |
|
481 iError = iFile.Create( iFileServer, fileNameBuf, EFileWrite | EFileShareAny ); |
|
482 if ( !iError ) |
|
483 { |
|
484 // todo |
|
485 } |
|
486 } |
|
487 |
|
488 if ( iError ) |
|
489 { |
|
490 iFile.Close(); |
|
491 iFileServer.Close(); |
|
492 return iError; |
|
493 } |
|
494 |
|
495 return iError; |
|
496 } |
|
497 |
|
498 // ----------------------------------------------------------------------------- |
|
499 // RATFileLog::GenerateNewFileName |
|
500 // Called internally when need generate new file name. |
|
501 // ----------------------------------------------------------------------------- |
|
502 // |
|
503 void RATFileLog::GenerateNewFileName( TDes& aFileName, |
|
504 const TDesC8& aProcessName ) |
|
505 { |
|
506 LOGSTR1( "ATFL void CATFileLog::GenerateNewFileName()" ); |
|
507 |
|
508 // Extension |
|
509 TBuf<KExtensionLength> extension; |
|
510 |
|
511 // Check if file already exist |
|
512 CheckIfFileAlreadyExist( aFileName ); |
|
513 if ( iError == KErrNotFound ) |
|
514 { |
|
515 // If not we can use filename without indexing |
|
516 return; |
|
517 } |
|
518 |
|
519 // File with aFileName already exist, let's add index |
|
520 |
|
521 // Parse file extension if exists. |
|
522 ParseExtension( aFileName, extension ); |
|
523 |
|
524 // Temp file name |
|
525 TBuf<KMaxFileName> tempName; |
|
526 |
|
527 for ( TInt i = KNameIndexStart; i < KNameIndexEnd; i++ ) |
|
528 { |
|
529 tempName.Delete( 0, tempName.MaxLength() ); |
|
530 tempName.Format( KFormat, &aFileName, &KLeftBracket, i, &KRightBracket, &extension ); |
|
531 LOGSTR2( "ATFL > tempName(%S)", &tempName ); |
|
532 // Try to open file |
|
533 CheckIfFileAlreadyExist( tempName ); |
|
534 // File does not exist, this index can be used |
|
535 if ( iError == KErrNotFound ) |
|
536 { |
|
537 aFileName.Copy( tempName ); |
|
538 break; |
|
539 } |
|
540 } |
|
541 } |
|
542 |
|
543 // ----------------------------------------------------------------------------- |
|
544 // RATFileLog::ParseExtension |
|
545 // Method is used to parse file name extension. |
|
546 // ----------------------------------------------------------------------------- |
|
547 // |
|
548 void RATFileLog::ParseExtension( |
|
549 TDes& aFileName, TDes& aExtension ) |
|
550 { |
|
551 LOGSTR2( "ATFL void CATFileLog::ParseExtension(%S)", |
|
552 &aFileName ); |
|
553 |
|
554 // Parse current file name |
|
555 TParse parse; |
|
556 // Set up the TParse object |
|
557 parse.Set( aFileName, NULL, NULL ); |
|
558 |
|
559 // Tests whether an extension is present. |
|
560 if ( parse.ExtPresent() ) |
|
561 { |
|
562 // Gets the extension |
|
563 aExtension.Copy( parse.Ext() ); |
|
564 // Remove extension from file name |
|
565 TInt pos( aFileName.Find( aExtension ) ); |
|
566 aFileName.Delete( pos, aFileName.Length() ); |
|
567 LOGSTR3( "ATFL > aFileName(%S), aExtension(%S)", |
|
568 &aFileName, &aExtension ); |
|
569 } |
|
570 } |
|
571 |
|
572 // ----------------------------------------------------------------------------- |
|
573 // RATFileLog::CheckIfFileAlreadyExist |
|
574 // Method is used to check that file exists and is valid. |
|
575 // ----------------------------------------------------------------------------- |
|
576 // |
|
577 void RATFileLog::CheckIfFileAlreadyExist( |
|
578 const TDes& aFileName ) |
|
579 { |
|
580 LOGSTR2( "ATFL void CATFileLog::CheckIfFileAlreadyExist(%S)", |
|
581 &aFileName ); |
|
582 |
|
583 iError = iFile.Open( iFileServer, aFileName, EFileWrite ); |
|
584 LOGSTR2( "ATFL > iError(%i)", iError ); |
|
585 } |
|
586 |
|
587 |
|
588 // ----------------------------------------------------------------------------- |
|
589 // RATFileLog::CloseFsAndFile |
|
590 // Internally used for closing a handle to the file server and a file |
|
591 // ----------------------------------------------------------------------------- |
|
592 // |
|
593 void RATFileLog::CloseFsAndFile() |
|
594 { |
|
595 LOGSTR1( "ATFL void CATFileLog::CloseFsAndFile()" ); |
|
596 |
|
597 // Close the file |
|
598 iFile.Close(); |
|
599 |
|
600 // Close the server session and return the error code |
|
601 iFileServer.Close(); |
|
602 } |
|
603 |