perfsrv/memspy/Engine/Source/SysMemTracker/MemSpyEngineHelperSysMemTrackerEntryHandlePAndS.cpp
changeset 48 516af714ebb4
equal deleted inserted replaced
45:185201be11b0 48:516af714ebb4
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "MemSpyEngineHelperSysMemTrackerEntryHandlePAndS.h"
       
    19 
       
    20 // System includes
       
    21 #include <e32base.h>
       
    22 #include <badesca.h>
       
    23 
       
    24 // Driver includes
       
    25 #include <memspy/driver/memspydriverclient.h>
       
    26 #include <memspy/driver/memspydriverconstants.h>
       
    27 #include <memspy/driver/memspydriverenumerationsshared.h>
       
    28 
       
    29 // User includes
       
    30 #include <memspy/engine/memspyengine.h>
       
    31 #include <memspy/engine/memspyengineutils.h>
       
    32 #include <memspy/engine/memspyengineoutputsink.h>
       
    33 #include <memspy/engine/memspyengineoutputlist.h>
       
    34 #include <memspy/engine/memspyenginehelperheap.h>
       
    35 #include <memspy/engine/memspyenginehelperchunk.h>
       
    36 #include <memspy/engine/memspyengineobjectthread.h>
       
    37 #include <memspy/engine/memspyengineobjectprocess.h>
       
    38 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    39 #include <memspy/engine/memspyenginehelpercodesegment.h>
       
    40 #include "MemSpyEngineHelperSysMemTrackerImp.h"
       
    41 #include<memspy/engine/memspyenginehelperkernelcontainers.h>
       
    42 #include <memspy/engine/memspyenginehelpersysmemtrackercycle.h>
       
    43 #include <memspy/engine/memspyenginehelpersysmemtrackerconfig.h>
       
    44 
       
    45 
       
    46 
       
    47 
       
    48 CMemSpyEngineHelperSysMemTrackerEntryHandlePAndS::CMemSpyEngineHelperSysMemTrackerEntryHandlePAndS( CMemSpyEngineHelperSysMemTrackerImp& aTracker )
       
    49 :   CMemSpyEngineHelperSysMemTrackerEntry( aTracker, EMemSpyEngineSysMemTrackerTypeHandlePAndS )
       
    50     {
       
    51     }
       
    52 
       
    53 
       
    54 CMemSpyEngineHelperSysMemTrackerEntryHandlePAndS::~CMemSpyEngineHelperSysMemTrackerEntryHandlePAndS()
       
    55     {
       
    56     delete iName;
       
    57     delete iThreadName;
       
    58     }
       
    59 
       
    60 
       
    61 void CMemSpyEngineHelperSysMemTrackerEntryHandlePAndS::ConstructL( TAny* aHandle )
       
    62     {
       
    63     SetHandle( aHandle );
       
    64     TInt err = Engine().Driver().GetPAndSInfo( aHandle, iInfo );
       
    65     User::LeaveIfError( err );
       
    66     SetThread( iInfo.iTid );
       
    67 
       
    68     // Get thread name, if possible.
       
    69     CMemSpyThread* thread = NULL;
       
    70     CMemSpyProcess* process = NULL;
       
    71     err = Engine().Container().ProcessAndThreadByThreadId( iInfo.iTid, process, thread );
       
    72     if  ( err == KErrNone && thread )
       
    73         {
       
    74         TFullName* name = new(ELeave) TFullName();
       
    75         CleanupStack::PushL( name );
       
    76         thread->FullName( *name );
       
    77         iThreadName = name->AllocL();
       
    78         CleanupStack::PopAndDestroy( name );
       
    79         }
       
    80     else
       
    81         {
       
    82         iThreadName = KMemSpySWMTThreadNotFound().AllocL();
       
    83         }
       
    84     }
       
    85 
       
    86 
       
    87 CMemSpyEngineHelperSysMemTrackerEntryHandlePAndS* CMemSpyEngineHelperSysMemTrackerEntryHandlePAndS::NewLC( CMemSpyEngineHelperSysMemTrackerImp& aTracker, TAny* aHandle )
       
    88     {
       
    89     CMemSpyEngineHelperSysMemTrackerEntryHandlePAndS* self = new(ELeave) CMemSpyEngineHelperSysMemTrackerEntryHandlePAndS( aTracker );
       
    90     CleanupStack::PushL( self );
       
    91     self->ConstructL( aHandle );
       
    92     return self;
       
    93     }
       
    94 
       
    95 
       
    96 TUint64 CMemSpyEngineHelperSysMemTrackerEntryHandlePAndS::Key() const
       
    97     {
       
    98     const TUint32 val = ( Type() << 28 ); 
       
    99     TUint64 ret = val;
       
   100     ret <<= 32;
       
   101     ret += Handle();
       
   102     return ret;
       
   103     }
       
   104 
       
   105 
       
   106 void CMemSpyEngineHelperSysMemTrackerEntryHandlePAndS::CreateChangeDescriptorL( CMemSpyEngineHelperSysMemTrackerCycle& aCycle )
       
   107     {
       
   108     // We lazy fetch the name to avoid having to get info for every single handle whenever a change cycle occurs...
       
   109     if  ( iName == NULL )
       
   110         {
       
   111         TMemSpyDriverHandleInfoGeneric info;
       
   112         const TInt err = Engine().Driver().GetGenericHandleInfo( KMemSpyDriverEnumerateContainerHandles, EMemSpyDriverContainerTypePropertyRef, (TAny*) Handle(), info );
       
   113         if  ( err == KErrNone )
       
   114             {
       
   115             // Save name
       
   116             iName = HBufC::NewL( info.iName.Length() );
       
   117             iName->Des().Copy( info.iName );
       
   118             }
       
   119         else
       
   120             {
       
   121             iName = KNullDesC().AllocL();
       
   122             }
       
   123         }
       
   124     
       
   125     CMemSpyEngineHelperSysMemTrackerCycleChangeHandlePAndS* changeDescriptor = CMemSpyEngineHelperSysMemTrackerCycleChangeHandlePAndS::NewLC( Attributes(), Handle(), iInfo, *iName, *iThreadName );
       
   126     aCycle.AddAndPopL( changeDescriptor );
       
   127     }
       
   128 
       
   129 
       
   130 
       
   131 
       
   132 
       
   133 
       
   134 
       
   135 
       
   136 
       
   137 
       
   138 
       
   139 
       
   140 
       
   141 
       
   142 
       
   143 
       
   144 
       
   145 CMemSpyEngineHelperSysMemTrackerCycleChangeHandlePAndS::CMemSpyEngineHelperSysMemTrackerCycleChangeHandlePAndS( TUint8 aAttribs, TUint32 aHandle, const TMemSpyDriverPAndSInfo& aInfo )
       
   146 :   CMemSpyEngineHelperSysMemTrackerCycleChange( aAttribs ), iHandle( aHandle ), iInfo( aInfo )
       
   147     {
       
   148     }
       
   149 
       
   150 
       
   151 CMemSpyEngineHelperSysMemTrackerCycleChangeHandlePAndS::~CMemSpyEngineHelperSysMemTrackerCycleChangeHandlePAndS()
       
   152     {
       
   153     delete iName;
       
   154     delete iThreadName;
       
   155     }
       
   156 
       
   157 
       
   158 void CMemSpyEngineHelperSysMemTrackerCycleChangeHandlePAndS::ConstructL( const TDesC& aName, const TDesC& aThreadName )
       
   159     {
       
   160     BaseConstructL();
       
   161     //
       
   162     iName = aName.AllocL();
       
   163     iThreadName = aThreadName.AllocL();
       
   164     }
       
   165 
       
   166 
       
   167 CMemSpyEngineHelperSysMemTrackerCycleChangeHandlePAndS* CMemSpyEngineHelperSysMemTrackerCycleChangeHandlePAndS::NewLC( TUint8 aAttribs, TUint32 aHandle, const TMemSpyDriverPAndSInfo& aInfo, const TDesC& aName, const TDesC& aThreadName )
       
   168     {
       
   169     CMemSpyEngineHelperSysMemTrackerCycleChangeHandlePAndS* self = new(ELeave) CMemSpyEngineHelperSysMemTrackerCycleChangeHandlePAndS( aAttribs, aHandle, aInfo );
       
   170     CleanupStack::PushL( self );
       
   171     self->ConstructL( aName, aThreadName );
       
   172     return self;
       
   173     }
       
   174 
       
   175 
       
   176 TMemSpyEngineSysMemTrackerType CMemSpyEngineHelperSysMemTrackerCycleChangeHandlePAndS::Type() const
       
   177     {
       
   178     return EMemSpyEngineSysMemTrackerTypeHandlePAndS;
       
   179     }
       
   180    
       
   181 
       
   182 void CMemSpyEngineHelperSysMemTrackerCycleChangeHandlePAndS::OutputHeaderL( CMemSpyEngineOutputSink& aSink, CMemSpyEngineHelperSysMemTrackerCycle& /*aCycle*/ )
       
   183     {
       
   184     _LIT( KHeaderLine, "Type, Name, Handle, Key Type, Category, Key, Ref. Count, Creator SID, Thread Id, Thread Name, Attribs");
       
   185     aSink.OutputLineL( KHeaderLine );
       
   186     }
       
   187  
       
   188 
       
   189 void CMemSpyEngineHelperSysMemTrackerCycleChangeHandlePAndS::OutputContentL( CMemSpyEngineOutputSink& aSink, CMemSpyEngineHelperSysMemTrackerCycle& /*aCycle*/ )
       
   190     {
       
   191     _LIT( KFormat, "%S,%S,0x%08x,%d,0x%08x,0x%08x,%d,0x%08x,%d,%S,%S" );
       
   192     //
       
   193     TMemSpySWMTTypeName type;
       
   194     FormatType( type );
       
   195     //
       
   196     TBuf<20> attribs;
       
   197     FormatAttributes( attribs );
       
   198     //
       
   199     HBufC* buf = HBufC::NewLC( 1024 );
       
   200     TPtr pBuf(buf->Des());
       
   201 
       
   202     // Now output line
       
   203     pBuf.Format( KFormat, 
       
   204                  &type,
       
   205                  iName, 
       
   206                  iHandle,
       
   207                  iInfo.iType,
       
   208                  iInfo.iCategory,
       
   209                  iInfo.iKey,
       
   210                  iInfo.iRefCount,
       
   211                  iInfo.iCreatorSID,
       
   212                  iInfo.iTid,
       
   213                  iThreadName,
       
   214                  &attribs
       
   215                  );
       
   216 
       
   217     aSink.OutputLineL( pBuf );
       
   218     CleanupStack::PopAndDestroy( buf );
       
   219     }
       
   220 
       
   221 
       
   222 
       
   223 
       
   224 
       
   225 
       
   226