--- a/analyzetool/dynamicmemoryhook/src/analyzetoolfastlog.cpp Wed Sep 15 13:53:27 2010 +0300
+++ b/analyzetool/dynamicmemoryhook/src/analyzetoolfastlog.cpp Wed Oct 13 16:17:58 2010 +0300
@@ -15,6 +15,7 @@
*
*/
+
#include <e32debug.h> // RDebug
#include <analyzetool/analyzetooltraceconstants.h>
#include "analyzetoolfastlog.h"
@@ -31,51 +32,26 @@
TInt ATFastLogProcessStarted( const TDesC8& aProcessName,
TUint aProcessId,
- TUint32 aIsDebug,
- const TDesC8& aAtoolVersion,
- const TDesC8& aApiVersion )
+ TUint32 aIsDebug )
{
LOGSTR1( "ATFL ATFastLogProcessStarted()" );
-
- // PCS <Process name> <Process ID> <Time stamp> <Udeb> <Version>
-
- //Buffer to trace
- TBuf8<KProcessStartBufLength> buffer;
-
- // AT indentifier
- buffer.Append( KATIdentifier );
- // process id
- buffer.AppendNum( aProcessId, EHex );
- buffer.Append( KSpace );
-
- // PCS
- buffer.Append( KProcessStart );
- // process name
- buffer.Append( aProcessName );
- buffer.Append( KSpace );
- // process id
- buffer.AppendNum( aProcessId, EHex );
- buffer.Append( KSpace );
- // time stamp
+ // Convert process name to 16-bit descriptor.
+ TBuf<KMaxProcessName> processName;
+ processName.Copy( aProcessName );
+ // Buffer to trace.
+ TBuf<KProcessStartBufLength> buffer;
+ // Format process name and id.
+ buffer.Format( KProcessStart16, &processName, aProcessId );
+ // Timestamp.
buffer.AppendNum( CurrentTime(), EHex ) ;
- buffer.Append( KSpace );
- // urel/udeb
+ // Append udeb/urel information to the process start.
+ buffer.Append( KSpaceTrace );
buffer.AppendNum( aIsDebug, EHex );
- buffer.Append( KSpace );
- // version
+ // Append version number.
+ buffer.Append( KSpaceTrace );
buffer.AppendNum( KATTraceVersion, EHex );
- buffer.Append( KSpace );
- // atool version
- buffer.Append( aAtoolVersion );
- buffer.Append( KSpace );
- // ATAPI version
- buffer.Append( aApiVersion );
-
-
-
-
- RDebug::RawPrint( buffer );
-
+ // Log to trace.
+ RDebug::Print( KTraceMessage, aProcessId ,&buffer );
return KErrNone;
}
@@ -83,44 +59,21 @@
TUint aHandleLeakCount )
{
LOGSTR1( "ATFL ATFastLogProcessEnded()" );
-
- // PCE
-
+ // Handle leaks.
if ( aHandleLeakCount > 0 )
- {
- // HDL <Handle count>
-
+ {
// Buffer to trace.
- TBuf8<KHandleLeakBufLength> buffer2;
-
- // AT indentifier
- buffer2.Append( KATIdentifier );
- // process id
- buffer2.AppendNum( aProcessId, EHex );
- buffer2.Append( KSpace );
-
- // HDL
- buffer2.Append( KHandleLeak );
- // leak count
- buffer2.AppendNum( aHandleLeakCount );
-
- RDebug::RawPrint( buffer2 );
- }
-
- // Buffer to trace.
- TBuf8<KProcessEndBufLength> buffer;
-
- // AT indentifier
- buffer.Append( KATIdentifier );
- // process id
- buffer.AppendNum( aProcessId, EHex );
- buffer.Append( KSpace );
-
- // PCE
- buffer.Append( KProcessEnd );
- RDebug::RawPrint( buffer );
-
-
+ TBuf<KHandleLeakBufLength> buffer2;
+ buffer2.Format( KHandleLeak16, &KUnknownModule16, aHandleLeakCount );
+ // Trace it.
+ RDebug::Print( KTraceMessage, aProcessId, &buffer2 );
+ }
+ // Process end trace.
+ TBuf<KProcessEndBufLength> buffer;
+ buffer.Format( KProcessEnd16, aProcessId );
+ buffer.AppendNum( CurrentTime(), EHex);
+ buffer.Append( KNewLineTrace );
+ RDebug::Print( KTraceMessage, aProcessId, &buffer );
return KErrNone;
}
@@ -130,31 +83,15 @@
TUint32 aEndAddress )
{
LOGSTR1( "ATFL ATFastLogDllLoaded()" );
-
- // DLL <DLL name> <Memory start address> <Memory end address>
-
+ // Timestamp.
+ TInt64 time = CurrentTime();
+ // Convert dll name to 16-bit descriptor.
+ TBuf<KMaxLibraryName> dll;
+ dll.Copy( aDllName );
// Buffer to trace.
- TBuf8<KDllLoadBufLength> buffer;
-
- // AT indentifier
- buffer.Append( KATIdentifier );
- // process id
- buffer.AppendNum( aProcessId, EHex );
- buffer.Append( KSpace );
-
- // DLL
- buffer.Append( KDllLoad );
- // dll name
- buffer.Append( aDllName );
- buffer.Append( KSpace );
- // start adress
- buffer.AppendNum( aStartAddress, EHex );
- buffer.Append( KSpace );
- //end adress
- buffer.AppendNum( aEndAddress, EHex );
-
- RDebug::RawPrint( buffer );
-
+ TBuf<KDllLoadBufLength> buffer;
+ buffer.Format( KDllLoad16, &dll, time, aStartAddress, aEndAddress );
+ RDebug::Print( KTraceMessage, aProcessId, &buffer );
return KErrNone;
}
@@ -162,77 +99,67 @@
TUint32 aEndAddress )
{
LOGSTR1( "ATFL ATFastLogDllUnloaded()" );
-
- // DLU <DLL name> <Memory start address> <Memory end address>
-
+ // Timestamp.
+ TInt64 time = CurrentTime();
+ // Convert dll name to 16-bit descriptor.
+ TBuf<KMaxLibraryName> dll;
+ dll.Copy( aDllName );
// Buffer to trace.
- TBuf8<KDllUnloadBufLength> buffer;
-
- // AT indentifier
- buffer.Append( KATIdentifier );
- // process id
- buffer.AppendNum( aProcessId, EHex );
- buffer.Append( KSpace );
-
- // DLU
- buffer.Append( KDllUnload );
- // dll name
- buffer.Append( aDllName );
- buffer.Append( KSpace );
- // start adress
- buffer.AppendNum( aStartAddress, EHex );
- buffer.Append( KSpace );
- //end adress
- buffer.AppendNum( aEndAddress, EHex );
-
- RDebug::RawPrint( buffer );
-
+ TBuf<KDllLoadBufLength> buffer;
+ buffer.Format( KDllUnload16, &dll, time, aStartAddress, aEndAddress );
+ RDebug::Print( KTraceMessage, aProcessId, &buffer );
return KErrNone;
}
TInt ATFastLogMemoryAllocated( TUint aProcessId, TUint32 aMemAddress,
TFixedArray<TUint32, KATMaxCallstackLength>& aCallstack,
- TInt aSize, TUint aThreadId )
+ TInt aSize )
{
LOGSTR1( "ATFL ATFastLogMemoryAllocated()" );
+ // ALLOCH <Memory address> <Time stamp> <Allocation size> <Call stack address count>
+ // <Call stack address> <Call stack address> ...
- // ALH <Memory address> <Allocation size> <Thread ID>
- // <Call stack address count> <Call stack address> <Call stack address> ...
-
- // Buffer to trace.
- TBuf8<KMemAllocBufLength> buffer;
+ // Timestamp.
+ TInt64 time = CurrentTime();
+
+ // Trace buffer and pointer to it.
+ TBufC<KMemAllocBufLength> buffer;
+ TPtr ptr( buffer.Des() );
+ // Append the tag implying a memory allocation line in the data file
+ ptr.Append( KMemoryAllocHeader );
- // AT indentifier
- buffer.Append( KATIdentifier );
- // process id
- buffer.AppendNum( aProcessId, EHex );
- buffer.Append( KSpace );
+ // Append the start address of this allocation in the 32-bit (max 8 characters)
+ // hexadecimal text format.
+ ptr.AppendNum( aMemAddress, EHex );
+
+ // Append the current time in the 64-bit (max 16 characters) hexadecimal text
+ // format
+ ptr.Append( KSpaceTrace );
+ ptr.AppendNum( time, EHex );
- // ALH
- buffer.Append( KMemoryAllocHeader );
- // memory adress
- buffer.AppendNum( aMemAddress, EHex );
- buffer.Append( KSpace );
- // allocation size
- buffer.AppendNum( aSize, EHex );
- buffer.Append( KSpace );
- // thread ID
- buffer.AppendNum( aThreadId, EHex );
- buffer.Append( KSpace );
-
+ // Append the size of the allocation in the 32-bit (max 8 characters) hexadecimal
+ // text format.
+ ptr.Append( KSpaceTrace );
+ ptr.AppendNum( aSize, EHex );
+
// Search call stack for address count.
- TInt addrCount(0);
- for ( TInt j = 0; j < aCallstack.Count() ; j++ )
- {
- if ( aCallstack.At(j) == 0 )
- break;
- addrCount++;
- }
- // Current position in call stack.
- TInt addrPos( 0 );
+ TInt addrCount(0);
+ for ( TInt j = 0; j < aCallstack.Count() ; j++ )
+ {
+ if ( aCallstack.At(j) == 0 )
+ break;
+ addrCount++;
+ }
+ // Current position in call stack.
+ TInt addrPos( 0 );
- // address count
- buffer.AppendNum( addrCount, EHex );
+ // Append address count.
+ ptr.Append( KSpaceTrace );
+ ptr.AppendNum( addrCount, EHex );
+
+ // Calculate last item length
+ TInt lastItemLength( KTraceMessage().Length() + KHexa32Length +
+ KSpaceLength + KNewlineLength );
TUint packetNumber( 1 );
@@ -240,310 +167,132 @@
// this memory allocation
for ( TInt j = 0; j < addrCount; j++ )
{
- // ALF <Memory address> <Packet number> <Call stack address> <Call stack address> ...
- if ( buffer.Length() <= 0 )
- {
- // AT indentifier
- buffer.Append( KATIdentifier );
- // process id
- buffer.AppendNum( aProcessId, EHex );
- buffer.Append( KSpace );
-
+ // ALLOCF <Memory address> <Time stamp> <Packet number>
+ // <Call stack address> <Call stack address> ...
+ if ( ptr.Length() <= 0 )
+ {
// Create alloc fragment message header
- buffer.Append( KMemoryAllocFragment );
- buffer.AppendNum( aMemAddress, EHex );
- buffer.Append( KSpace );
- buffer.AppendNum( packetNumber, EHex );
+ ptr.Append( KMemoryAllocFragment );
+ ptr.AppendNum( aMemAddress, EHex );
+ ptr.Append( KSpaceTrace );
+ ptr.AppendNum( time, EHex );
+ ptr.Append( KSpaceTrace );
+ ptr.AppendNum( packetNumber, EHex );
// Increase packet number
packetNumber++;
}
// Append call stack address.
- buffer.Append( KSpace );
- buffer.AppendNum( aCallstack.At( addrPos ), EHex );
+ ptr.AppendFormat( KHexaNumberTrace, aCallstack.At( addrPos ) );
// Move the call stack position.
addrPos++;
// Check if buffer max length exceed
- if ( KLastItemLength + buffer.Length() >= KMemAllocBufLength )
+ if ( lastItemLength + ptr.Length() >= KMemAllocBufLength )
{
+ ptr.Append( KNewLineTrace );
// Log through debug channel
- RDebug::RawPrint( buffer );
+ RDebug::Print( KTraceMessage, aProcessId, &buffer );
// Empty trace buffer
- buffer.Delete( 0, buffer.MaxLength() );
+ ptr.Delete( 0, ptr.MaxLength() );
}
}
// Send last message if exists.
- if ( buffer.Length() > 0 )
+ if ( ptr.Length() > 0 )
{
- RDebug::RawPrint( buffer );
+ ptr.Append( KNewLineTrace );
+ RDebug::Print( KTraceMessage, aProcessId, &buffer);
}
-
return KErrNone;
}
TInt ATFastLogMemoryFreed( TUint aProcessId, TUint32 aMemAddress,
- TFixedArray<TUint32, KATMaxFreeCallstackLength>& aFreeCallstack,
- TUint aThreadId )
+ TFixedArray<TUint32, KATMaxFreeCallstackLength>& aFreeCallstack )
{
LOGSTR1( "ATFL ATFastLogMemoryFreed()" );
-
- // FRH <Memory address> <Thread ID> <Call stack address count>
- // <Call stack address> <Call stack address> ...
-
- // Buffer to trace.
- TBuf8<KMemFreedBufLength> buffer;
-
- // AT indentifier
- buffer.Append( KATIdentifier );
- // process id
- buffer.AppendNum( aProcessId, EHex );
- buffer.Append( KSpace );
-
- // FRH
- buffer.Append( KMemoryFreedHeader );
-
- // Append the start address of this allocation in the 32-bit (max 8 characters)
- // hexadecimal text format.
- buffer.AppendNum( aMemAddress, EHex );
- buffer.Append( KSpace );
-
- // thread ID
- buffer.AppendNum( aThreadId, EHex );
- buffer.Append( KSpace );
-
- // Search call stack for address count.
- TInt addrCount(0);
- for ( TInt j = 0; j < aFreeCallstack.Count() ; j++ )
- {
- if ( aFreeCallstack.At(j) == 0 )
- break;
- addrCount++;
- }
- // Current position in call stack.
- TInt addrPos( 0 );
-
- // address count.
- buffer.AppendNum( addrCount, EHex );
-
- TUint packetNumber( 1 );
-
- // Go through all call stack's memory addresses associated with
- // this memory allocation
- for ( TInt j = 0; j < addrCount; j++ )
- {
- // FRF <Memory address> <Packet number>
- // <Call stack address> <Call stack address> ...
- if ( buffer.Length() <= 0 )
- {
- // Create alloc fragment message header
- buffer.Append( KMemoryFreedFragment );
- buffer.AppendNum( aMemAddress, EHex );
- buffer.Append( KSpace );
- buffer.AppendNum( packetNumber, EHex );
- // Increase packet number
- packetNumber++;
- }
-
- // Append call stack address.
- buffer.Append( KSpace );
- buffer.AppendNum( aFreeCallstack.At( addrPos ), EHex );
-
- // Move the call stack position.
- addrPos++;
-
- // Check if buffer max length exceed
- if ( KLastItemLength + buffer.Length() >= KMemFreedBufLength )
- {
- // Log through debug channel
- RDebug::RawPrint( buffer );
- // Empty trace buffer
- buffer.Delete( 0, buffer.MaxLength() );
- }
- }
- // Send last message if exists.
- if ( buffer.Length() > 0 )
- {
- RDebug::RawPrint( buffer );
- }
-
- return KErrNone;
- }
-
-TInt ATFastLogMemoryReallocated( TUint aProcessId, TUint32 aMemAddressFree, TUint32 aMemAddressAlloc,
- TFixedArray<TUint32, KATMaxCallstackLength>& aCallstack,
- TInt aSize, TUint aThreadId )
- {
- LOGSTR1( "ATFL ATFastLogMemoryReallocated()" );
+ // FREEH <Memory address> <Time tamp> <Call stack address count> <Call stack address>
+ // <Call stack address> ...
+
+ // Timestamp.
+ TInt64 time = CurrentTime();
+
+ // Trace buffer and pointer to it.
+ TBufC<KMemFreedBufLength> buffer;
+ TPtr ptr( buffer.Des() );
+
+ // Append the tag implying a memory allocation line in the data file
+ ptr.Append( KMemoryFreedHeader );
+
+ // Append the start address of this allocation in the 32-bit (max 8 characters)
+ // hexadecimal text format.
+ ptr.AppendNum( aMemAddress, EHex );
- // RAH <Freed memory address> <Allocated memory address> <Allocation size> <Thread ID>
- // <Call stack address count> <Call stack address> <Call stack address> ...
-
- // Buffer to trace.
- TBuf8<KMemReallocBufLength> buffer;
-
- // AT indentifier
- buffer.Append( KATIdentifier );
- // process id
- buffer.AppendNum( aProcessId, EHex );
- buffer.Append( KSpace );
+ // Append timestamp;
+ ptr.Append( KSpaceTrace );
+ ptr.AppendNum( time, EHex);
- // RAH
- buffer.Append( KMemoryReallocHeader );
- // memory adress freed
- buffer.AppendNum( aMemAddressFree, EHex );
- buffer.Append( KSpace );
- // memory adress allocated
- buffer.AppendNum( aMemAddressAlloc, EHex );
- buffer.Append( KSpace );
- // allocation size
- buffer.AppendNum( aSize, EHex );
- buffer.Append( KSpace );
- // thread ID
- buffer.AppendNum( aThreadId, EHex );
- buffer.Append( KSpace );
-
// Search call stack for address count.
- TInt addrCount(0);
- for ( TInt j = 0; j < aCallstack.Count() ; j++ )
- {
- if ( aCallstack.At(j) == 0 )
- break;
- addrCount++;
- }
- // Current position in call stack.
- TInt addrPos( 0 );
+ TInt addrCount(0);
+ for ( TInt j = 0; j < aFreeCallstack.Count() ; j++ )
+ {
+ if ( aFreeCallstack.At(j) == 0 )
+ break;
+ addrCount++;
+ }
+ // Current position in call stack.
+ TInt addrPos( 0 );
- // address count
- buffer.AppendNum( addrCount, EHex );
-
+ // Append address count.
+ ptr.Append( KSpaceTrace );
+ ptr.AppendNum( addrCount, EHex );
+
+ // Calculate last item length
+ TInt lastItemLength( KTraceMessage().Length() + KHexa32Length +
+ KSpaceLength + KNewlineLength );
+
TUint packetNumber( 1 );
// Go through all call stack's memory addresses associated with
// this memory allocation
for ( TInt j = 0; j < addrCount; j++ )
{
- // RAF <Freed memory address> <Allocated memory address> <Packet number>
+ // ALLOCF <Memory address> <Time stamp> <Packet number>
// <Call stack address> <Call stack address> ...
- if ( buffer.Length() <= 0 )
- {
- // AT indentifier
- buffer.Append( KATIdentifier );
- // process id
- buffer.AppendNum( aProcessId, EHex );
- buffer.Append( KSpace );
-
+ if ( ptr.Length() <= 0 )
+ {
// Create alloc fragment message header
- buffer.Append( KMemoryReallocFragment );
- // memory adress freed
- buffer.AppendNum( aMemAddressFree, EHex );
- buffer.Append( KSpace );
- // memory adress allocated
- buffer.AppendNum( aMemAddressAlloc, EHex );
- buffer.Append( KSpace );
- // packet number
- buffer.AppendNum( packetNumber, EHex );
+ ptr.Append( KMemoryFreedFragment );
+ ptr.AppendNum( aMemAddress, EHex );
+ ptr.Append( KSpaceTrace );
+ ptr.AppendNum( packetNumber, EHex );
// Increase packet number
packetNumber++;
}
// Append call stack address.
- buffer.Append( KSpace );
- buffer.AppendNum( aCallstack.At( addrPos ), EHex );
+ ptr.AppendFormat( KHexaNumberTrace, aFreeCallstack.At( addrPos ) );
// Move the call stack position.
addrPos++;
// Check if buffer max length exceed
- if ( KLastItemLength + buffer.Length() >= KMemAllocBufLength )
+ if ( lastItemLength + ptr.Length() >= KMemFreedBufLength )
{
+ ptr.Append( KNewLineTrace );
// Log through debug channel
- RDebug::RawPrint( buffer );
+ RDebug::Print( KTraceMessage, aProcessId, &buffer );
// Empty trace buffer
- buffer.Delete( 0, buffer.MaxLength() );
+ ptr.Delete( 0, ptr.MaxLength() );
}
}
// Send last message if exists.
- if ( buffer.Length() > 0 )
+ if ( ptr.Length() > 0 )
{
- RDebug::RawPrint( buffer);
+ ptr.Append( KNewLineTrace );
+ RDebug::Print( KTraceMessage, aProcessId, &buffer);
}
-
- return KErrNone;
- }
-
-TInt ATFastLogThreadStarted( TUint aProcessId, TUint aThreadId )
- {
- LOGSTR1( "ATFL ATFastLogThreadStarted()" );
-
- // TDS <Thread ID>
-
- //Buffer to trace
- TBuf8<KThreadStartBufLength> buffer;
-
- // AT indentifier
- buffer.Append( KATIdentifier );
- // process id
- buffer.AppendNum( aProcessId, EHex );
- buffer.Append( KSpace );
-
- // TDS
- buffer.Append( KThreadStart );
- // thread ID
- buffer.AppendNum( aThreadId, EHex );
-
- RDebug::RawPrint( buffer );
-
- return KErrNone;
+ return KErrNone;
}
-TInt ATFastLogThreadEnded( TUint aProcessId, TUint64 aThreadId )
- {
- LOGSTR1( "ATFL ATFastLogThreadEnded()" );
-
- // TDE <Thread ID>
-
- //Buffer to trace
- TBuf8<KThreadEndBufLength> buffer;
-
- // AT indentifier
- buffer.Append( KATIdentifier );
- // process id
- buffer.AppendNum( aProcessId, EHex );
- buffer.Append( KSpace );
-
- // TDE
- buffer.Append( KThreadEnd );
- // thread ID
- buffer.AppendNum( aThreadId, EHex );
-
- RDebug::RawPrint( buffer );
-
- return KErrNone;
- }
-
-TInt ATFastLogDeviceInfo( const TDesC8& aS60Version, const TDesC8& aChecksum)
- {
- LOGSTR1( "ATFL ATFastLogVersionsInfo()" );
-
- //Buffer to trace
- TBuf8<KVersionsInfoBufLength> buffer;
-
- // AT indentifier
- buffer.Append( KATIdentifier );
-
- // VER
- buffer.Append( KVersionsInfo );
-
- // sw version
- buffer.Append(aS60Version);
- buffer.Append(KSpace);
- // rom checksum
- buffer.Append(aChecksum);
-
- RDebug::RawPrint( buffer );
-
- return KErrNone;
- }