memspyui/ui/avkon/src/MemSpyViewHeapTracking.cpp
branchRCL_3
changeset 19 b3cee849fa46
equal deleted inserted replaced
18:48060abbbeaf 19:b3cee849fa46
       
     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 "MemSpyViewHeapTracking.h"
       
    19 
       
    20 // System includes
       
    21 #include <hal.h>
       
    22 
       
    23 // Engine includes
       
    24 #include <memspy/engine/memspyengine.h>
       
    25 #include <memspy/engine/memspyengineobjectprocess.h>
       
    26 #include <memspy/engine/memspyengineobjectthread.h>
       
    27 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    28 #include <memspy/engine/memspyengineobjectthreadinfoobjects.h>
       
    29 #include <memspy/engine/memspyengineobjectthreadinfocontainer.h>
       
    30 #include <memspy/engine/memspyenginehelpersysmemtracker.h>
       
    31 
       
    32 // User includes
       
    33 #include "MemSpyUiUtils.h"
       
    34 #include "MemSpyViewMainMenu.h"
       
    35 #include "MemSpyContainerObserver.h"
       
    36 #include "MemSpyViewHeapTrackingSettings.h"
       
    37 #include "MemSpyViewHeapTrackingResults.h"
       
    38 
       
    39 
       
    40 CMemSpyViewHeapTracking::CMemSpyViewHeapTracking( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver )
       
    41 :   CMemSpyViewBase( aEngine, aObserver ),
       
    42     iState( EMemSpyViewHeapTrackingStateIdle )
       
    43     {
       
    44     if ( iEngine.HelperSysMemTracker().IsActive() )
       
    45         {
       
    46         iState = EMemSpyViewHeapTrackingStateTimerOn;
       
    47         }
       
    48     }
       
    49 
       
    50 
       
    51 CMemSpyViewHeapTracking::~CMemSpyViewHeapTracking()
       
    52     {
       
    53     delete iStopTimerCallBack;
       
    54     iEngine.HelperSysMemTracker().RemoveObserver( this );
       
    55     }
       
    56 
       
    57 
       
    58 void CMemSpyViewHeapTracking::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune )
       
    59     {
       
    60     _LIT( KTitle, "System-Wide Memory Tracking" );
       
    61     SetTitleL( KTitle );
       
    62     //
       
    63     CMemSpyViewBase::ConstructL( aRect, aContainer, aSelectionRune );
       
    64     
       
    65     // Backup current config because it may be overwritten with Basic/Full mode settings.
       
    66     CMemSpyEngineHelperSysMemTracker& swmt = iEngine.HelperSysMemTracker();
       
    67     TMemSpyEngineHelperSysMemTrackerConfig config;
       
    68     swmt.GetConfig( config );
       
    69     iOriginalConfig = config;
       
    70     
       
    71     if ( config.iMode != TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeCustom )
       
    72         {
       
    73         // Set config. Needed for updating config for Basic or Full mode.
       
    74         SetConfigByModeL( config.iMode, config );        
       
    75         }
       
    76         
       
    77     // Make sure the correct item is selected
       
    78     TInt index = 0;
       
    79     if  ( aSelectionRune != NULL )
       
    80         {
       
    81         const TMemSpyViewType viewType = (TMemSpyViewType) ((TInt) aSelectionRune);
       
    82         index = IndexByViewType( viewType );
       
    83         }
       
    84     iListBox->SetCurrentItemIndex( index );
       
    85     HandleListBoxItemSelectedL( index );
       
    86     }
       
    87 
       
    88 
       
    89 void CMemSpyViewHeapTracking::RefreshL()
       
    90     {
       
    91     SetListBoxModelL();
       
    92     CMemSpyViewBase::RefreshL();
       
    93     }
       
    94 
       
    95 
       
    96 TMemSpyViewType CMemSpyViewHeapTracking::ViewType() const
       
    97     {
       
    98     return EMemSpyViewTypeHeapTracking;
       
    99     }
       
   100 
       
   101 
       
   102 CMemSpyViewBase* CMemSpyViewHeapTracking::PrepareParentViewL()
       
   103     {
       
   104     
       
   105     // Save custom settings even if mode is Basic or Full
       
   106     TRAP_IGNORE(
       
   107         CMemSpyEngineHelperSysMemTracker& swmt = iEngine.HelperSysMemTracker();
       
   108         TMemSpyEngineHelperSysMemTrackerConfig config;
       
   109         swmt.GetConfig( config );
       
   110         config.iEnabledCategories = iOriginalConfig.iEnabledCategories;
       
   111         config.iThreadNameFilter = iOriginalConfig.iThreadNameFilter;
       
   112         config.iDumpData = iOriginalConfig.iDumpData;
       
   113         swmt.SetConfigL( config );
       
   114         Settings().StoreSettingsL();
       
   115         );
       
   116     
       
   117     CMemSpyViewMainMenu* parent = new(ELeave) CMemSpyViewMainMenu( iEngine, iObserver );
       
   118     CleanupStack::PushL( parent );
       
   119     parent->ConstructL( Rect(), *Parent(), (TAny*) ViewType() );
       
   120     CleanupStack::Pop( parent );
       
   121     return parent;
       
   122     }
       
   123 
       
   124 
       
   125 CMemSpyViewBase* CMemSpyViewHeapTracking::PrepareChildViewL()
       
   126     {
       
   127     CMemSpyViewBase* child = NULL;
       
   128     const TInt index = iListBox->CurrentItemIndex();
       
   129     
       
   130     // Get current config
       
   131     CMemSpyEngineHelperSysMemTracker& swmt = iEngine.HelperSysMemTracker();
       
   132     TMemSpyEngineHelperSysMemTrackerConfig config;
       
   133     swmt.GetConfig( config );
       
   134     
       
   135     //
       
   136     if  ( index == 0 )
       
   137         {
       
   138         // This is the start/stop toggle so we don't make a child view
       
   139         child = NULL; 
       
   140 
       
   141         // ... instead we either start or stop the tracker
       
   142         if  ( !iEngine.HelperSysMemTracker().IsActive() )
       
   143             {
       
   144             iState = EMemSpyViewHeapTrackingStateSingleOn;
       
   145             // Setting observer to be able to stop SWMT after first cycle is completed
       
   146             iEngine.HelperSysMemTracker().SetObserver( this );
       
   147             iEngine.HelperSysMemTracker().StartL();
       
   148             }
       
   149 
       
   150         // Redraw listbox 
       
   151         RefreshL();
       
   152         }
       
   153     else if  ( index == 1 )
       
   154         {
       
   155         // This is the start/stop toggle so we don't make a child view
       
   156         child = NULL; 
       
   157 
       
   158         // ... instead we either start or stop the tracker
       
   159         if  ( iEngine.HelperSysMemTracker().IsActive() && iState == EMemSpyViewHeapTrackingStateTimerOn )
       
   160             {
       
   161             iState = EMemSpyViewHeapTrackingStateIdle;
       
   162             iEngine.HelperSysMemTracker().StopL();
       
   163             }
       
   164         else if ( iState == EMemSpyViewHeapTrackingStateIdle )
       
   165             {
       
   166             iState = EMemSpyViewHeapTrackingStateTimerOn;
       
   167             iEngine.HelperSysMemTracker().StartL();
       
   168             }
       
   169 
       
   170         // Redraw listbox 
       
   171         RefreshL();
       
   172         }
       
   173     else if ( index == 2 )
       
   174         {
       
   175         switch ( config.iMode )
       
   176             {
       
   177             case TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeBasic:
       
   178                 {
       
   179                 // Set Full mode
       
   180                 SetConfigByModeL( TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeFull, config );
       
   181                 break;
       
   182                 }
       
   183             case TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeFull:
       
   184                 {
       
   185                 // Set Custom mode
       
   186                 SetConfigByModeL( TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeCustom, config );
       
   187                 break;
       
   188                 }
       
   189             case TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeCustom:
       
   190                 {
       
   191                 // Set Basic mode
       
   192                 SetConfigByModeL( TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeBasic, config );
       
   193                 break;
       
   194                 }
       
   195             default: break;
       
   196             }
       
   197                 
       
   198         // Redraw listbox 
       
   199         RefreshL();
       
   200         }
       
   201     else if ( index == 3 )
       
   202         {        
       
   203         if ( config.iMode == TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeCustom )
       
   204             {
       
   205             child = new(ELeave) CMemSpyViewHeapTrackingSettings( iEngine, iObserver );
       
   206             }
       
   207         else
       
   208             {
       
   209             child = new(ELeave) CMemSpyViewHeapTrackingResults( iEngine, iObserver );
       
   210             }
       
   211         }
       
   212     else if ( index == 4 )
       
   213         {
       
   214         child = new(ELeave) CMemSpyViewHeapTrackingResults( iEngine, iObserver );
       
   215         }
       
   216     if  ( child )
       
   217         {
       
   218         CleanupStack::PushL( child );
       
   219         child->ConstructL( Rect(), *Parent() );
       
   220         CleanupStack::Pop( child );
       
   221         }
       
   222     
       
   223     //
       
   224     return child;
       
   225     }
       
   226 
       
   227 
       
   228 void CMemSpyViewHeapTracking::SetListBoxModelL()
       
   229     {
       
   230     CDesCArrayFlat* model = new(ELeave) CDesCArrayFlat(5);
       
   231     CleanupStack::PushL( model );
       
   232 
       
   233     TBuf<KMaxFullName + 1> item;
       
   234     
       
   235     // Get current config
       
   236     CMemSpyEngineHelperSysMemTracker& swmt = iEngine.HelperSysMemTracker();
       
   237     TMemSpyEngineHelperSysMemTrackerConfig config;
       
   238     swmt.GetConfig( config );
       
   239 
       
   240     // 1st item
       
   241     _LIT( KItem1FormatEnable, "\tGet dump now" );
       
   242     model->AppendL( KItem1FormatEnable );
       
   243 
       
   244     
       
   245     // 1st item
       
   246     if  ( iEngine.HelperSysMemTracker().IsActive() && iState == EMemSpyViewHeapTrackingStateTimerOn )
       
   247         {
       
   248         _LIT( KItem1FormatEnable, "\tStop timer\t\t%d (sec)" );
       
   249         TName item;
       
   250         item.Format( KItem1FormatEnable, config.iTimerPeriod.Int() / 1000000 );
       
   251         model->AppendL( item );
       
   252         }
       
   253     else
       
   254         {
       
   255         _LIT( KItem1FormatEnable, "\tStart timer\t\t%d (sec)" );
       
   256         TName item;
       
   257         item.Format( KItem1FormatEnable, config.iTimerPeriod.Int() / 1000000 );
       
   258         model->AppendL( item );
       
   259         }
       
   260     
       
   261     // 2nd item
       
   262     switch ( config.iMode )
       
   263         {
       
   264         case TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeBasic:
       
   265             {
       
   266             _LIT( KItem2Format, "\tTracking mode\t\tBasic" );
       
   267             model->AppendL( KItem2Format );        
       
   268             break;
       
   269             }
       
   270         case TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeFull:
       
   271             {
       
   272             _LIT( KItem2Format, "\tTracking mode\t\tFull" );
       
   273             model->AppendL( KItem2Format );        
       
   274             break;
       
   275             }
       
   276         case TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeCustom:
       
   277             {
       
   278             _LIT( KItem2Format, "\tTracking mode\t\tCustom" );
       
   279             model->AppendL( KItem2Format );
       
   280             
       
   281             // 3rd item
       
   282             TFullName item;
       
   283             if ( config.DumpData() && 
       
   284                 config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserHeap )
       
   285                 {
       
   286                 _LIT( KItem3Format, "\tSettings\t\t%d categ., dump" );
       
   287                 item.Format( KItem3Format, config.EnabledCategoryCount() );
       
   288                 }
       
   289             else
       
   290                 {
       
   291                 _LIT( KItem3Format, "\tSettings\t\t%d categories" );
       
   292                 item.Format( KItem3Format, config.EnabledCategoryCount() );
       
   293                 }
       
   294             model->AppendL( item );            
       
   295             break;
       
   296             }
       
   297         default: break;
       
   298         }
       
   299     
       
   300     // 4th item    
       
   301     const TInt cycleCount = iEngine.HelperSysMemTracker().MdcaCount();
       
   302     if ( cycleCount )
       
   303         {
       
   304         _LIT( KItem2Format, "\tResults\t\t%d cycles" );
       
   305         TFullName item;
       
   306         item.Format( KItem2Format, cycleCount );
       
   307         model->AppendL( item );
       
   308         }
       
   309     else
       
   310         {
       
   311         _LIT( KItem2Format, "\tResults\t\tNo results" );
       
   312         model->AppendL( KItem2Format );
       
   313         }
       
   314 
       
   315     // Set up list box
       
   316     CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox );
       
   317     listbox->Model()->SetItemTextArray( model );
       
   318     listbox->Model()->SetOwnershipType( ELbmOwnsItemArray );
       
   319     CleanupStack::Pop( model );
       
   320     }
       
   321 
       
   322 
       
   323 void CMemSpyViewHeapTracking::HandleCyclesResetL()
       
   324     {
       
   325     }
       
   326 
       
   327 
       
   328 void CMemSpyViewHeapTracking::HandleCycleStartedL( const CMemSpyEngineHelperSysMemTrackerCycle& /*aCycle*/ )
       
   329     {
       
   330     }
       
   331 
       
   332 
       
   333 void CMemSpyViewHeapTracking::HandleCycleFinishedL( const CMemSpyEngineHelperSysMemTrackerCycle& /*aCycle*/ )
       
   334     {
       
   335     // Stopping SWMT does not work directly from this function.
       
   336     // It has to be made asynchronously.
       
   337     iStopTimerCallBack = new (ELeave) CAsyncCallBack( TCallBack( CMemSpyViewHeapTracking::AsyncStopTimerCallback, this ), CActive::EPriorityStandard );
       
   338     iStopTimerCallBack->CallBack();
       
   339     }
       
   340 
       
   341 
       
   342 TInt CMemSpyViewHeapTracking::IndexByViewType( TMemSpyViewType aType )
       
   343     {
       
   344     // Get current config
       
   345     CMemSpyEngineHelperSysMemTracker& swmt = iEngine.HelperSysMemTracker();
       
   346     TMemSpyEngineHelperSysMemTrackerConfig config;
       
   347     swmt.GetConfig( config );
       
   348     
       
   349     TInt index = 0;
       
   350     //
       
   351     switch( aType )
       
   352         {
       
   353     default:
       
   354     case EMemSpyViewTypeHeapTrackingResults:
       
   355         {
       
   356         if ( config.iMode == TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeCustom )
       
   357             {
       
   358             index = 4;
       
   359             }
       
   360         else
       
   361             {
       
   362             index = 3;
       
   363             }
       
   364         break;
       
   365         }
       
   366     case EMemSpyViewTypeHeapTrackingSettings:
       
   367         index = 3;
       
   368         break;
       
   369         }
       
   370     //
       
   371     return index;
       
   372     }
       
   373 
       
   374 
       
   375 void CMemSpyViewHeapTracking::SetConfigByModeL( TMemSpyEngineHelperSysMemTrackerConfig::TMemSpyEngineSysMemTrackerMode aMode, TMemSpyEngineHelperSysMemTrackerConfig& aConfig )
       
   376     {
       
   377     switch ( aMode )
       
   378         {
       
   379         case TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeBasic:
       
   380             {
       
   381             aConfig.iMode = aMode;
       
   382             aConfig.iEnabledCategories = TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserHeap |
       
   383                                          TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserStacks |
       
   384                                          TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryGlobalData |
       
   385                                          TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategorySystemMemory;
       
   386             aConfig.iDumpData = EFalse;
       
   387             break;
       
   388             }
       
   389         case TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeFull:
       
   390             {
       
   391             aConfig.iMode = aMode;
       
   392             aConfig.iEnabledCategories = TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryAll;
       
   393             aConfig.iDumpData = ETrue;
       
   394             aConfig.iThreadNameFilter = KNullDesC;
       
   395             break;
       
   396             }
       
   397         case TMemSpyEngineHelperSysMemTrackerConfig::MemSpyEngineSysMemTrackerModeCustom:
       
   398             {
       
   399             aConfig.iMode = aMode;
       
   400             aConfig.iEnabledCategories = iOriginalConfig.iEnabledCategories;
       
   401             aConfig.iDumpData = iOriginalConfig.iDumpData;
       
   402             aConfig.iThreadNameFilter = iOriginalConfig.iThreadNameFilter;
       
   403             break;
       
   404             }
       
   405         default: User::Leave( KErrArgument );
       
   406         }
       
   407     // Push changes to SWMT
       
   408     CMemSpyEngineHelperSysMemTracker& swmt = iEngine.HelperSysMemTracker();
       
   409     swmt.SetConfigL( aConfig );
       
   410     Settings().StoreSettingsL();
       
   411     }
       
   412 
       
   413 
       
   414 TInt CMemSpyViewHeapTracking::AsyncStopTimerCallback( TAny* aParam )
       
   415     {
       
   416     CMemSpyViewHeapTracking* view = static_cast<CMemSpyViewHeapTracking*>( aParam );
       
   417     return view->AsyncStopTimerCallback();
       
   418     }
       
   419 
       
   420 
       
   421 TInt CMemSpyViewHeapTracking::AsyncStopTimerCallback()
       
   422     {
       
   423     iState = EMemSpyViewHeapTrackingStateIdle;
       
   424     iEngine.HelperSysMemTracker().RemoveObserver( this );
       
   425     TRAP_IGNORE(
       
   426         iEngine.HelperSysMemTracker().StopL();
       
   427         RefreshL();
       
   428         );
       
   429     delete iStopTimerCallBack;
       
   430     iStopTimerCallBack = NULL;
       
   431     return KErrNone;
       
   432     }
       
   433 
       
   434 
       
   435