memspyui/ui/avkon/src/MemSpyViewKernelHeap.cpp
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
     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 "MemSpyViewKernelHeap.h"
       
    19 
       
    20 // Engine includes
       
    21 #include <memspy/engine/memspyengine.h>
       
    22 #include <memspy/engine/memspyengineobjectprocess.h>
       
    23 #include <memspy/engine/memspyengineobjectthread.h>
       
    24 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    25 #include <memspy/engine/memspyengineobjectthreadinfoobjects.h>
       
    26 #include <memspy/engine/memspyengineobjectthreadinfocontainer.h>
       
    27 #include <memspy/engine/memspyenginehelperheap.h>
       
    28 #include <memspy/engine/memspyengineoutputlist.h>
       
    29 
       
    30 #include <memspysession.h>
       
    31 #include <memspy/api/memspyapiheap.h>
       
    32 
       
    33 // User includes
       
    34 #include "MemSpyUiUtils.h"
       
    35 #include "MemSpyViewKernel.h"
       
    36 #include "MemSpyContainerObserver.h"
       
    37 
       
    38 // Constants
       
    39 const TInt KMemSpyBufferSize = 20;
       
    40 
       
    41 // Literal constants
       
    42 _LIT(KMemSpyHexFormat, "0x%08x");
       
    43 _LIT(KMemSpyUnsignedFormat, "%u");
       
    44 _LIT(KMemSpyDecFormat, "%d");
       
    45 _LIT(KMemSpyLongFormat, "%Ld");
       
    46 _LIT(KMemSpyCaptionYes, "Yes");
       
    47 _LIT(KMemSpyCaptionNo, "No");
       
    48 
       
    49 
       
    50 CMemSpyViewKernelHeap::CMemSpyViewKernelHeap( RMemSpySession& aSession, MMemSpyViewObserver& aObserver ) //cigasto: remember to uncomment from MMP!
       
    51 :   CMemSpyViewBase( aSession, aObserver )
       
    52     {
       
    53     }
       
    54 
       
    55 CMemSpyViewKernelHeap::~CMemSpyViewKernelHeap()
       
    56     {
       
    57     }
       
    58 
       
    59 
       
    60 void CMemSpyViewKernelHeap::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune )
       
    61     {
       
    62     _LIT( KTitle, "Kernel Heap" );
       
    63     SetTitleL( KTitle );
       
    64     //
       
    65     CMemSpyViewBase::ConstructL( aRect, aContainer, aSelectionRune );
       
    66     }
       
    67 
       
    68 
       
    69 void CMemSpyViewKernelHeap::RefreshL()
       
    70     {
       
    71     SetListBoxModelL();
       
    72     CMemSpyViewBase::RefreshL();
       
    73     }
       
    74 
       
    75 
       
    76 TMemSpyViewType CMemSpyViewKernelHeap::ViewType() const
       
    77     {
       
    78     return EMemSpyViewTypeKernelHeap;
       
    79     }
       
    80 
       
    81 
       
    82 CMemSpyViewBase* CMemSpyViewKernelHeap::PrepareParentViewL()
       
    83     {
       
    84     CMemSpyViewKernel* parent = new(ELeave) CMemSpyViewKernel( iMemSpySession, iObserver );
       
    85     CleanupStack::PushL( parent );
       
    86     parent->ConstructL( Rect(), *Parent(), (TAny*) ViewType() );
       
    87     CleanupStack::Pop( parent );
       
    88     return parent;
       
    89     }
       
    90 
       
    91 
       
    92 CMemSpyViewBase* CMemSpyViewKernelHeap::PrepareChildViewL()
       
    93     {	
       
    94     CMemSpyViewBase* child = NULL;
       
    95     return child;    
       
    96     }
       
    97 
       
    98 
       
    99 void CMemSpyViewKernelHeap::SetListBoxModelL()
       
   100     {	
       
   101 	CMemSpyApiHeap* iHeap;
       
   102 	iHeap = iMemSpySession.GetHeap( );
       
   103 		
       
   104 	CDesCArrayFlat* model = new (ELeave) CDesC16ArrayFlat( 22 );
       
   105 		
       
   106 	model = FormatModel( iHeap );	
       
   107 				
       
   108 	CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox );
       
   109 	listbox->Model()->SetItemTextArray( model );
       
   110 	listbox->Model()->SetOwnershipType( ELbmOwnsItemArray );			
       
   111 	}
       
   112 
       
   113 
       
   114 TBool CMemSpyViewKernelHeap::HandleCommandL( TInt aCommand )
       
   115     {
       
   116     TBool handled = ETrue;
       
   117     //
       
   118     switch ( aCommand )
       
   119         {
       
   120     case EMemSpyCmdKernelHeapDump:
       
   121         OnCmdDumpKernelHeapL();
       
   122         break;
       
   123 
       
   124     default:
       
   125         handled = CMemSpyViewBase::HandleCommandL( aCommand );
       
   126         break;
       
   127         }
       
   128     //
       
   129     return handled;
       
   130     }
       
   131 
       
   132 
       
   133 void CMemSpyViewKernelHeap::OnCmdDumpKernelHeapL()
       
   134     {	
       
   135     iMemSpySession.DumpKernelHeap();
       
   136     }
       
   137 
       
   138 
       
   139 //CDesCArrayFlat* CMemSpyViewKernelHeap::FormatModel( RArray<CMemSpyApiHeap*> &aHeap )
       
   140 CDesCArrayFlat* CMemSpyViewKernelHeap::FormatModel( CMemSpyApiHeap* aHeap )
       
   141 	{
       
   142 	CDesCArrayFlat* ret = new (ELeave) CDesC16ArrayFlat( 2 );
       
   143 	
       
   144 	 _LIT( KItem0, "Heap type" );		   	  
       
   145 	 _LIT( KItem1, "Heap size" );	  
       
   146 	 _LIT( KItem8b, "Heap base address" );	        	       
       
   147 	 _LIT( KItem1b, "Shared" );	        
       
   148 	 _LIT( KItem2, "Chunk size" );
       
   149 	 _LIT( KItem3, "Alloc. count" );
       
   150 	 _LIT( KItem4, "Free. count" );
       
   151 	 _LIT( KItem5, "Biggest alloc." );
       
   152 	 _LIT( KItem6, "Biggest free" );
       
   153 	 _LIT( KItem6a, "Total alloc." );
       
   154 	 _LIT( KItem6b, "Total free" );
       
   155 	 _LIT( KItem7, "Slack free space" );
       
   156 	 _LIT( KItem8a, "Fragmentation" );
       
   157 	 _LIT( KItem13, "Header size (A)" );
       
   158 	 _LIT( KItem14, "Header size (F)" );
       
   159 	 _LIT( KItem9a, "Overhead (alloc)" );
       
   160 	 _LIT( KItem9b, "Overhead (free)" );
       
   161 	 _LIT( KItem9c, "Overhead (total)" );
       
   162 	 _LIT( KItem9d, "Overhead" );
       
   163 	 _LIT( KItem10, "Min. length" );
       
   164 	 _LIT( KItem11, "Max. length" );
       
   165 	 _LIT( KItem12, "Debug Allocator Library" );
       
   166 	 
       
   167 	HBufC* iItem = HBufC::NewL( KMaxName );	
       
   168 	
       
   169 	iItem = FormatItem( KItem0, aHeap->Type() );
       
   170 	TPtr pItem( iItem->Des() );
       
   171 	ret->AppendL( pItem );
       
   172 	pItem.Zero();	
       
   173 	
       
   174 	iItem = FormatItem( KItem1, aHeap->Size() );
       
   175 	pItem = iItem->Des();
       
   176 	ret->AppendL( pItem );
       
   177 	pItem.Zero();	
       
   178 	
       
   179 	TUint address( aHeap->BaseAddress() );	
       
   180 	iItem = FormatItem( KItem8b, address );
       
   181 	pItem = iItem->Des();
       
   182 	ret->AppendL( pItem );
       
   183 	pItem.Zero();
       
   184 	
       
   185 	if(aHeap->Shared()) //Yes / No value formatting		
       
   186 		iItem = FormatItem( KItem1b, KMemSpyCaptionYes );		
       
   187 	else		
       
   188 		iItem = FormatItem( KItem1b, KMemSpyCaptionNo );	
       
   189 	pItem = iItem->Des();
       
   190 	ret->AppendL( pItem );
       
   191 	pItem.Zero();
       
   192 	
       
   193 	iItem = FormatItem( KItem2, aHeap->ChunkSize() );
       
   194 	pItem = iItem->Des();
       
   195 	ret->AppendL( pItem );
       
   196 	pItem.Zero();
       
   197 	
       
   198 	iItem = FormatItem( KItem3, aHeap->AllocationsCount() );
       
   199 	pItem = iItem->Des();
       
   200 	ret->AppendL( pItem );
       
   201 	pItem.Zero();
       
   202 	
       
   203 	iItem = FormatItem( KItem4, aHeap->FreeCount() );
       
   204 	pItem = iItem->Des();
       
   205 	ret->AppendL( pItem );
       
   206 	pItem.Zero();
       
   207 	
       
   208 	iItem = FormatItem( KItem5, aHeap->BiggestAllocation() );
       
   209 	pItem = iItem->Des();
       
   210 	ret->AppendL( pItem );
       
   211 	pItem.Zero();
       
   212 	
       
   213 	iItem = FormatItem( KItem6, aHeap->BiggestFree() );
       
   214 	pItem = iItem->Des();
       
   215 	ret->AppendL( pItem );
       
   216 	pItem.Zero();
       
   217 	
       
   218 	iItem = FormatItem( KItem6a, aHeap->TotalAllocations() );
       
   219 	pItem = iItem->Des();
       
   220 	ret->AppendL( pItem );
       
   221 	pItem.Zero();
       
   222 	
       
   223 	iItem = FormatItem( KItem6b, aHeap->TotalFree() );
       
   224 	pItem = iItem->Des();
       
   225 	ret->AppendL( pItem );
       
   226 	pItem.Zero();
       
   227 	
       
   228 	iItem = FormatItem( KItem7, aHeap->SlackFreeSpace() );
       
   229 	pItem = iItem->Des();
       
   230 	ret->AppendL( pItem );
       
   231 	pItem.Zero();
       
   232 	
       
   233 	TReal iOneHundred( aHeap->Size() );
       
   234 	TReal iValue( aHeap->Fragmentation() );	
       
   235 	iItem = FormatPercentageItem( KItem8a, iOneHundred, iValue );
       
   236 	pItem = iItem->Des();
       
   237 	ret->AppendL( pItem );
       
   238 	pItem.Zero();
       
   239 	
       
   240 	iItem = FormatItem( KItem13, aHeap->HeaderSizeA() );
       
   241 	pItem = iItem->Des();
       
   242 	ret->AppendL( pItem );
       
   243 	pItem.Zero();
       
   244 	
       
   245 	iItem = FormatItem( KItem14, aHeap->HeaderSizeF() );
       
   246 	pItem = iItem->Des();
       
   247 	ret->AppendL( pItem );
       
   248 	pItem.Zero();
       
   249 	
       
   250 	iItem = FormatItem( KItem9a, aHeap->AllocationOverhead() );
       
   251 	pItem = iItem->Des();
       
   252 	ret->AppendL( pItem );
       
   253 	pItem.Zero();
       
   254 	
       
   255 	iItem = FormatItem( KItem9b, aHeap->FreeOverhead() );
       
   256 	pItem = iItem->Des();
       
   257 	ret->AppendL( pItem );
       
   258 	pItem.Zero();
       
   259 	
       
   260 	iItem = FormatItem( KItem9c, aHeap->TotalOverhead() );
       
   261 	pItem = iItem->Des();
       
   262 	ret->AppendL( pItem );
       
   263 	pItem.Zero();
       
   264 	
       
   265 	TReal iOverhead( aHeap->Overhead() );	
       
   266 	iItem = FormatPercentageItem( KItem9d, iOneHundred, iOverhead );	
       
   267 	pItem = iItem->Des();
       
   268 	ret->AppendL( pItem );
       
   269 	pItem.Zero();
       
   270 	
       
   271 	iItem = FormatItem( KItem10, aHeap->MinLength() );
       
   272 	pItem = iItem->Des();
       
   273 	ret->AppendL( pItem );
       
   274 	pItem.Zero();
       
   275 		
       
   276 	iItem = FormatItem( KItem11, aHeap->MaxLength() );
       
   277 	pItem = iItem->Des();
       
   278 	ret->AppendL( pItem );
       
   279 	pItem.Zero();
       
   280 	
       
   281 	if( aHeap->DebugAllocatorLibrary() )		
       
   282 		iItem = FormatItem( KItem12, KMemSpyCaptionYes );		
       
   283 	else
       
   284 		iItem = FormatItem( KItem12, KMemSpyCaptionNo );	
       
   285 	pItem = iItem->Des();
       
   286 	ret->AppendL( pItem );
       
   287 	pItem.Zero();
       
   288 	
       
   289 	return ret;
       
   290 	}
       
   291 
       
   292 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, const TDesC& aValue )
       
   293 	{
       
   294 	HBufC* retBuf = HBufC::NewL( KMaxName );
       
   295 	TPtr pRetBuf( retBuf->Des() );
       
   296 	pRetBuf.Zero();
       
   297 	pRetBuf.Append( _L("\t") );
       
   298 	pRetBuf.Append( aCaption );
       
   299 	pRetBuf.Append( _L("\t\t") );
       
   300 	pRetBuf.Append( aValue );
       
   301 	return retBuf;
       
   302 	}
       
   303 
       
   304 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TInt aValue )
       
   305 	{
       
   306 	HBufC* retBuf = HBufC::NewL( KMaxName );
       
   307 	TPtr pRetBuf( retBuf->Des() );
       
   308 	pRetBuf.Zero();
       
   309     
       
   310 	TBuf<KMemSpyBufferSize> val;
       
   311     val.Format( KMemSpyDecFormat, aValue );
       
   312     
       
   313     pRetBuf.Append( _L("\t") );
       
   314     pRetBuf.Append( aCaption );
       
   315     pRetBuf.Append( _L("\t\t") );
       
   316     pRetBuf.Append( val );    
       
   317 	
       
   318 	return retBuf;
       
   319 	}
       
   320 
       
   321 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TUint aValue )
       
   322 	{
       
   323 	HBufC* retBuf = HBufC::NewL( KMaxName );
       
   324 	TPtr pRetBuf( retBuf->Des() );
       
   325 	pRetBuf.Zero();
       
   326     
       
   327 	TBuf<KMemSpyBufferSize> val;
       
   328     //val.Format( KMemSpyDecFormat, aValue );
       
   329 	val.Format( KMemSpyHexFormat, aValue );
       
   330     
       
   331     pRetBuf.Append( _L("\t") );
       
   332     pRetBuf.Append( aCaption );
       
   333     pRetBuf.Append( _L("\t\t") );
       
   334     pRetBuf.Append( val );    
       
   335 	
       
   336 	return retBuf;	
       
   337 	}
       
   338 
       
   339 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, const TInt64& aValue )
       
   340 	{
       
   341 	HBufC* retBuf = HBufC::NewL( KMaxName );
       
   342 	TPtr pRetBuf( retBuf->Des() );
       
   343 	pRetBuf.Zero();
       
   344 	    
       
   345 	TBuf<KMemSpyBufferSize> val;
       
   346 	val.Format( KMemSpyLongFormat, aValue );
       
   347 	    
       
   348 	pRetBuf.Append( _L("\t") );
       
   349 	pRetBuf.Append( aCaption );
       
   350 	pRetBuf.Append( _L("\t\t") );
       
   351 	pRetBuf.Append( val );    
       
   352 		
       
   353 	return retBuf;	
       
   354 	}
       
   355 
       
   356 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TAny* aValue )
       
   357 	{
       
   358 	HBufC* retBuf = HBufC::NewL( KMaxName );
       
   359 	TPtr pRetBuf( retBuf->Des() );
       
   360 	pRetBuf.Zero();
       
   361 		    
       
   362 	TBuf<KMemSpyBufferSize> val;
       
   363 	val.Format( KMemSpyHexFormat, aValue );
       
   364 		    
       
   365 	pRetBuf.Append( _L("\t") );
       
   366 	pRetBuf.Append( aCaption );
       
   367 	pRetBuf.Append( _L("\t\t") );
       
   368 	pRetBuf.Append( val );    
       
   369 			
       
   370 	return retBuf;	
       
   371 	}
       
   372 
       
   373 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TUint* aValue )
       
   374 	{
       
   375 	HBufC* retBuf = HBufC::NewL( KMaxName );
       
   376 	TPtr pRetBuf( retBuf->Des() );
       
   377 	pRetBuf.Zero();
       
   378 		    
       
   379 	TBuf<KMemSpyBufferSize> val;
       
   380 	val.Format( KMemSpyHexFormat, aValue );
       
   381 		    
       
   382 	pRetBuf.Append( _L("\t") );
       
   383 	pRetBuf.Append( aCaption );
       
   384 	pRetBuf.Append( _L("\t\t") );
       
   385 	pRetBuf.Append( val );    
       
   386 			
       
   387 	return retBuf;	
       
   388 	}
       
   389 
       
   390 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TUint8* aValue )
       
   391 	{
       
   392 	HBufC* retBuf = HBufC::NewL( KMaxName );
       
   393 	TPtr pRetBuf( retBuf->Des() );
       
   394 	pRetBuf.Zero();
       
   395 		    
       
   396 	TBuf<KMemSpyBufferSize> val;
       
   397 	val.Format( KMemSpyHexFormat, aValue );
       
   398 		    
       
   399 	pRetBuf.Append( _L("\t") );
       
   400 	pRetBuf.Append( aCaption );
       
   401 	pRetBuf.Append( _L("\t\t") );
       
   402 	pRetBuf.Append( val );    
       
   403 			
       
   404 	return retBuf;	
       
   405 	}
       
   406 
       
   407 HBufC* CMemSpyViewKernelHeap::FormatPercentageItem( const TDesC& aCaption, TReal aOneHundredPercentValue, TReal aValue )
       
   408 	{
       
   409 	HBufC* retBuf = HBufC::NewL( KMaxName );	//buffer for formatted item
       
   410 	TPtr pRetBuf( retBuf->Des() );
       
   411 	pRetBuf.Zero();
       
   412 	
       
   413     const TReal value = (TInt) (( aValue / aOneHundredPercentValue) * 100.0); // percentage value calculation    
       
   414     _LIT(KPercentFormat, "%3.2f %%");
       
   415     TMemSpyPercentText val;
       
   416     val.Format( KPercentFormat, value );
       
   417     
       
   418 	pRetBuf.Append( _L("\t") );
       
   419 	pRetBuf.Append( aCaption );
       
   420 	pRetBuf.Append( _L("\t\t") );
       
   421 	pRetBuf.Append( val );    
       
   422 			
       
   423 	return retBuf;
       
   424 	}