memspy/Engine/Source/SysMemTracker/MemSpyEngineHelperSysMemTrackerEntryManager.cpp
changeset 48 516af714ebb4
parent 45 185201be11b0
child 55 f2950aff7424
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 "MemSpyEngineHelperSysMemTrackerEntryManager.h"
       
    19 
       
    20 // System includes
       
    21 #include <e32debug.h>
       
    22 
       
    23 // Driver includes
       
    24 #include <memspy/driver/memspydriverclient.h>
       
    25 
       
    26 // User includes
       
    27 #include <memspy/engine/memspyengine.h>
       
    28 #include <memspy/engine/memspyengineutils.h>
       
    29 #include <memspy/engine/memspyenginemidwife.h>
       
    30 #include <memspy/engine/memspyengineundertaker.h>
       
    31 #include <memspy/engine/memspyengineobjectthread.h>
       
    32 #include <memspy/engine/memspyengineobjectprocess.h>
       
    33 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    34 #include <memspy/engine/memspyenginehelperheap.h>
       
    35 #include <memspy/engine/memspyenginehelperchunk.h>
       
    36 #include <memspy/engine/memspyenginehelperfbserv.h>
       
    37 #include <memspy/engine/memspyenginehelperfilesystem.h>
       
    38 #include <memspy/engine/memspyenginehelpercodesegment.h>
       
    39 #include <memspy/engine/memspyenginehelperkernelcontainers.h>
       
    40 #include <memspy/engine/memspyenginehelperwindowserver.h>
       
    41 #include <memspy/engine/memspyenginehelpersysmemtracker.h>
       
    42 #include "MemSpyEngineHelperSysMemTrackerImp.h"
       
    43 #include "MemSpyEngineHelperSysMemTrackerLog.h"
       
    44 #include <memspy/engine/memspyenginehelpersysmemtrackercycle.h>
       
    45 #include <memspy/engine/memspyenginehelpersysmemtrackercyclechange.h>
       
    46 #include "MemSpyEngineHelperSysMemTrackerEntries.h"
       
    47 #include "MemSpyEngineHelperSysMemTrackerEntryChunk.h"
       
    48 #include "MemSpyEngineHelperSysMemTrackerEntryGlobalData.h"
       
    49 #include "MemSpyEngineHelperSysMemTrackerEntryHeap.h"
       
    50 #include "MemSpyEngineHelperSysMemTrackerEntryRamDrive.h"
       
    51 #include "MemSpyEngineHelperSysMemTrackerEntryStack.h"
       
    52 #include "MemSpyEngineHelperSysMemTrackerEntryCode.h"
       
    53 #include "MemSpyEngineHelperSysMemTrackerEntryHandleGeneric.h"
       
    54 #include "MemSpyEngineHelperSysMemTrackerEntryHandlePAndS.h"
       
    55 #include "MemSpyEngineHelperSysMemTrackerEntryOpenFile.h"
       
    56 #include "MemSpyEngineHelperSysMemTrackerEntryDiskSpace.h"
       
    57 #include "MemSpyEngineHelperSysMemTrackerEntryBitmap.h"
       
    58 #include "MemSpyEngineHelperSysMemTrackerEntryFbserv.h"
       
    59 #include "MemSpyEngineHelperSysMemTrackerEntryFileServerCache.h"
       
    60 #include "MemSpyEngineHelperSysMemTrackerEntrySystemMemory.h"
       
    61 #include "MemSpyEngineHelperSysMemTrackerEntryWindowServer.h"
       
    62 
       
    63 
       
    64 // Constants
       
    65 
       
    66 // Message printed to RDebug output for some clients that may be reading traces 
       
    67 _LIT( KMemSpyKeepaliveMessage, "<MEMSPY_PROGRESS>" );
       
    68 
       
    69 
       
    70 CMemSpyEngineHelperSysMemTrackerEntryManager::CMemSpyEngineHelperSysMemTrackerEntryManager( CMemSpyEngineHelperSysMemTrackerImp& aTracker, CMemSpyEngineHelperSysMemTrackerEntryManager* aMasterList )
       
    71 :   iTracker( aTracker ), iMasterList( aMasterList )
       
    72     {
       
    73     }
       
    74 
       
    75     
       
    76 CMemSpyEngineHelperSysMemTrackerEntryManager::~CMemSpyEngineHelperSysMemTrackerEntryManager()
       
    77     {
       
    78     iEntries.ResetAndDestroy();
       
    79     iEntries.Close();
       
    80     }
       
    81 
       
    82 
       
    83 void CMemSpyEngineHelperSysMemTrackerEntryManager::ConstructL()
       
    84     {
       
    85     CreateSeedItemsL();
       
    86     }
       
    87 
       
    88 
       
    89 CMemSpyEngineHelperSysMemTrackerEntryManager* CMemSpyEngineHelperSysMemTrackerEntryManager::NewL( CMemSpyEngineHelperSysMemTrackerImp& aTracker )
       
    90     {
       
    91     CMemSpyEngineHelperSysMemTrackerEntryManager* self = new(ELeave) CMemSpyEngineHelperSysMemTrackerEntryManager( aTracker );
       
    92     CleanupStack::PushL( self );
       
    93     self->ConstructL();
       
    94     CleanupStack::Pop( self );
       
    95     return self;
       
    96     }
       
    97 
       
    98 
       
    99 CMemSpyEngineHelperSysMemTrackerEntryManager* CMemSpyEngineHelperSysMemTrackerEntryManager::NewL( CMemSpyEngineHelperSysMemTrackerImp& aTracker, CMemSpyEngineHelperSysMemTrackerEntryManager& aMasterList )
       
   100     {
       
   101     CMemSpyEngineHelperSysMemTrackerEntryManager* self = new(ELeave) CMemSpyEngineHelperSysMemTrackerEntryManager( aTracker, &aMasterList );
       
   102     CleanupStack::PushL( self );
       
   103     self->ConstructL();
       
   104     CleanupStack::Pop( self );
       
   105     return self;
       
   106     }
       
   107 
       
   108 
       
   109 void CMemSpyEngineHelperSysMemTrackerEntryManager::IdentifyChangesL( CMemSpyEngineHelperSysMemTrackerCycle& aCycle )
       
   110     {
       
   111     // Mark everything in this list (i.e. the master list) as dead.
       
   112     MarkEverythingDead();
       
   113 
       
   114     // Create a new list which will act as a secondary list. This new list will only contain
       
   115     // new entries. Any entries which it attempts to create that already exist in the master list
       
   116     // will be discared (after updating the corresponding master list entry with new values).
       
   117     CMemSpyEngineHelperSysMemTrackerEntryManager* newEM = CMemSpyEngineHelperSysMemTrackerEntryManager::NewL( iTracker, *this );
       
   118     CleanupStack::PushL( newEM );
       
   119 
       
   120     // At this point, we have performed several key operations
       
   121     // 
       
   122     // 1) We have tagged everything that is still alive as "alive".
       
   123     // 2) We have left everything that no longer exists as "dead"
       
   124     // 3) We have updated all alive entries with new values (if they have changed)
       
   125     // 4) We have identified new entries (these are currently orphaned within the secondary list right now).
       
   126     //
       
   127     // We now need to merge the two lists, i.e. take all the new entries in 'newEM' and merge them
       
   128     // into the current master list.
       
   129     MergeListIntoMeL( *newEM );
       
   130 
       
   131     // We can throw the other list away now as it will be empty.
       
   132     CleanupStack::PopAndDestroy( newEM );
       
   133 
       
   134     // At this point we have our final new list, but it still contains dead entries.
       
   135     // We must next output all the change information required for this cycle.
       
   136     ProcessChangesL( aCycle );
       
   137     }
       
   138 
       
   139 
       
   140 void CMemSpyEngineHelperSysMemTrackerEntryManager::EverythingHasChangedL( CMemSpyEngineHelperSysMemTrackerCycle& aCycle )
       
   141     {
       
   142     ProcessChangesL( aCycle );
       
   143     }
       
   144 
       
   145 
       
   146 
       
   147 
       
   148 
       
   149 
       
   150 
       
   151 
       
   152 
       
   153 
       
   154 
       
   155 
       
   156 
       
   157 
       
   158 
       
   159 
       
   160 
       
   161 
       
   162 
       
   163 
       
   164 
       
   165 
       
   166 
       
   167 void CMemSpyEngineHelperSysMemTrackerEntryManager::ProcessChangesL( CMemSpyEngineHelperSysMemTrackerCycle& aCycle )
       
   168     {
       
   169     const TInt count = iEntries.Count();
       
   170     for( TInt i=count-1; i>=0; i-- )
       
   171         {
       
   172         CMemSpyEngineHelperSysMemTrackerEntry* entry = iEntries[ i ];
       
   173         
       
   174         // Create any change descriptors etc
       
   175         TRAP_IGNORE( entry->HandleNewCycleL( aCycle ) );
       
   176 
       
   177         // Destroy the entry if it's no longer needed
       
   178         if  ( entry->IsDead() )
       
   179             {
       
   180             delete entry;
       
   181             iEntries.Remove( i );
       
   182             }
       
   183         else
       
   184             {
       
   185             // It's not new anymore
       
   186             entry->SetNew( EFalse );
       
   187             }
       
   188         }
       
   189     }
       
   190 
       
   191 
       
   192 void CMemSpyEngineHelperSysMemTrackerEntryManager::AddItemAndPopL( CMemSpyEngineHelperSysMemTrackerEntry* aItem )
       
   193     {
       
   194     // We sort by entry key, we do not allow duplicates
       
   195     TLinearOrder<CMemSpyEngineHelperSysMemTrackerEntry> orderer( CompareKey );
       
   196 
       
   197     // Before we save the entry we must check to see if the master list knows about it.
       
   198     const TUint64 key( aItem->Key() );
       
   199 
       
   200     // Operates in one of two ways. If we're in stand-alone mode, then it saves every specified entry.
       
   201     // If we're in secondary mode (i.e. we have an associated master list) then it only saves new entries.
       
   202     // Entries which are changed are updated (in the master list) and entries that don't exist anymore
       
   203     // are tagged as dead.
       
   204     //
       
   205     if  ( ActingAsSecondaryList() )
       
   206         {
       
   207         CMemSpyEngineHelperSysMemTrackerEntry* existingEntry = iMasterList->EntryByKey( key );
       
   208         if  ( existingEntry )
       
   209             {
       
   210             // Entry used to exist, still does. Update the master list entry with the information
       
   211             // from the transient (new) entry.
       
   212             existingEntry->UpdateFromL( *aItem );
       
   213 
       
   214             // Entry is still alive. Previously, at the start of the cycle, we'd tagged all master list
       
   215             // entries as dead, hence we must undo that if we find the entry really still exists...
       
   216             // NB: this also updates the timestamp for the entry, to show when it was last still alive.
       
   217             existingEntry->SetAlive();
       
   218 
       
   219             // But it definitely isn't new anymore as we've seen it at least once before
       
   220             existingEntry->SetNew( EFalse );
       
   221 
       
   222             // Transient entry not needed anymore, keep original
       
   223             CleanupStack::PopAndDestroy( aItem );
       
   224             }
       
   225         else
       
   226             {
       
   227             // Entry didn't exist before - it's a new one
       
   228             iEntries.InsertInOrderL( aItem, orderer );
       
   229             CleanupStack::Pop( aItem );
       
   230             }
       
   231 
       
   232         // Any entries in the master list which aren't present anymore in this list (aka, dead entries)
       
   233         // will remain tagged as dead and will be filtered out and dealt with shortly...
       
   234         }
       
   235     else
       
   236         {
       
   237         // We ARE the master list
       
   238         const TInt err = iEntries.InsertInOrder( aItem, orderer );
       
   239         if  ( err == KErrAlreadyExists )
       
   240             {
       
   241             // Don't allow duplicates
       
   242             RDebug::Printf( "CMemSpyEngineHelperSysMemTrackerEntryManager::AddItemAndPopL() - ******* duplicate key ******* key: %LU, type: %d, tid: 0x%08x, pid: 0x%08x, handle: 0x%08x", key, aItem->Type(), (TUint32) aItem->ThreadId(), (TUint32) aItem->ProcessId(), aItem->Handle() );
       
   243             delete aItem;
       
   244             }
       
   245         else if ( err != KErrNone )
       
   246             {
       
   247             User::Leave( err );
       
   248             }
       
   249 
       
   250         CleanupStack::Pop( aItem );
       
   251         }
       
   252     }
       
   253 
       
   254 
       
   255 void CMemSpyEngineHelperSysMemTrackerEntryManager::MarkEverythingDead()
       
   256     {
       
   257     const TInt count = iEntries.Count();
       
   258     for( TInt i=count-1; i>=0; i-- )
       
   259         {
       
   260         CMemSpyEngineHelperSysMemTrackerEntry* entry = iEntries[ i ];
       
   261         entry->SetDead();
       
   262         }
       
   263     }
       
   264 
       
   265 
       
   266 void CMemSpyEngineHelperSysMemTrackerEntryManager::MergeListIntoMeL( CMemSpyEngineHelperSysMemTrackerEntryManager& aOtherList )
       
   267     {
       
   268     const TInt count = aOtherList.iEntries.Count();
       
   269     for( TInt i=count-1; i>=0; i-- )
       
   270         {
       
   271         CMemSpyEngineHelperSysMemTrackerEntry* entry = aOtherList.iEntries[ i ];
       
   272         CleanupStack::PushL( entry );
       
   273         aOtherList.iEntries.Remove( i );
       
   274         AddItemAndPopL( entry );
       
   275         }
       
   276     }
       
   277 
       
   278 
       
   279 TInt CMemSpyEngineHelperSysMemTrackerEntryManager::FindByHandle( TUint aHandle, TMemSpyEngineSysMemTrackerType aType ) const
       
   280     {
       
   281     TInt ret = KErrNotFound;
       
   282     //
       
   283     const TInt count = iEntries.Count();
       
   284     for( TInt i=0; i<count; i++ )
       
   285         {
       
   286         const CMemSpyEngineHelperSysMemTrackerEntry* entry = iEntries[ i ];
       
   287         if  ( entry->Handle() == aHandle && entry->Type() == aType )
       
   288             {
       
   289             ret = i;
       
   290             break;
       
   291             }
       
   292         }
       
   293     //
       
   294     return ret;
       
   295     }
       
   296 
       
   297 
       
   298 TInt CMemSpyEngineHelperSysMemTrackerEntryManager::FindByThreadId( const TThreadId& aThreadId ) const
       
   299     {
       
   300     TInt ret = KErrNotFound;
       
   301     //
       
   302     const TInt count = iEntries.Count();
       
   303     for( TInt i=0; i<count; i++ )
       
   304         {
       
   305         const CMemSpyEngineHelperSysMemTrackerEntry* entry = iEntries[ i ];
       
   306         if  ( entry->ThreadId() == aThreadId )
       
   307             {
       
   308             ret = i;
       
   309             break;
       
   310             }
       
   311         }
       
   312     //
       
   313     return ret;
       
   314     }
       
   315 
       
   316 
       
   317 CMemSpyEngineHelperSysMemTrackerEntry* CMemSpyEngineHelperSysMemTrackerEntryManager::EntryByKey( const TUint64& aKey )
       
   318     {
       
   319     TLinearOrder<CMemSpyEngineHelperSysMemTrackerEntry> orderer( CompareKey );
       
   320     //
       
   321     CMemSpyEngineHelperSysMemTrackerEntryWithSuppliedKey tempEntry( iTracker, aKey );
       
   322     const TInt pos = iEntries.FindInOrder( &tempEntry, orderer );
       
   323     //
       
   324     CMemSpyEngineHelperSysMemTrackerEntry* ret = NULL;
       
   325     if  ( pos >= 0 )
       
   326         {
       
   327         ret = iEntries[ pos ];
       
   328         }
       
   329     //
       
   330     return ret;
       
   331     }
       
   332 
       
   333 
       
   334 TInt CMemSpyEngineHelperSysMemTrackerEntryManager::CompareKey( const CMemSpyEngineHelperSysMemTrackerEntry& aLeft, const CMemSpyEngineHelperSysMemTrackerEntry& aRight )
       
   335     {
       
   336     TInt ret = -1;
       
   337     //
       
   338     const TUint64 kLeft( aLeft.Key() );
       
   339     const TUint64 kRight( aRight.Key() );
       
   340     //
       
   341     if  ( kLeft > kRight )
       
   342         {
       
   343         ret = 1;
       
   344         }
       
   345     else if ( kLeft == kRight )
       
   346         {
       
   347         ret = 0;
       
   348         }
       
   349     //
       
   350     return ret;
       
   351     }
       
   352 
       
   353 
       
   354 TInt CMemSpyEngineHelperSysMemTrackerEntryManager::CompareKeyAndTimeStamp( const CMemSpyEngineHelperSysMemTrackerEntry& aLeft, const CMemSpyEngineHelperSysMemTrackerEntry& aRight )
       
   355     {
       
   356     TInt ret = CompareKey( aLeft, aRight );
       
   357     if  ( ret == 0 )
       
   358         {
       
   359         // Keys are the same, so compare time stamps
       
   360         const TTime& tLeft = aLeft.LastUpdateTime();
       
   361         const TTime& tRight = aRight.LastUpdateTime();
       
   362         //
       
   363         ret = -1;
       
   364         if  ( tLeft > tRight )
       
   365             {
       
   366             ret = 1;
       
   367             }
       
   368         else if ( tLeft == tRight )
       
   369             {
       
   370             ret = 0;
       
   371             }
       
   372         }
       
   373     //
       
   374     return ret;
       
   375     }
       
   376 
       
   377 
       
   378 CMemSpyEngine& CMemSpyEngineHelperSysMemTrackerEntryManager::Engine()
       
   379     {
       
   380     return iTracker.Engine();
       
   381     }
       
   382 
       
   383 
       
   384 
       
   385 
       
   386 
       
   387 
       
   388 
       
   389 
       
   390 
       
   391 
       
   392 
       
   393 
       
   394 
       
   395 
       
   396 
       
   397 
       
   398 
       
   399 
       
   400 
       
   401 
       
   402 
       
   403 
       
   404 
       
   405 
       
   406 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsL()
       
   407     {
       
   408     RDebug::Print( KMemSpyKeepaliveMessage );
       
   409     
       
   410     TMemSpyEngineHelperSysMemTrackerConfig config;
       
   411     Engine().HelperSysMemTracker().GetConfig( config );
       
   412     
       
   413     // Get chunk list for entire device
       
   414     CMemSpyEngineChunkList* chunks = Engine().HelperChunk().ListL( );
       
   415     CleanupStack::PushL( chunks );
       
   416 
       
   417 #ifdef SYSMEMTRACKERLOGGING
       
   418     {
       
   419     const TInt chunkCount = chunks->Count();
       
   420     for( TInt i=chunkCount-1; i>=0; i-- )
       
   421         {
       
   422         const TMemSpyDriverChunkInfo& info = chunks->At( i ).Info();
       
   423         RDebug::Print( _L("CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsL() - MASTER - info[%03d]: type: %d, size: %d, name: %S"), i, info.iType, info.iSize, &info.iName );
       
   424         }
       
   425     }
       
   426 #endif
       
   427     
       
   428     if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryFileServerCache )
       
   429         {
       
   430         RDebug::Print( KMemSpyKeepaliveMessage );
       
   431         // Extract F32 cache chunk
       
   432         CreateSeedItemsFileServerCacheL( *chunks );        
       
   433         }
       
   434 
       
   435 #ifdef SYSMEMTRACKERLOGGING
       
   436     {
       
   437     const TInt chunkCount = chunks->Count();
       
   438     for( TInt i=chunkCount-1; i>=0; i-- )
       
   439         {
       
   440         const TMemSpyDriverChunkInfo& info = chunks->At( i ).Info();
       
   441         RDebug::Print( _L("CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsL() -  AFTER F32 CACHE - info[%03d]: type: %d, size: %d, name: %S"), i, info.iType, info.iSize, &info.iName );
       
   442         }
       
   443     }
       
   444 #endif
       
   445 
       
   446 // TODO: Uncomment when  bitmap handels are fixed
       
   447 //    if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryBitmapHandles )
       
   448 //        {
       
   449 //        RDebug::Print( KMemSpyKeepaliveMessage );
       
   450 //        // Bitmap
       
   451 //        CreateSeedItemsBitmapL( *chunks );        
       
   452 //        }
       
   453 
       
   454 #ifdef SYSMEMTRACKERLOGGING
       
   455     {
       
   456     const TInt chunkCount = chunks->Count();
       
   457     for( TInt i=chunkCount-1; i>=0; i-- )
       
   458         {
       
   459         const TMemSpyDriverChunkInfo& info = chunks->At( i ).Info();
       
   460         RDebug::Print( _L("CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsL() -  AFTER BITMAPS - info[%03d]: type: %d, size: %d, name: %S"), i, info.iType, info.iSize, &info.iName );
       
   461         }
       
   462     }
       
   463 #endif
       
   464 
       
   465     if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserHeap )
       
   466         {
       
   467         RDebug::Print( KMemSpyKeepaliveMessage );
       
   468         // Look for user heaps
       
   469         CreateSeedItemsHeapUserL( *chunks );
       
   470         }
       
   471 
       
   472 #ifdef SYSMEMTRACKERLOGGING
       
   473     {
       
   474     const TInt chunkCount = chunks->Count();
       
   475     for( TInt i=chunkCount-1; i>=0; i-- )
       
   476         {
       
   477         const TMemSpyDriverChunkInfo& info = chunks->At( i ).Info();
       
   478         RDebug::Print( _L("CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsL() -  AFTER USER HEAP - info[%03d]: type: %d, size: %d, name: %S"), i, info.iType, info.iSize, &info.iName );
       
   479         }
       
   480     }
       
   481 #endif
       
   482 
       
   483 //  TODO: Uncomment after fix
       
   484 //    if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryKernelHeap )
       
   485 //        {
       
   486 //        RDebug::Print( KMemSpyKeepaliveMessage );
       
   487 //        // Look for kernel heaps
       
   488 //        CreateSeedItemsHeapKernelL( *chunks );
       
   489 //        }
       
   490 
       
   491 #ifdef SYSMEMTRACKERLOGGING
       
   492     {
       
   493     const TInt chunkCount = chunks->Count();
       
   494     for( TInt i=chunkCount-1; i>=0; i-- )
       
   495         {
       
   496         const TMemSpyDriverChunkInfo& info = chunks->At( i ).Info();
       
   497         RDebug::Print( _L("CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsL() -  AFTER KERNEL HEAP - info[%03d]: type: %d, size: %d, name: %S"), i, info.iType, info.iSize, &info.iName );
       
   498         }
       
   499     }
       
   500 #endif
       
   501 
       
   502     if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryLocalChunks )
       
   503         {
       
   504         RDebug::Print( KMemSpyKeepaliveMessage );
       
   505         // Local chunks
       
   506         CreateSeedItemsChunkLocalL( *chunks );        
       
   507         }
       
   508 
       
   509 #ifdef SYSMEMTRACKERLOGGING
       
   510     {
       
   511     const TInt chunkCount = chunks->Count();
       
   512     for( TInt i=chunkCount-1; i>=0; i-- )
       
   513         {
       
   514         const TMemSpyDriverChunkInfo& info = chunks->At( i ).Info();
       
   515         RDebug::Print( _L("CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsL() -  AFTER LOCL CHUNK - info[%03d]: type: %d, size: %d, name: %S"), i, info.iType, info.iSize, &info.iName );
       
   516         }
       
   517     }
       
   518 #endif
       
   519 
       
   520     if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryGlobalChunks )
       
   521         {
       
   522         RDebug::Print( KMemSpyKeepaliveMessage );
       
   523         // Global chunks
       
   524         CreateSeedItemsChunkGlobalL( *chunks );        
       
   525         }
       
   526 
       
   527 #ifdef SYSMEMTRACKERLOGGING
       
   528     {
       
   529     const TInt chunkCount = chunks->Count();
       
   530     for( TInt i=chunkCount-1; i>=0; i-- )
       
   531         {
       
   532         const TMemSpyDriverChunkInfo& info = chunks->At( i ).Info();
       
   533         RDebug::Print( _L("CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsL() -  AFTER GLOB CHUNK - info[%03d]: type: %d, size: %d, name: %S"), i, info.iType, info.iSize, &info.iName );
       
   534         }
       
   535     }
       
   536 #endif
       
   537 
       
   538     if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryRAMDrive )
       
   539         {
       
   540         RDebug::Print( KMemSpyKeepaliveMessage );
       
   541         // RAM drive
       
   542         CreateSeedItemRamDriveL( *chunks );        
       
   543         }
       
   544 
       
   545 #ifdef SYSMEMTRACKERLOGGING
       
   546     {
       
   547     const TInt chunkCount = chunks->Count();
       
   548     for( TInt i=chunkCount-1; i>=0; i-- )
       
   549         {
       
   550         const TMemSpyDriverChunkInfo& info = chunks->At( i ).Info();
       
   551         RDebug::Print( _L("CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsL() -  AFTER RAMD - info[%03d]: type: %d, size: %d, name: %S"), i, info.iType, info.iSize, &info.iName );
       
   552         }
       
   553     }
       
   554 #endif
       
   555 
       
   556 //    TODO: Uncomment after fix
       
   557 //    if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserStacks )
       
   558 //        {
       
   559 //        RDebug::Print( KMemSpyKeepaliveMessage );
       
   560 //        // Stacks ($DAT)
       
   561 //        CreateSeedItemsStacksL( *chunks );        
       
   562 //        }
       
   563 
       
   564 #ifdef SYSMEMTRACKERLOGGING
       
   565      {
       
   566    const TInt chunkCount = chunks->Count();
       
   567     for( TInt i=chunkCount-1; i>=0; i-- )
       
   568         {
       
   569         const TMemSpyDriverChunkInfo& info = chunks->At( i ).Info();
       
   570         RDebug::Print( _L("CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsL() -  AFTER STACKS - info[%03d]: type: %d, size: %d, name: %S"), i, info.iType, info.iSize, &info.iName );
       
   571         }
       
   572     }
       
   573 #endif
       
   574 
       
   575 //  TODO: Uncomment after fix
       
   576 //    if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryGlobalData )
       
   577 //        {
       
   578 //        RDebug::Print( KMemSpyKeepaliveMessage );
       
   579 //        // Global data (DLL$DATA)
       
   580 //        CreateSeedItemsGlobalDataL( *chunks );        
       
   581 //        }
       
   582 
       
   583  #ifdef SYSMEMTRACKERLOGGING
       
   584     {
       
   585     const TInt chunkCount = chunks->Count();
       
   586     for( TInt i=chunkCount-1; i>=0; i-- )
       
   587         {
       
   588         const TMemSpyDriverChunkInfo& info = chunks->At( i ).Info();
       
   589         RDebug::Print( _L("CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsL() -  AFTER GLOBAL DATA - info[%03d]: type: %d, size: %d, name: %S"), i, info.iType, info.iSize, &info.iName );
       
   590         }
       
   591     }
       
   592 #endif
       
   593 
       
   594     // Don't need the chunks anymore
       
   595     CleanupStack::PopAndDestroy( chunks );
       
   596 
       
   597     if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryRAMLoadedCode )
       
   598         {
       
   599         RDebug::Print( KMemSpyKeepaliveMessage );
       
   600         // Code
       
   601         CreateSeedItemsCodeL();        
       
   602         }
       
   603 
       
   604     if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryKernelHandles )
       
   605         {
       
   606         // Handles
       
   607         RDebug::Print( KMemSpyKeepaliveMessage);
       
   608         CreateSeedItemsHandlesL();        
       
   609         }
       
   610 
       
   611     if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryOpenFiles )
       
   612         {
       
   613         RDebug::Print( KMemSpyKeepaliveMessage );
       
   614         // Open files
       
   615         CreateSeedItemsOpenFilesL();        
       
   616         }
       
   617 
       
   618     if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryDiskusage )
       
   619         {
       
   620         RDebug::Print( KMemSpyKeepaliveMessage );
       
   621         // Disk space
       
   622         CreateSeedItemsDiskSpaceL();        
       
   623         }
       
   624 
       
   625     if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategorySystemMemory )
       
   626         {
       
   627         RDebug::Print( KMemSpyKeepaliveMessage );
       
   628         // System memory
       
   629         CreateSeedItemsSystemMemoryL();        
       
   630         }
       
   631 	
       
   632     if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryWindowGroups )
       
   633         {
       
   634         RDebug::Print( KMemSpyKeepaliveMessage );
       
   635         // Window Server
       
   636         CreateSeedItemsWindowServerL();        
       
   637         }
       
   638     }
       
   639 
       
   640 
       
   641 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsHeapUserL( CMemSpyEngineChunkList& aList )
       
   642     {
       
   643     CMemSpyEngine& engine = Engine();
       
   644     const TInt procCount = engine.Container().Count();
       
   645     for(TInt i=0; i<procCount; i++)
       
   646         {
       
   647         if ( !( i % 10 ) ) // Print the message on only every 10th cycle
       
   648             {
       
   649             RDebug::Print( KMemSpyKeepaliveMessage  );
       
   650             }
       
   651         CMemSpyProcess& process = engine.Container().At( i );
       
   652         TRAP_IGNORE( CreateSeedItemsHeapUserL( process, &aList ) );
       
   653         }
       
   654     }
       
   655 
       
   656 
       
   657 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsHeapUserL( CMemSpyProcess& aProcess, CMemSpyEngineChunkList* aList )
       
   658     {
       
   659     SYSMEMTRACKERLOG_PRINTF( RDebug::Printf( "CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsHeapUserL() - START - aProcess: %d", (TUint) aProcess.Id() ) );
       
   660     
       
   661     CMemSpyEngine& engine = Engine();
       
   662     engine.ProcessSuspendLC( aProcess.Id() );
       
   663 
       
   664     const TInt threadCount = aProcess.Count();
       
   665     SYSMEMTRACKERLOG_PRINTF( RDebug::Printf( "CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsHeapUserL() - threadCount: %d", threadCount ) );
       
   666 
       
   667     for( TInt j=0; j<threadCount; j++ )
       
   668         {
       
   669         CMemSpyThread& thread = aProcess.At( j );
       
   670         //
       
   671         if  ( !thread.IsDead() )
       
   672             {
       
   673             TRAP_IGNORE( CreateSeedItemsHeapUserL( thread, aList ) );
       
   674             }
       
   675         }
       
   676     
       
   677     CleanupStack::PopAndDestroy(); // ProcessSuspendLC
       
   678 
       
   679     SYSMEMTRACKERLOG_PRINTF( RDebug::Printf( "CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsHeapUserL() - END" ) );
       
   680     }
       
   681 
       
   682 
       
   683 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsHeapUserL( CMemSpyThread& aThread, CMemSpyEngineChunkList* aList )
       
   684     {
       
   685     TBool exists = FindByThreadId( aThread.Id() ) != KErrNotFound;
       
   686     //
       
   687     if  ( !exists )
       
   688         {
       
   689         CMemSpyEngineHelperSysMemTrackerEntryHeap* entry = CMemSpyEngineHelperSysMemTrackerEntryHeap::NewUserLC( iTracker, aThread );
       
   690 
       
   691         // Check if chunk already logged
       
   692         TInt entryIndex = FindByHandle( entry->Handle(), EMemSpyEngineSysMemTrackerTypeHeapUser ); 
       
   693         exists =  entryIndex != KErrNotFound;
       
   694         SYSMEMTRACKERLOG_PRINTF( RDebug::Printf( "CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsHeapUserL() - heapChunkHandle: 0x%08x, already exists: %d", entry->Handle(), exists ) );
       
   695         if ( exists )
       
   696             {
       
   697             CMemSpyEngineHelperSysMemTrackerEntryHeap& sharedheapEntry = static_cast< CMemSpyEngineHelperSysMemTrackerEntryHeap& >( *iEntries[ entryIndex ] );
       
   698             sharedheapEntry.SetAsShared( ETrue );
       
   699             }
       
   700 
       
   701         // Remove utilised entries
       
   702         if  ( aList )
       
   703             {
       
   704             aList->RemoveByHandle( (TAny*) entry->Handle() );
       
   705             }
       
   706 
       
   707         // Save
       
   708         if  ( !exists )
       
   709             {
       
   710             AddItemAndPopL( entry );
       
   711             }
       
   712         else
       
   713             {
       
   714             CleanupStack::PopAndDestroy( entry );
       
   715             }
       
   716         }
       
   717     }
       
   718 
       
   719 
       
   720 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsHeapKernelL( CMemSpyEngineChunkList& aList )
       
   721     {
       
   722     SYSMEMTRACKERLOG_PRINTF( RDebug::Printf( "CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsHeapKernelL() - START" ) );
       
   723 
       
   724     CMemSpyEngine& engine = Engine();
       
   725     CMemSpyEngineHelperSysMemTrackerEntryHeap* entry = CMemSpyEngineHelperSysMemTrackerEntryHeap::NewKernelLC( iTracker );
       
   726     AddItemAndPopL( entry );
       
   727 
       
   728     // Remove utilised entries
       
   729     aList.RemoveByHandle( (TAny*) entry->Handle() );
       
   730 
       
   731     SYSMEMTRACKERLOG_PRINTF( RDebug::Printf( "CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsHeapKernelL() - END" ) );
       
   732     }
       
   733 
       
   734 
       
   735 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsChunkLocalL( CMemSpyEngineChunkList& aList )
       
   736     {
       
   737     SYSMEMTRACKERLOG_PRINTF( RDebug::Printf( "CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsChunkL() - START" ) );
       
   738 
       
   739     const TInt chunkCount = aList.Count();
       
   740     for( TInt i=chunkCount-1; i>=0; i-- )
       
   741         {
       
   742         const TMemSpyDriverChunkInfo& info = aList.At( i ).Info();
       
   743         SYSMEMTRACKERLOG_PRINTF( RDebug::Print( _L("CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsChunkLocalL() - info[%03d]: type: %d, pid: 0x%04x, size: %d, name: %S"), i, info.iType, info.iOwnerId, info.iSize, &info.iName ) );
       
   744         //
       
   745         if  ( info.iType == EMemSpyDriverChunkTypeLocal )
       
   746             {
       
   747             // Try to find corresponding process
       
   748             const TInt processIndex = Engine().Container().ProcessIndexById( info.iOwnerId );
       
   749             SYSMEMTRACKERLOG_PRINTF( RDebug::Print( _L("CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsChunkLocalL() - processIndex: %d"), processIndex ) );
       
   750             //
       
   751             if  ( processIndex >= 0 )
       
   752                 {
       
   753                 CMemSpyProcess& process = Engine().Container().At( processIndex );
       
   754                 //
       
   755                 TRAP_IGNORE(
       
   756                     CMemSpyEngineHelperSysMemTrackerEntryChunk* entry = CMemSpyEngineHelperSysMemTrackerEntryChunk::NewLC( iTracker, info, process );
       
   757                     AddItemAndPopL( entry );
       
   758                     );
       
   759                 //
       
   760                 aList.Remove( i );
       
   761                 }
       
   762             }
       
   763         }
       
   764 
       
   765     SYSMEMTRACKERLOG_PRINTF( RDebug::Printf( "CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsChunkL() - END" ) );
       
   766     }
       
   767 
       
   768 
       
   769 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsChunkGlobalL( CMemSpyEngineChunkList& aList )
       
   770     {
       
   771     const TInt chunkCount = aList.Count();
       
   772     for( TInt i=chunkCount-1; i>=0; i-- )
       
   773         {
       
   774         const TMemSpyDriverChunkInfo& info = aList.At( i ).Info();
       
   775         if  ( info.iType == EMemSpyDriverChunkTypeGlobal )
       
   776             {
       
   777             if  ( CMemSpyEngineHelperFbServ::IsSharedBitmapChunk( info ) || CMemSpyEngineHelperFbServ::IsLargeBitmapChunk( info ) )
       
   778                 {
       
   779                 // Don't process these two yet, they'll be handled by the bitmap code
       
   780                 }
       
   781             else
       
   782                 {
       
   783                 TRAP_IGNORE(
       
   784                     CMemSpyEngineHelperSysMemTrackerEntryChunk* entry = CMemSpyEngineHelperSysMemTrackerEntryChunk::NewLC( iTracker, info );
       
   785                     AddItemAndPopL( entry );
       
   786                     );
       
   787 
       
   788                 // Remove processed item
       
   789                 aList.Remove( i );
       
   790                 }
       
   791             }
       
   792         }
       
   793     }
       
   794 
       
   795 
       
   796 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemRamDriveL( CMemSpyEngineChunkList& aList )
       
   797     {
       
   798     const TInt chunkCount = aList.Count();
       
   799     for( TInt i=chunkCount-1; i>=0; i-- )
       
   800         {
       
   801         const TMemSpyDriverChunkInfo& info = aList.At( i ).Info();
       
   802         if  ( info.iType == EMemSpyDriverChunkTypeRamDrive )
       
   803             {
       
   804             TRAP_IGNORE(
       
   805                 CMemSpyEngineHelperSysMemTrackerEntryRamDrive* entry = CMemSpyEngineHelperSysMemTrackerEntryRamDrive::NewLC( iTracker, info );
       
   806                 AddItemAndPopL( entry );
       
   807                 );
       
   808 
       
   809             // Remove processed item
       
   810             aList.Remove( i );
       
   811             }
       
   812         }
       
   813     }
       
   814 
       
   815 
       
   816 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsStacksL( CMemSpyEngineChunkList& aList )
       
   817     {
       
   818     CMemSpyEngine& engine = Engine();
       
   819     CMemSpyEngineObjectContainer& container = engine.Container();
       
   820     //
       
   821     const TInt procCount = container.Count();
       
   822     for( TInt p=0; p<procCount; p++ )
       
   823         {
       
   824         CMemSpyProcess& process = container.At( p );
       
   825 
       
   826         // We've now sized the user-mode stacks for the process.
       
   827         // Try to locate the stack/data chunk
       
   828         const TInt index = aList.ItemIndexByProcessId( process.Id(), EMemSpyDriverChunkTypeStackAndProcessGlobalData );
       
   829         if  ( index >= 0 )
       
   830             {
       
   831             const TMemSpyDriverChunkInfo& stackChunkInfo = aList.At( index ).Info();
       
   832             //
       
   833             const TInt threadCount = process.Count();
       
   834             for( TInt t=0; t<threadCount; t++ )
       
   835                 {
       
   836                 CMemSpyThread& thread = process.At( t );
       
   837                 //
       
   838                 if  ( !thread.IsDead() )
       
   839                     {
       
   840                     TRAP_IGNORE( CreateSeedItemsStacksL( thread, stackChunkInfo ) );
       
   841                     }
       
   842                 }
       
   843             }
       
   844         }
       
   845     }
       
   846 
       
   847 
       
   848 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsStacksL( CMemSpyThread& aThread, const TMemSpyDriverChunkInfo& aStackChunkInfo )
       
   849     {
       
   850     RThread rThread;
       
   851     if  ( aThread.Open( rThread ) == KErrNone )
       
   852         {
       
   853         CleanupClosePushL( rThread );
       
   854 
       
   855         TThreadStackInfo stackInfo;
       
   856         if  ( rThread.StackInfo( stackInfo ) == KErrNone )
       
   857             {
       
   858             CMemSpyEngineHelperSysMemTrackerEntryStack* entry = CMemSpyEngineHelperSysMemTrackerEntryStack::NewLC( iTracker, aThread, aStackChunkInfo, stackInfo );
       
   859             AddItemAndPopL( entry );
       
   860             }
       
   861 
       
   862         CleanupStack::PopAndDestroy( &rThread );
       
   863         }
       
   864     }
       
   865 
       
   866 
       
   867 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsGlobalDataL( CMemSpyEngineChunkList& aList )
       
   868     {
       
   869     CMemSpyEngine& engine = Engine();
       
   870     CMemSpyEngineObjectContainer& container = engine.Container();
       
   871     //
       
   872     const TInt chunkCount = aList.Count();
       
   873     for( TInt i=chunkCount-1; i>=0; i-- )
       
   874         {
       
   875         const TMemSpyDriverChunkInfo& info = aList.At( i ).Info();
       
   876 
       
   877         if  ( info.iType == EMemSpyDriverChunkTypeGlobalData || info.iType == EMemSpyDriverChunkTypeStackAndProcessGlobalData )
       
   878             {
       
   879             // Need to get associated process
       
   880             const TInt processIndex = container.ProcessIndexById( info.iOwnerId );
       
   881             if  ( processIndex >= 0 )
       
   882                 {
       
   883                 CMemSpyProcess& process = container.At( processIndex );
       
   884                 //
       
   885                 if  ( info.iType == EMemSpyDriverChunkTypeGlobalData )
       
   886                     {
       
   887                     if ( !( i % 10 ) ) // Print the message on only every 10th cycle
       
   888                         {
       
   889                         RDebug::Print( KMemSpyKeepaliveMessage  );
       
   890                         }
       
   891                     // Pure global data, unique chunk
       
   892                     TRAP_IGNORE( 
       
   893                         CMemSpyEngineHelperSysMemTrackerGlobalData* entry = CMemSpyEngineHelperSysMemTrackerGlobalData::NewLC( iTracker, process, info );
       
   894                         AddItemAndPopL( entry );
       
   895                         );
       
   896 
       
   897                     // Remove processed item
       
   898                     aList.Remove( i );
       
   899                     }
       
   900                 else if ( info.iType == EMemSpyDriverChunkTypeStackAndProcessGlobalData )
       
   901                     {
       
   902                     if ( !( i % 10 ) ) // Print the message on only every 10th cycle
       
   903                         {
       
   904                         RDebug::Print( KMemSpyKeepaliveMessage  );
       
   905                         }
       
   906                     // We don't check uniqueness as any stack entries share a common handle with the process
       
   907                     // global data.
       
   908                     TRAP_IGNORE( 
       
   909                         CMemSpyEngineHelperSysMemTrackerGlobalData* entry = CMemSpyEngineHelperSysMemTrackerGlobalData::NewLC( iTracker, process, info );
       
   910                         AddItemAndPopL( entry );
       
   911                         );
       
   912 
       
   913                     // Remove processed item
       
   914                     aList.Remove( i );
       
   915                     }
       
   916                 }
       
   917             }
       
   918         }
       
   919     }
       
   920 
       
   921 
       
   922 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsCodeL()
       
   923     {
       
   924     CMemSpyEngineCodeSegList* code = Engine().HelperCodeSegment().CodeSegmentListRamLoadedL();
       
   925     CleanupStack::PushL( code );
       
   926     //
       
   927     const TInt count = code->Count();
       
   928     for( TInt i=0; i<count; i++ )
       
   929         {
       
   930         const CMemSpyEngineCodeSegEntry& info = code->At( i );
       
   931         //
       
   932         TRAP_IGNORE( 
       
   933             CMemSpyEngineHelperSysMemTrackerEntryCode* entry = CMemSpyEngineHelperSysMemTrackerEntryCode::NewLC( iTracker, info );
       
   934             AddItemAndPopL( entry );
       
   935             );
       
   936         }
       
   937     //
       
   938     CleanupStack::PopAndDestroy( code );
       
   939     }
       
   940 
       
   941 
       
   942 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsHandlesL()
       
   943     {
       
   944     CMemSpyEngineGenericKernelObjectContainer* allContainers = Engine().HelperKernelContainers().ObjectsAllLightweightL();
       
   945     CleanupStack::PushL( allContainers );
       
   946     //
       
   947     const TInt count = allContainers->Count();
       
   948     for( TInt i=0; i<count; i++ )
       
   949         {
       
   950         const CMemSpyEngineGenericKernelObjectList& list = allContainers->At( i );
       
   951         //
       
   952         const TInt entryCount = list.Count();
       
   953         for( TInt j=0; j<entryCount; j++ )
       
   954             {
       
   955             TAny* handle = list.HandleAt( j );
       
   956             CMemSpyEngineHelperSysMemTrackerEntry* entry = NULL;
       
   957             //
       
   958             TRAP_IGNORE( 
       
   959                 if  ( list.Type() == EMemSpyDriverContainerTypePropertyRef )
       
   960                     {
       
   961                     entry = CMemSpyEngineHelperSysMemTrackerEntryHandlePAndS::NewLC( iTracker, handle );
       
   962                     }
       
   963                 else
       
   964                     {
       
   965                     entry = CMemSpyEngineHelperSysMemTrackerEntryHandleGeneric::NewLC( iTracker, handle, list.Type() );
       
   966                     }
       
   967 
       
   968                 AddItemAndPopL( entry );
       
   969                 );
       
   970             }
       
   971         }
       
   972     //
       
   973     CleanupStack::PopAndDestroy( allContainers );
       
   974     }
       
   975 
       
   976 
       
   977 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsOpenFilesL()
       
   978     {
       
   979     CMemSpyEngineOpenFileList* list = Engine().HelperFileSystem().ListOpenFilesLC();
       
   980     //
       
   981     const TInt threadCount = list->Count();
       
   982     for( TInt t=0; t<threadCount; t++ )
       
   983         {
       
   984         const CMemSpyEngineOpenFileListForThread& thread = list->At( t );
       
   985         //
       
   986         const TInt entryCount = thread.Count();
       
   987         for( TInt e=0; e<entryCount; e++ )
       
   988             {
       
   989             const CMemSpyEngineOpenFileListEntry& fileEntry = thread.At( e );
       
   990             //
       
   991             TRAP_IGNORE( 
       
   992                 CMemSpyEngineHelperSysMemTrackerEntryOpenFile* entry = CMemSpyEngineHelperSysMemTrackerEntryOpenFile::NewLC( iTracker, thread, fileEntry );
       
   993                 AddItemAndPopL( entry );
       
   994                 );
       
   995             }
       
   996         }
       
   997     //
       
   998     CleanupStack::PopAndDestroy( list );
       
   999     }
       
  1000 
       
  1001 
       
  1002 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsDiskSpaceL()
       
  1003     {
       
  1004     TDriveList list;
       
  1005     //
       
  1006     RFs& fsSession = Engine().FsSession();
       
  1007     if  ( fsSession.DriveList( list ) == KErrNone )
       
  1008         {
       
  1009         TDriveInfo info;
       
  1010         //
       
  1011         for( TInt i=0; i<KMaxDrives; i++ )
       
  1012             {
       
  1013             if  ( list[ i ] != KDriveAbsent )
       
  1014                 {
       
  1015                 if  ( fsSession.Drive( info, i ) == KErrNone )
       
  1016                     {
       
  1017                     TRAP_IGNORE( 
       
  1018                         CMemSpyEngineHelperSysMemTrackerEntryDiskSpace* entry = CMemSpyEngineHelperSysMemTrackerEntryDiskSpace::NewLC( iTracker, static_cast<TDriveNumber>( i ) );
       
  1019                         AddItemAndPopL( entry );
       
  1020                         );
       
  1021                     }
       
  1022                 }
       
  1023             }
       
  1024         }
       
  1025     }
       
  1026 
       
  1027 
       
  1028 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsSystemMemoryL()
       
  1029     {
       
  1030     TRAP_IGNORE( 
       
  1031         CMemSpyEngineHelperSysMemTrackerEntrySystemMemory* entryT = CMemSpyEngineHelperSysMemTrackerEntrySystemMemory::NewLC( iTracker, ETypeTotal );
       
  1032         AddItemAndPopL( entryT );
       
  1033         );
       
  1034     TRAP_IGNORE( 
       
  1035         CMemSpyEngineHelperSysMemTrackerEntrySystemMemory* entryF = CMemSpyEngineHelperSysMemTrackerEntrySystemMemory::NewLC( iTracker, ETypeFree );
       
  1036         AddItemAndPopL( entryF );
       
  1037         );
       
  1038     }
       
  1039 
       
  1040 
       
  1041 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsBitmapL( CMemSpyEngineChunkList& aList )
       
  1042     {
       
  1043     TInt bitmapConCount = 0;
       
  1044     TInt fontConCount = 0;
       
  1045     //
       
  1046     RArray<TInt> handles;
       
  1047     CleanupClosePushL( handles );
       
  1048     Engine().HelperFbServ().GetArrayOfBitmapHandlesL( handles, bitmapConCount, fontConCount );
       
  1049     //
       
  1050     const TInt count = handles.Count();
       
  1051     for( TInt i=0; i<count; i++ )
       
  1052         {
       
  1053         const TInt handle = handles[ i ];
       
  1054         //
       
  1055         TRAP_IGNORE( 
       
  1056             CMemSpyEngineHelperSysMemTrackerEntryBitmap* entry = CMemSpyEngineHelperSysMemTrackerEntryBitmap::NewLC( iTracker, handle );
       
  1057             AddItemAndPopL( entry );
       
  1058             );
       
  1059         }
       
  1060     //
       
  1061     CleanupStack::PopAndDestroy( &handles );
       
  1062     
       
  1063     // Make overall fbserv info item
       
  1064     TMemSpyDriverChunkInfo infoChunkLarge;
       
  1065     TMemSpyDriverChunkInfo infoChunkShared;
       
  1066     //
       
  1067     const TInt chunkCount = aList.Count();
       
  1068     for( TInt i=chunkCount-1; i>=0; i-- )
       
  1069         {
       
  1070         const TMemSpyDriverChunkInfo& info = aList.At( i ).Info();
       
  1071         if  ( CMemSpyEngineHelperFbServ::IsSharedBitmapChunk( info ) )
       
  1072             {
       
  1073             SYSMEMTRACKERLOG_PRINTF( RDebug::Printf( "CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsBitmapL() - found FbsSharedChunk..." ) );
       
  1074             infoChunkShared = info;
       
  1075             aList.Remove( i );
       
  1076             }
       
  1077         else if ( CMemSpyEngineHelperFbServ::IsLargeBitmapChunk( info ) )
       
  1078             {
       
  1079             SYSMEMTRACKERLOG_PRINTF( RDebug::Printf( "CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsBitmapL() - found FbsLargeChunk..." ) );
       
  1080             infoChunkLarge = info;
       
  1081             aList.Remove( i );
       
  1082             }
       
  1083         }
       
  1084 
       
  1085     TRAP_IGNORE( 
       
  1086         CMemSpyEngineHelperSysMemTrackerEntryFbserv* entry = CMemSpyEngineHelperSysMemTrackerEntryFbserv::NewLC( iTracker, infoChunkLarge, infoChunkShared, bitmapConCount, fontConCount, count );
       
  1087         AddItemAndPopL( entry );
       
  1088         );
       
  1089     }
       
  1090 
       
  1091 
       
  1092 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsFileServerCacheL( CMemSpyEngineChunkList& aList )
       
  1093     {
       
  1094     TInt index = KErrNotFound;
       
  1095     const CMemSpyEngineChunkEntry* entry = Engine().HelperFileSystem().IdentifyCacheChunk( aList, index );
       
  1096     //
       
  1097     if  ( entry )
       
  1098         {
       
  1099         const TMemSpyDriverChunkInfo& info = entry->Info();
       
  1100         SYSMEMTRACKERLOG_PRINTF( RDebug::Printf( "CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsFileServerCacheL() - found F32 cache chunk..." ) );
       
  1101         //
       
  1102         TRAP_IGNORE( 
       
  1103             CMemSpyEngineHelperSysMemTrackerEntryFileServerCache* entry = CMemSpyEngineHelperSysMemTrackerEntryFileServerCache::NewLC( iTracker, info );
       
  1104             AddItemAndPopL( entry );
       
  1105         );
       
  1106         //
       
  1107         aList.Remove( index );
       
  1108         }
       
  1109     }
       
  1110 
       
  1111 
       
  1112 void CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsWindowServerL()
       
  1113     {
       
  1114     if ( Engine().IsHelperWindowServerSupported() )
       
  1115         {
       
  1116         MMemSpyEngineHelperWindowServer& windowServerManager = Engine().HelperWindowServer();
       
  1117         MMemSpyEngineWindowGroupList* windowGroupList = windowServerManager.WindowGroupListL();
       
  1118         CleanupDeletePushL( windowGroupList );
       
  1119         TInt count = windowGroupList->Count();
       
  1120         TBool isFocused( EFalse );
       
  1121         for ( TInt i = 0; i < count; i++ )
       
  1122             {
       
  1123             TMemSpyEngineWindowGroupDetails windowGroupDetails;
       
  1124             windowServerManager.GetWindowGroupDetailsL( windowGroupList->At( i ).iId, windowGroupDetails );
       
  1125             windowGroupDetails.iOrdinalPosition = windowGroupList->At( i ).iOrdinalPosition;
       
  1126             if ( !isFocused && windowGroupDetails.iPriority == 0 )
       
  1127                 {
       
  1128                 windowGroupDetails.iIsFocused = ETrue;
       
  1129                 isFocused = ETrue;
       
  1130                 }
       
  1131             else
       
  1132                 {
       
  1133                 windowGroupDetails.iIsFocused = EFalse;
       
  1134                 }
       
  1135             TRAP_IGNORE( 
       
  1136                 CMemSpyEngineHelperSysMemTrackerEntryWindowServer* entry = CMemSpyEngineHelperSysMemTrackerEntryWindowServer::NewLC( iTracker, windowGroupDetails );
       
  1137                 AddItemAndPopL( entry );
       
  1138                 );
       
  1139             }
       
  1140         CleanupStack::PopAndDestroy( windowGroupList );
       
  1141         }
       
  1142     else
       
  1143         {
       
  1144         SYSMEMTRACKERLOG_PRINTF( RDebug::Printf( "CMemSpyEngineHelperSysMemTrackerEntryManager::CreateSeedItemsWindowServerL() - Not supported" ) );
       
  1145         }
       
  1146     }
       
  1147 
       
  1148 
       
  1149 
       
  1150