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