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