analyzetool/dynamicmemoryhook/src/analyzetoolfastlog.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 49 7fdc9a71d314
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
    13 *
    13 *
    14 * Description:  
    14 * Description:  
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 
    18 #include <e32debug.h> // RDebug
    19 #include <e32debug.h> // RDebug
    19 #include <analyzetool/analyzetooltraceconstants.h>
    20 #include <analyzetool/analyzetooltraceconstants.h>
    20 #include "analyzetoolfastlog.h"
    21 #include "analyzetoolfastlog.h"
    21 #include "atlog.h"
    22 #include "atlog.h"
    22 
    23 
    29     return time.Int64() - KMicroSecondsAt1970;
    30     return time.Int64() - KMicroSecondsAt1970;
    30     }
    31     }
    31 
    32 
    32 TInt ATFastLogProcessStarted( const TDesC8& aProcessName,
    33 TInt ATFastLogProcessStarted( const TDesC8& aProcessName,
    33                                  TUint aProcessId,
    34                                  TUint aProcessId,
    34                                  TUint32 aIsDebug,
    35                                  TUint32 aIsDebug )
    35                                  const TDesC8& aAtoolVersion,
       
    36                                  const TDesC8& aApiVersion )
       
    37     {
    36     {
    38     LOGSTR1( "ATFL ATFastLogProcessStarted()" );
    37     LOGSTR1( "ATFL ATFastLogProcessStarted()" );
    39     
    38     // Convert process name to 16-bit descriptor.
    40     // PCS <Process name> <Process ID> <Time stamp> <Udeb> <Version>
    39     TBuf<KMaxProcessName> processName;
    41 
    40     processName.Copy( aProcessName );
    42     //Buffer to trace
    41     // Buffer to trace.
    43     TBuf8<KProcessStartBufLength> buffer;
    42     TBuf<KProcessStartBufLength> buffer;
    44     
    43     // Format process name and id.
    45     // AT indentifier
    44     buffer.Format( KProcessStart16, &processName, aProcessId );
    46     buffer.Append( KATIdentifier );
    45     // Timestamp.
    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 ) ;
    46     buffer.AppendNum( CurrentTime(), EHex ) ;
    61     buffer.Append( KSpace );
    47     // Append udeb/urel information to the process start.
    62     // urel/udeb
    48     buffer.Append( KSpaceTrace );  
    63     buffer.AppendNum( aIsDebug, EHex );
    49     buffer.AppendNum( aIsDebug, EHex );
    64     buffer.Append( KSpace );
    50     // Append version number.
    65     // version
    51     buffer.Append( KSpaceTrace );  
    66     buffer.AppendNum( KATTraceVersion, EHex );
    52     buffer.AppendNum( KATTraceVersion, EHex );
    67     buffer.Append( KSpace );    
    53     // Log to trace.
    68     // atool version
    54     RDebug::Print( KTraceMessage, aProcessId ,&buffer );
    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;
    55     return KErrNone;
    80     }
    56     }
    81 
    57 
    82 TInt ATFastLogProcessEnded( TUint aProcessId, 
    58 TInt ATFastLogProcessEnded( TUint aProcessId, 
    83                             TUint aHandleLeakCount )
    59                             TUint aHandleLeakCount )
    84     {
    60     {
    85     LOGSTR1( "ATFL ATFastLogProcessEnded()" );
    61     LOGSTR1( "ATFL ATFastLogProcessEnded()" );
    86     
    62     // Handle leaks.
    87     // PCE
       
    88     
       
    89     if ( aHandleLeakCount > 0 )
    63     if ( aHandleLeakCount > 0 )
    90     	{
    64         {
    91         // HDL <Handle count>
       
    92     
       
    93         // Buffer to trace.
    65         // Buffer to trace.
    94         TBuf8<KHandleLeakBufLength> buffer2;
    66         TBuf<KHandleLeakBufLength> buffer2;
    95         
    67         buffer2.Format( KHandleLeak16, &KUnknownModule16, aHandleLeakCount );
    96         // AT indentifier
    68         // Trace it.
    97         buffer2.Append( KATIdentifier );
    69         RDebug::Print( KTraceMessage, aProcessId, &buffer2 );
    98         // process id
    70         }
    99         buffer2.AppendNum( aProcessId, EHex );
    71     // Process end trace.
   100         buffer2.Append( KSpace );
    72     TBuf<KProcessEndBufLength> buffer;
   101         
    73     buffer.Format( KProcessEnd16, aProcessId );
   102         // HDL
    74     buffer.AppendNum( CurrentTime(), EHex);
   103         buffer2.Append( KHandleLeak );
    75     buffer.Append( KNewLineTrace );
   104         // leak count
    76     RDebug::Print( KTraceMessage, aProcessId, &buffer );
   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;
    77     return KErrNone;
   125     }
    78     }
   126 
    79 
   127 TInt ATFastLogDllLoaded( TUint aProcessId, 
    80 TInt ATFastLogDllLoaded( TUint aProcessId, 
   128                                         const TDesC8& aDllName,
    81                                         const TDesC8& aDllName,
   129                                         TUint32 aStartAddress,
    82                                         TUint32 aStartAddress,
   130                                         TUint32 aEndAddress )
    83                                         TUint32 aEndAddress )
   131     {
    84     {
   132     LOGSTR1( "ATFL ATFastLogDllLoaded()" );
    85     LOGSTR1( "ATFL ATFastLogDllLoaded()" );
   133     
    86     // Timestamp.
   134     // DLL <DLL name> <Memory start address> <Memory end address>
    87     TInt64 time = CurrentTime();
   135     
    88     // Convert dll name to 16-bit descriptor.
       
    89     TBuf<KMaxLibraryName> dll;
       
    90     dll.Copy( aDllName );
   136     // Buffer to trace.
    91     // Buffer to trace.
   137     TBuf8<KDllLoadBufLength> buffer;
    92     TBuf<KDllLoadBufLength> buffer;
   138     
    93     buffer.Format( KDllLoad16, &dll, time, aStartAddress, aEndAddress );
   139     // AT indentifier
    94     RDebug::Print( KTraceMessage, aProcessId, &buffer );
   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;
    95     return KErrNone;
   159     }
    96     }
   160 
    97 
   161 TInt ATFastLogDllUnloaded( TUint aProcessId, const TDesC8& aDllName, TUint32 aStartAddress,
    98 TInt ATFastLogDllUnloaded( TUint aProcessId, const TDesC8& aDllName, TUint32 aStartAddress,
   162                                        TUint32 aEndAddress )
    99                                        TUint32 aEndAddress )
   163     {
   100     {
   164     LOGSTR1( "ATFL ATFastLogDllUnloaded()" );
   101     LOGSTR1( "ATFL ATFastLogDllUnloaded()" );
   165     
   102     // Timestamp.
   166     // DLU <DLL name> <Memory start address> <Memory end address>
   103     TInt64 time = CurrentTime();
   167     
   104     // Convert dll name to 16-bit descriptor.
       
   105     TBuf<KMaxLibraryName> dll;
       
   106     dll.Copy( aDllName );
   168     // Buffer to trace.
   107     // Buffer to trace.
   169     TBuf8<KDllUnloadBufLength> buffer;
   108     TBuf<KDllLoadBufLength> buffer;
   170     
   109     buffer.Format( KDllUnload16, &dll, time, aStartAddress, aEndAddress );
   171     // AT indentifier
   110     RDebug::Print( KTraceMessage, aProcessId, &buffer );   
   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;
   111     return KErrNone;
   191     }
   112     }
   192 
   113 
   193 TInt ATFastLogMemoryAllocated( TUint aProcessId, TUint32 aMemAddress,
   114 TInt ATFastLogMemoryAllocated( TUint aProcessId, TUint32 aMemAddress,
   194                                   TFixedArray<TUint32, KATMaxCallstackLength>& aCallstack,
   115                                   TFixedArray<TUint32, KATMaxCallstackLength>& aCallstack,
   195                                   TInt aSize, TUint aThreadId )
   116                                   TInt aSize )
   196     {
   117     {
   197     LOGSTR1( "ATFL ATFastLogMemoryAllocated()" );
   118     LOGSTR1( "ATFL ATFastLogMemoryAllocated()" );
   198     
   119     // ALLOCH <Memory address> <Time stamp> <Allocation size> <Call stack address count> 
   199     // ALH <Memory address> <Allocation size> <Thread ID> 
   120     // <Call stack address> <Call stack address> ...
   200     // <Call stack address count> <Call stack address> <Call stack address> ...
   121     
   201         
   122     // Timestamp.
   202     // Buffer to trace.
   123     TInt64 time = CurrentTime();
   203     TBuf8<KMemAllocBufLength> buffer;
   124     
   204     
   125     // Trace buffer and pointer to it.
   205     // AT indentifier
   126     TBufC<KMemAllocBufLength> buffer;
   206     buffer.Append( KATIdentifier );
   127     TPtr ptr( buffer.Des() );
   207     // process id
   128     // Append the tag implying a memory allocation line in the data file
   208     buffer.AppendNum( aProcessId, EHex  );
   129     ptr.Append( KMemoryAllocHeader );
   209     buffer.Append( KSpace );
   130     
   210     
   131     // Append the start address of this allocation in the 32-bit (max 8 characters)
   211     // ALH
   132     // hexadecimal text format.
   212     buffer.Append( KMemoryAllocHeader );
   133     ptr.AppendNum( aMemAddress, EHex );
   213     // memory adress
   134     
   214     buffer.AppendNum( aMemAddress, EHex );
   135     // Append the current time in the 64-bit (max 16 characters) hexadecimal text
   215     buffer.Append( KSpace );
   136     // format
   216     // allocation size
   137     ptr.Append( KSpaceTrace );
   217     buffer.AppendNum( aSize, EHex );
   138     ptr.AppendNum( time, EHex );
   218     buffer.Append( KSpace ); 
   139     
   219     // thread ID
   140     // Append the size of the allocation in the 32-bit (max 8 characters) hexadecimal
   220     buffer.AppendNum( aThreadId, EHex );
   141     // text format.
   221     buffer.Append( KSpace );
   142     ptr.Append( KSpaceTrace );
   222 
   143     ptr.AppendNum( aSize, EHex );
       
   144     
   223     // Search call stack for address count.
   145     // Search call stack for address count.
   224 	TInt addrCount(0);
   146     TInt addrCount(0);
   225 	for ( TInt j = 0; j < aCallstack.Count() ; j++ )
   147     for ( TInt j = 0; j < aCallstack.Count() ; j++ )
   226 		{
   148         {
   227 		if ( aCallstack.At(j) == 0 )
   149         if ( aCallstack.At(j) == 0 )
   228 			break;
   150             break;
   229 		addrCount++;
   151         addrCount++;
   230 		}
   152         }
   231 	// Current position in call stack.
   153     // Current position in call stack.
   232 	TInt addrPos( 0 );
   154     TInt addrPos( 0 );
   233     
   155     
   234     // address count
   156     // Append address count.
   235     buffer.AppendNum( addrCount, EHex );
   157     ptr.Append( KSpaceTrace );
       
   158     ptr.AppendNum( addrCount, EHex );
       
   159             
       
   160     // Calculate last item length
       
   161     TInt lastItemLength( KTraceMessage().Length() + KHexa32Length + 
       
   162             KSpaceLength + KNewlineLength );
   236     
   163     
   237     TUint packetNumber( 1 );
   164     TUint packetNumber( 1 );
   238     
   165     
   239     // Go through all call stack's memory addresses associated with
   166     // Go through all call stack's memory addresses associated with
   240     // this memory allocation 
   167     // this memory allocation 
   241     for ( TInt j = 0; j < addrCount; j++ )
   168     for ( TInt j = 0; j < addrCount; j++ )
   242         {
   169         {
   243         // ALF <Memory address> <Packet number> <Call stack address> <Call stack address> ...
   170         // ALLOCF <Memory address> <Time stamp> <Packet number> 
   244         if ( buffer.Length() <= 0 )
   171         // <Call stack address> <Call stack address> ...
   245             {
   172         if ( ptr.Length() <= 0 )
   246             // AT indentifier
   173             {               
   247             buffer.Append( KATIdentifier );
       
   248             // process id
       
   249             buffer.AppendNum( aProcessId, EHex  );
       
   250             buffer.Append( KSpace ); 
       
   251             
       
   252             // Create alloc fragment message header
   174             // Create alloc fragment message header
   253             buffer.Append( KMemoryAllocFragment );
   175             ptr.Append( KMemoryAllocFragment );
   254             buffer.AppendNum( aMemAddress, EHex );
   176             ptr.AppendNum( aMemAddress, EHex );
   255             buffer.Append( KSpace );     
   177             ptr.Append( KSpaceTrace );
   256             buffer.AppendNum( packetNumber, EHex );
   178             ptr.AppendNum( time, EHex );
       
   179             ptr.Append( KSpaceTrace );        
       
   180             ptr.AppendNum( packetNumber, EHex );
   257             // Increase packet number
   181             // Increase packet number
   258             packetNumber++;
   182             packetNumber++;
   259             }
   183             }
   260       
   184       
   261         // Append call stack address.
   185         // Append call stack address.
   262         buffer.Append( KSpace );
   186         ptr.AppendFormat( KHexaNumberTrace, aCallstack.At( addrPos ) );
   263         buffer.AppendNum( aCallstack.At( addrPos ), EHex );
       
   264         
   187         
   265         // Move the call stack position.
   188         // Move the call stack position.
   266         addrPos++;
   189         addrPos++;
   267         
   190         
   268         // Check if buffer max length exceed
   191         // Check if buffer max length exceed
   269         if ( KLastItemLength + buffer.Length() >= KMemAllocBufLength )
   192         if ( lastItemLength + ptr.Length() >= KMemAllocBufLength )
   270             {
   193             {
       
   194             ptr.Append( KNewLineTrace );
   271             // Log through debug channel 
   195             // Log through debug channel 
   272             RDebug::RawPrint( buffer );
   196             RDebug::Print( KTraceMessage, aProcessId, &buffer );
   273             // Empty trace buffer
   197             // Empty trace buffer
   274             buffer.Delete( 0, buffer.MaxLength() );
   198             ptr.Delete( 0, ptr.MaxLength() );
   275             }
   199             }
   276         }
   200         }
   277     // Send last message if exists.
   201     // Send last message if exists.
   278     if ( buffer.Length() > 0 )
   202     if ( ptr.Length() > 0 )
   279         {
   203         {
   280         RDebug::RawPrint( buffer );
   204         ptr.Append( KNewLineTrace );
   281         }
   205         RDebug::Print( KTraceMessage, aProcessId, &buffer);
       
   206         }
       
   207     return KErrNone;
       
   208     }
       
   209 
       
   210 
       
   211 TInt ATFastLogMemoryFreed( TUint aProcessId, TUint32 aMemAddress, 
       
   212                               TFixedArray<TUint32, KATMaxFreeCallstackLength>& aFreeCallstack )
       
   213     {
       
   214     LOGSTR1( "ATFL ATFastLogMemoryFreed()" );
       
   215     // FREEH <Memory address> <Time tamp> <Call stack address count> <Call stack address>
       
   216     // <Call stack address> ...
       
   217     
       
   218     // Timestamp.
       
   219     TInt64 time = CurrentTime();
       
   220     
       
   221     // Trace buffer and pointer to it.
       
   222     TBufC<KMemFreedBufLength> buffer;
       
   223     TPtr ptr( buffer.Des() );
   282  
   224  
   283     return KErrNone;
   225     // Append the tag implying a memory allocation line in the data file
   284     }
   226     ptr.Append( KMemoryFreedHeader );
   285 
   227     
   286 
   228     // Append the start address of this allocation in the 32-bit (max 8 characters)
   287 TInt ATFastLogMemoryFreed( TUint aProcessId, TUint32 aMemAddress, 
   229     // hexadecimal text format.
   288                               TFixedArray<TUint32, KATMaxFreeCallstackLength>& aFreeCallstack,
   230     ptr.AppendNum( aMemAddress, EHex );
   289                               TUint aThreadId )
   231     
   290     {
   232     // Append timestamp;
   291     LOGSTR1( "ATFL ATFastLogMemoryFreed()" );
   233     ptr.Append( KSpaceTrace );
   292 
   234     ptr.AppendNum( time, EHex);
   293 	// FRH <Memory address> <Thread ID> <Call stack address count> 
   235     
   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.
   236     // Search call stack for address count.
   409 	TInt addrCount(0);
   237     TInt addrCount(0);
   410 	for ( TInt j = 0; j < aCallstack.Count() ; j++ )
   238     for ( TInt j = 0; j < aFreeCallstack.Count() ; j++ )
   411 		{
   239         {
   412 		if ( aCallstack.At(j) == 0 )
   240         if ( aFreeCallstack.At(j) == 0 )
   413 			break;
   241             break;
   414 		addrCount++;
   242         addrCount++;
   415 		}
   243         }
   416 	// Current position in call stack.
   244     // Current position in call stack.
   417 	TInt addrPos( 0 );
   245     TInt addrPos( 0 );
   418     
   246     
   419     // address count
   247     // Append address count.
   420     buffer.AppendNum( addrCount, EHex );
   248     ptr.Append( KSpaceTrace );
   421         
   249     ptr.AppendNum( addrCount, EHex );
       
   250             
       
   251     // Calculate last item length
       
   252     TInt lastItemLength( KTraceMessage().Length() + KHexa32Length + 
       
   253             KSpaceLength + KNewlineLength );
       
   254     
   422     TUint packetNumber( 1 );
   255     TUint packetNumber( 1 );
   423     
   256     
   424     // Go through all call stack's memory addresses associated with
   257     // Go through all call stack's memory addresses associated with
   425     // this memory allocation 
   258     // this memory allocation 
   426     for ( TInt j = 0; j < addrCount; j++ )
   259     for ( TInt j = 0; j < addrCount; j++ )
   427         {
   260         {
   428         // RAF <Freed memory address> <Allocated memory address> <Packet number>
   261         // ALLOCF <Memory address> <Time stamp> <Packet number> 
   429         // <Call stack address> <Call stack address> ...
   262         // <Call stack address> <Call stack address> ...
   430         if ( buffer.Length() <= 0 )
   263         if ( ptr.Length() <= 0 )
   431             {
   264             {               
   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
   265             // Create alloc fragment message header
   439             buffer.Append( KMemoryReallocFragment );
   266             ptr.Append( KMemoryFreedFragment );
   440             // memory adress freed
   267             ptr.AppendNum( aMemAddress, EHex );
   441             buffer.AppendNum( aMemAddressFree, EHex );
   268             ptr.Append( KSpaceTrace );
   442             buffer.Append( KSpace );
   269             ptr.AppendNum( packetNumber, EHex );
   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
   270             // Increase packet number
   449             packetNumber++;
   271             packetNumber++;
   450             }
   272             }
   451       
   273       
   452         // Append call stack address.
   274         // Append call stack address.
   453         buffer.Append( KSpace );
   275         ptr.AppendFormat( KHexaNumberTrace, aFreeCallstack.At( addrPos ) );
   454         buffer.AppendNum( aCallstack.At( addrPos ), EHex );
       
   455         
   276         
   456         // Move the call stack position.
   277         // Move the call stack position.
   457         addrPos++;
   278         addrPos++;
   458         
   279         
   459         // Check if buffer max length exceed
   280         // Check if buffer max length exceed
   460         if ( KLastItemLength + buffer.Length() >= KMemAllocBufLength )
   281         if ( lastItemLength + ptr.Length() >= KMemFreedBufLength )
   461             {
   282             {
       
   283             ptr.Append( KNewLineTrace );
   462             // Log through debug channel 
   284             // Log through debug channel 
   463             RDebug::RawPrint( buffer );
   285             RDebug::Print( KTraceMessage, aProcessId, &buffer );
   464             // Empty trace buffer
   286             // Empty trace buffer
   465             buffer.Delete( 0, buffer.MaxLength() );
   287             ptr.Delete( 0, ptr.MaxLength() );
   466             }
   288             }
   467         }
   289         }
   468     // Send last message if exists.
   290     // Send last message if exists.
   469     if ( buffer.Length() > 0 )
   291     if ( ptr.Length() > 0 )
   470         {
   292         {
   471         RDebug::RawPrint( buffer);
   293         ptr.Append( KNewLineTrace );
   472         }
   294         RDebug::Print( KTraceMessage, aProcessId, &buffer);
   473       
   295         }
   474     return KErrNone;
   296     return KErrNone;   
   475     }
   297     }
   476 
   298 
   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     }