memspyui/ui/avkon/src/MemSpyViewKernelHeap.cpp
changeset 17 4f2773374eff
child 19 4b22a598b890
equal deleted inserted replaced
15:e11368ed4880 17:4f2773374eff
       
     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 ); //array for formated items TODO: to remove constant
       
   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 	// Get list contents
       
   114 	TMemSpyHeapInfo heapInfo;
       
   115 	iEngine.HelperHeap().GetHeapInfoKernelL( heapInfo );
       
   116 	CMemSpyEngineOutputList* list = iEngine.HelperHeap().NewHeapSummaryShortLC( heapInfo );
       
   117 
       
   118 	// Set up list box
       
   119 	CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox );
       
   120 	listbox->Model()->SetItemTextArray( list );
       
   121 	listbox->Model()->SetOwnershipType( ELbmOwnsItemArray );
       
   122 	CleanupStack::Pop( list );
       
   123 	*/
       
   124 	}
       
   125 
       
   126 
       
   127 TBool CMemSpyViewKernelHeap::HandleCommandL( TInt aCommand )
       
   128     {
       
   129     TBool handled = ETrue;
       
   130     //
       
   131     switch ( aCommand )
       
   132         {
       
   133     case EMemSpyCmdKernelHeapDump:
       
   134         OnCmdDumpKernelHeapL();
       
   135         break;
       
   136 
       
   137     default:
       
   138         handled = CMemSpyViewBase::HandleCommandL( aCommand );
       
   139         break;
       
   140         }
       
   141     //
       
   142     return handled;
       
   143     }
       
   144 
       
   145 
       
   146 void CMemSpyViewKernelHeap::OnCmdDumpKernelHeapL()
       
   147     {
       
   148 	// TODO
       
   149     //iEngine.HelperHeap().OutputHeapDataKernelL();
       
   150     }
       
   151 
       
   152 
       
   153 //CDesCArrayFlat* CMemSpyViewKernelHeap::FormatModel( RArray<CMemSpyApiHeap*> &aHeap )
       
   154 CDesCArrayFlat* CMemSpyViewKernelHeap::FormatModel( CMemSpyApiHeap* aHeap )
       
   155 	{
       
   156 	CDesCArrayFlat* ret = new (ELeave) CDesC16ArrayFlat( 2 );
       
   157 	
       
   158 	 _LIT( KItem0, "Heap type" );		   	  
       
   159 	 _LIT( KItem1, "Heap size" );	  
       
   160 	 _LIT( KItem8b, "Heap base address" );	        	       
       
   161 	 _LIT( KItem1b, "Shared" );	        
       
   162 	 _LIT( KItem2, "Chunk size" );
       
   163 	 _LIT( KItem3, "Alloc. count" );
       
   164 	 _LIT( KItem4, "Free. count" );
       
   165 	 _LIT( KItem5, "Biggest alloc." );
       
   166 	 _LIT( KItem6, "Biggest free" );
       
   167 	 _LIT( KItem6a, "Total alloc." );
       
   168 	 _LIT( KItem6b, "Total free" );
       
   169 	 _LIT( KItem7, "Slack free space" );
       
   170 	 _LIT( KItem8a, "Fragmentation" );
       
   171 	 _LIT( KItem13, "Header size (A)" );
       
   172 	 _LIT( KItem14, "Header size (F)" );
       
   173 	 _LIT( KItem9a, "Overhead (alloc)" );
       
   174 	 _LIT( KItem9b, "Overhead (free)" );
       
   175 	 _LIT( KItem9c, "Overhead (total)" );
       
   176 	 _LIT( KItem9d, "Overhead" );
       
   177 	 _LIT( KItem10, "Min. length" );
       
   178 	 _LIT( KItem11, "Max. length" );
       
   179 	 _LIT( KItem12, "Debug Allocator Library" );
       
   180 	 
       
   181 	HBufC* iItem = HBufC::NewL( 64 );	
       
   182 	
       
   183 	iItem = FormatItem( KItem0, aHeap->Type() );
       
   184 	TPtr pItem( iItem->Des() );
       
   185 	ret->AppendL( pItem );
       
   186 	pItem.Zero();	
       
   187 	
       
   188 	iItem = FormatItem( KItem1, aHeap->Size() );
       
   189 	pItem = iItem->Des();
       
   190 	ret->AppendL( pItem );
       
   191 	pItem.Zero();	
       
   192 	
       
   193 	TUint address( aHeap->BaseAddress() );	
       
   194 	iItem = FormatItem( KItem8b, address );
       
   195 	pItem = iItem->Des();
       
   196 	ret->AppendL( pItem );
       
   197 	pItem.Zero();
       
   198 	
       
   199 	if(aHeap->Shared()) //Yes / No value formatting		
       
   200 		iItem = FormatItem( KItem1b, KMemSpyCaptionYes );		
       
   201 	else		
       
   202 		iItem = FormatItem( KItem1b, KMemSpyCaptionNo );	
       
   203 	pItem = iItem->Des();
       
   204 	ret->AppendL( pItem );
       
   205 	pItem.Zero();
       
   206 	
       
   207 	iItem = FormatItem( KItem2, aHeap->ChunkSize() );
       
   208 	pItem = iItem->Des();
       
   209 	ret->AppendL( pItem );
       
   210 	pItem.Zero();
       
   211 	
       
   212 	iItem = FormatItem( KItem3, aHeap->AllocationsCount() );
       
   213 	pItem = iItem->Des();
       
   214 	ret->AppendL( pItem );
       
   215 	pItem.Zero();
       
   216 	
       
   217 	iItem = FormatItem( KItem4, aHeap->FreeCount() );
       
   218 	pItem = iItem->Des();
       
   219 	ret->AppendL( pItem );
       
   220 	pItem.Zero();
       
   221 	
       
   222 	iItem = FormatItem( KItem5, aHeap->BiggestAllocation() );
       
   223 	pItem = iItem->Des();
       
   224 	ret->AppendL( pItem );
       
   225 	pItem.Zero();
       
   226 	
       
   227 	iItem = FormatItem( KItem6, aHeap->BiggestFree() );
       
   228 	pItem = iItem->Des();
       
   229 	ret->AppendL( pItem );
       
   230 	pItem.Zero();
       
   231 	
       
   232 	iItem = FormatItem( KItem6a, aHeap->TotalAllocations() );
       
   233 	pItem = iItem->Des();
       
   234 	ret->AppendL( pItem );
       
   235 	pItem.Zero();
       
   236 	
       
   237 	iItem = FormatItem( KItem6b, aHeap->TotalFree() );
       
   238 	pItem = iItem->Des();
       
   239 	ret->AppendL( pItem );
       
   240 	pItem.Zero();
       
   241 	
       
   242 	iItem = FormatItem( KItem7, aHeap->SlackFreeSpace() );
       
   243 	pItem = iItem->Des();
       
   244 	ret->AppendL( pItem );
       
   245 	pItem.Zero();
       
   246 	
       
   247 	TReal iOneHundred( aHeap->Size() );
       
   248 	TReal iValue( aHeap->Fragmentation() );	
       
   249 	iItem = FormatPercentageItem( KItem8a, iOneHundred, iValue );
       
   250 	pItem = iItem->Des();
       
   251 	ret->AppendL( pItem );
       
   252 	pItem.Zero();
       
   253 	
       
   254 	iItem = FormatItem( KItem13, aHeap->HeaderSizeA() );
       
   255 	pItem = iItem->Des();
       
   256 	ret->AppendL( pItem );
       
   257 	pItem.Zero();
       
   258 	
       
   259 	iItem = FormatItem( KItem14, aHeap->HeaderSizeF() );
       
   260 	pItem = iItem->Des();
       
   261 	ret->AppendL( pItem );
       
   262 	pItem.Zero();
       
   263 	
       
   264 	iItem = FormatItem( KItem9a, aHeap->AllocationOverhead() );
       
   265 	pItem = iItem->Des();
       
   266 	ret->AppendL( pItem );
       
   267 	pItem.Zero();
       
   268 	
       
   269 	iItem = FormatItem( KItem9b, aHeap->FreeOverhead() );
       
   270 	pItem = iItem->Des();
       
   271 	ret->AppendL( pItem );
       
   272 	pItem.Zero();
       
   273 	
       
   274 	iItem = FormatItem( KItem9c, aHeap->TotalOverhead() );
       
   275 	pItem = iItem->Des();
       
   276 	ret->AppendL( pItem );
       
   277 	pItem.Zero();
       
   278 	
       
   279 	TReal iOverhead( aHeap->Overhead() );	
       
   280 	iItem = FormatPercentageItem( KItem9d, iOneHundred, iOverhead );	
       
   281 	pItem = iItem->Des();
       
   282 	ret->AppendL( pItem );
       
   283 	pItem.Zero();
       
   284 	
       
   285 	iItem = FormatItem( KItem10, aHeap->MinLength() );
       
   286 	pItem = iItem->Des();
       
   287 	ret->AppendL( pItem );
       
   288 	pItem.Zero();
       
   289 		
       
   290 	iItem = FormatItem( KItem11, aHeap->MaxLength() );
       
   291 	pItem = iItem->Des();
       
   292 	ret->AppendL( pItem );
       
   293 	pItem.Zero();
       
   294 	
       
   295 	if( aHeap->DebugAllocatorLibrary() )		
       
   296 		iItem = FormatItem( KItem12, KMemSpyCaptionYes );		
       
   297 	else
       
   298 		iItem = FormatItem( KItem12, KMemSpyCaptionNo );	
       
   299 	pItem = iItem->Des();
       
   300 	ret->AppendL( pItem );
       
   301 	pItem.Zero();
       
   302 	
       
   303 	return ret;
       
   304 	}
       
   305 
       
   306 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, const TDesC& aValue )
       
   307 	{
       
   308 	HBufC* retBuf = HBufC::NewL( 64 );
       
   309 	TPtr pRetBuf( retBuf->Des() );
       
   310 	pRetBuf.Zero();
       
   311 	pRetBuf.Append( _L("\t") );
       
   312 	pRetBuf.Append( aCaption );
       
   313 	pRetBuf.Append( _L("\t\t") );
       
   314 	pRetBuf.Append( aValue );
       
   315 	return retBuf;
       
   316 	}
       
   317 
       
   318 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TInt aValue )
       
   319 	{
       
   320 	HBufC* retBuf = HBufC::NewL( 64 );
       
   321 	TPtr pRetBuf( retBuf->Des() );
       
   322 	pRetBuf.Zero();
       
   323     
       
   324 	TBuf<KMemSpyBufferSize> val;
       
   325     val.Format( KMemSpyDecFormat, aValue );
       
   326     
       
   327     pRetBuf.Append( _L("\t") );
       
   328     pRetBuf.Append( aCaption );
       
   329     pRetBuf.Append( _L("\t\t") );
       
   330     pRetBuf.Append( val );    
       
   331 	
       
   332 	return retBuf;
       
   333 	}
       
   334 
       
   335 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TUint aValue )
       
   336 	{
       
   337 	HBufC* retBuf = HBufC::NewL( 64 );
       
   338 	TPtr pRetBuf( retBuf->Des() );
       
   339 	pRetBuf.Zero();
       
   340     
       
   341 	TBuf<KMemSpyBufferSize> val;
       
   342     //val.Format( KMemSpyDecFormat, aValue );
       
   343 	val.Format( KMemSpyHexFormat, aValue );
       
   344     
       
   345     pRetBuf.Append( _L("\t") );
       
   346     pRetBuf.Append( aCaption );
       
   347     pRetBuf.Append( _L("\t\t") );
       
   348     pRetBuf.Append( val );    
       
   349 	
       
   350 	return retBuf;	
       
   351 	}
       
   352 
       
   353 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, const TInt64& aValue )
       
   354 	{
       
   355 	HBufC* retBuf = HBufC::NewL( 64 );
       
   356 	TPtr pRetBuf( retBuf->Des() );
       
   357 	pRetBuf.Zero();
       
   358 	    
       
   359 	TBuf<KMemSpyBufferSize> val;
       
   360 	val.Format( KMemSpyLongFormat, aValue );
       
   361 	    
       
   362 	pRetBuf.Append( _L("\t") );
       
   363 	pRetBuf.Append( aCaption );
       
   364 	pRetBuf.Append( _L("\t\t") );
       
   365 	pRetBuf.Append( val );    
       
   366 		
       
   367 	return retBuf;	
       
   368 	}
       
   369 
       
   370 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TAny* aValue )
       
   371 	{
       
   372 	HBufC* retBuf = HBufC::NewL( 64 );
       
   373 	TPtr pRetBuf( retBuf->Des() );
       
   374 	pRetBuf.Zero();
       
   375 		    
       
   376 	TBuf<KMemSpyBufferSize> val;
       
   377 	val.Format( KMemSpyHexFormat, aValue );
       
   378 		    
       
   379 	pRetBuf.Append( _L("\t") );
       
   380 	pRetBuf.Append( aCaption );
       
   381 	pRetBuf.Append( _L("\t\t") );
       
   382 	pRetBuf.Append( val );    
       
   383 			
       
   384 	return retBuf;	
       
   385 	}
       
   386 
       
   387 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TUint* aValue )
       
   388 	{
       
   389 	HBufC* retBuf = HBufC::NewL( 64 );
       
   390 	TPtr pRetBuf( retBuf->Des() );
       
   391 	pRetBuf.Zero();
       
   392 		    
       
   393 	TBuf<KMemSpyBufferSize> val;
       
   394 	val.Format( KMemSpyHexFormat, aValue );
       
   395 		    
       
   396 	pRetBuf.Append( _L("\t") );
       
   397 	pRetBuf.Append( aCaption );
       
   398 	pRetBuf.Append( _L("\t\t") );
       
   399 	pRetBuf.Append( val );    
       
   400 			
       
   401 	return retBuf;	
       
   402 	}
       
   403 
       
   404 HBufC* CMemSpyViewKernelHeap::FormatItem( const TDesC& aCaption, TUint8* aValue )
       
   405 	{
       
   406 	HBufC* retBuf = HBufC::NewL( 64 );
       
   407 	TPtr pRetBuf( retBuf->Des() );
       
   408 	pRetBuf.Zero();
       
   409 		    
       
   410 	TBuf<KMemSpyBufferSize> val;
       
   411 	val.Format( KMemSpyHexFormat, aValue );
       
   412 		    
       
   413 	pRetBuf.Append( _L("\t") );
       
   414 	pRetBuf.Append( aCaption );
       
   415 	pRetBuf.Append( _L("\t\t") );
       
   416 	pRetBuf.Append( val );    
       
   417 			
       
   418 	return retBuf;	
       
   419 	}
       
   420 
       
   421 HBufC* CMemSpyViewKernelHeap::FormatPercentageItem( const TDesC& aCaption, TReal aOneHundredPercentValue, TReal aValue )
       
   422 	{
       
   423 	HBufC* retBuf = HBufC::NewL( 64 );	//buffer for formatted item
       
   424 	TPtr pRetBuf( retBuf->Des() );
       
   425 	pRetBuf.Zero();
       
   426 	
       
   427     const TReal value = (TInt) (( aValue / aOneHundredPercentValue) * 100.0); // percentage value calculation    
       
   428     _LIT(KPercentFormat, "%3.2f %%");
       
   429     TMemSpyPercentText val;
       
   430     val.Format( KPercentFormat, value );
       
   431     
       
   432 	pRetBuf.Append( _L("\t") );
       
   433 	pRetBuf.Append( aCaption );
       
   434 	pRetBuf.Append( _L("\t\t") );
       
   435 	pRetBuf.Append( val );    
       
   436 			
       
   437 	return retBuf;
       
   438 	}