memspy/Engine/Source/Helpers/MemSpyEngineHelperHeap.cpp
changeset 30 86a2e675b80a
parent 26 4fde310f06fe
equal deleted inserted replaced
26:4fde310f06fe 30:86a2e675b80a
    43 _LIT( KCellTypeGoodFreeCell,             "[Free Cell]                 ");
    43 _LIT( KCellTypeGoodFreeCell,             "[Free Cell]                 ");
    44 _LIT( KCellTypeBadAllocatedCellSize,     "[Bad Allocated Cell Size]   ");
    44 _LIT( KCellTypeBadAllocatedCellSize,     "[Bad Allocated Cell Size]   ");
    45 _LIT( KCellTypeBadAllocatedCellAddress,  "[Bad Allocated Cell Address]");
    45 _LIT( KCellTypeBadAllocatedCellAddress,  "[Bad Allocated Cell Address]");
    46 _LIT( KCellTypeBadFreeCellAddress,       "[Bad Free Cell Address]     ");
    46 _LIT( KCellTypeBadFreeCellAddress,       "[Bad Free Cell Address]     ");
    47 _LIT( KCellTypeBadFreeCellSize,          "[Bad Free Cell Size]        ");
    47 _LIT( KCellTypeBadFreeCellSize,          "[Bad Free Cell Size]        ");
       
    48 _LIT( KCellTypeBad,                      "[Bad Cell]                  ");
    48 _LIT( KCellTypeUnknown,                  "[Unknown!]                  ");
    49 _LIT( KCellTypeUnknown,                  "[Unknown!]                  ");
    49 _LIT( KCellListLineFormat, "%S cell: 0x%08x, cellLen: %8d, allocNum: %8d, nestingLev: %8d, cellData: 0x%08x, cellDataAddr: 0x%08x, headerSize: %02d");
    50 _LIT( KCellListLineFormat, "%S cell: 0x%08x, cellLen: %8d, allocNum: %8d, nestingLev: %8d, cellData: 0x%08x, cellDataAddr: 0x%08x, headerSize: %02d");
    50 _LIT( KMemSpyMarkerHeapData, "<%SMEMSPY_HEAP_DATA_%03d>" );
    51 _LIT( KMemSpyMarkerHeapData, "<%SMEMSPY_HEAP_DATA_%03d>" );
    51 _LIT( KMemSpyMarkerCSV, "<%SMEMSPY_HEAP_CSV>" );
    52 _LIT( KMemSpyMarkerCSV, "<%SMEMSPY_HEAP_CSV>" );
    52 _LIT( KMemSpyPrefixHeapData, "HeapData - %S - ");
    53 _LIT( KMemSpyPrefixHeapData, "HeapData - %S - ");
   102     const TInt error = iEngine.Driver().GetHeapInfoUser( heapInfo, aThread.Id(), freeCells );
   103     const TInt error = iEngine.Driver().GetHeapInfoUser( heapInfo, aThread.Id(), freeCells );
   103     if ( error == KErrNone )
   104     if ( error == KErrNone )
   104         {
   105         {
   105         UpdateSharedHeapInfoL( aThread.Process().Id(), aThread.Id(), heapInfo );
   106         UpdateSharedHeapInfoL( aThread.Process().Id(), aThread.Id(), heapInfo );
   106         }
   107         }
   107     if  ( error == KErrNone && heapInfo.Type() == TMemSpyHeapInfo::ETypeRHeap )
   108     if  ( error == KErrNone && heapInfo.Type() != TMemSpyHeapInfo::ETypeUnknown )
   108         {
   109         {
   109         // Get thread name for context
   110         // Get thread name for context
   110         const TFullName pName( aThread.FullName() );
   111         const TFullName pName( aThread.FullName() );
   111 
   112 
   112         // Begin a new data stream
   113         // Begin a new data stream
   157             while( r == KErrNone )
   158             while( r == KErrNone )
   158                 {
   159                 {
   159                 TUint fourByteCellData = 0;
   160                 TUint fourByteCellData = 0;
   160                 TPtrC pType(KNullDesC);
   161                 TPtrC pType(KNullDesC);
   161                 //
   162                 //
   162                 switch(cellType)
   163 				if (cellType & EMemSpyDriverAllocatedCellMask)
   163                     {
   164 					{
   164                 case EMemSpyDriverGoodAllocatedCell:
       
   165                     {
       
   166                     r = iEngine.Driver().WalkHeapReadCellData( cellAddress, cellData, 4 );
   165                     r = iEngine.Driver().WalkHeapReadCellData( cellAddress, cellData, 4 );
   167                     if  ( r == KErrNone )
   166                     if  ( r == KErrNone )
   168                         {
   167                         {
   169                         fourByteCellData = DescriptorAsDWORD( cellData );
   168                         fourByteCellData = DescriptorAsDWORD( cellData );
   170                         }
   169                         }
   171                     pType.Set(KCellTypeGoodAllocatedCell);
   170                     pType.Set(KCellTypeGoodAllocatedCell);
   172                     break;
       
   173                     }
   171                     }
   174                 case EMemSpyDriverGoodFreeCell:
   172 				else if (cellType & EMemSpyDriverFreeCellMask)
       
   173 					{
   175                     pType.Set(KCellTypeGoodFreeCell);
   174                     pType.Set(KCellTypeGoodFreeCell);
   176                     break;
   175 					}
   177                 case EMemSpyDriverBadAllocatedCellSize:
   176 				else if (cellType & EMemSpyDriverBadCellMask)
   178                     pType.Set(KCellTypeBadAllocatedCellSize);
   177 					{
   179                     break;
   178 					switch (cellType)
   180                 case EMemSpyDriverBadAllocatedCellAddress:
   179 						{
   181                     pType.Set(KCellTypeBadAllocatedCellAddress);
   180 					case EMemSpyDriverHeapBadAllocatedCellSize:
   182                     break;
   181 						pType.Set(KCellTypeBadAllocatedCellSize);
   183                 case EMemSpyDriverBadFreeCellAddress:
   182 						break;
   184                     pType.Set(KCellTypeBadFreeCellAddress);
   183 					case EMemSpyDriverHeapBadAllocatedCellAddress:
   185                     break;
   184 						pType.Set(KCellTypeBadAllocatedCellAddress);
   186                 case EMemSpyDriverBadFreeCellSize:
   185 						break;
   187                     pType.Set(KCellTypeBadFreeCellSize);
   186 					case EMemSpyDriverHeapBadFreeCellAddress:
   188                     break;
   187 						pType.Set(KCellTypeBadFreeCellAddress);
   189                 default:
   188 						break;
       
   189 					case EMemSpyDriverHeapBadFreeCellSize:
       
   190 						pType.Set(KCellTypeBadFreeCellSize);
       
   191 						break;
       
   192 					default:
       
   193 						pType.Set(KCellTypeBad);
       
   194 						break;
       
   195 						}
       
   196 					}
       
   197 				else
       
   198 					{
   190                     pType.Set(KCellTypeUnknown);
   199                     pType.Set(KCellTypeUnknown);
   191                     break;
       
   192                     }
   200                     }
   193 
   201 
   194                 if  ( r == KErrNone )
   202                 if  ( r == KErrNone )
   195                     {
   203                     {
   196                     pTempBuffer.Format( KCellListLineFormat, &pType, cellAddress, cellLength, cellAllocationNumber, cellNestingLevel, fourByteCellData, cellPayloadAddress, cellHeaderSize );
   204                     pTempBuffer.Format( KCellListLineFormat, &pType, cellAddress, cellLength, cellAllocationNumber, cellNestingLevel, fourByteCellData, cellPayloadAddress, cellHeaderSize );
   239 void CMemSpyEngineHelperHeap::OutputHeapDataUserL( const CMemSpyThread& aThread, TBool aCreateDataStream )
   247 void CMemSpyEngineHelperHeap::OutputHeapDataUserL( const CMemSpyThread& aThread, TBool aCreateDataStream )
   240     {
   248     {
   241     // Make sure the process is suspended for the entire time we are manipulating it's heap
   249     // Make sure the process is suspended for the entire time we are manipulating it's heap
   242     iEngine.ProcessSuspendLC( aThread.Process().Id() );
   250     iEngine.ProcessSuspendLC( aThread.Process().Id() );
   243 
   251 
   244     // Get the heap info, including free cell information
   252     // Get the heap info, including cell information
   245     RArray<TMemSpyDriverFreeCell> freeCells;
   253     RArray<TMemSpyDriverCell> cells;
   246     CleanupClosePushL( freeCells );
   254     CleanupClosePushL( cells );
   247     TMemSpyHeapInfo heapInfo;
   255     TMemSpyHeapInfo heapInfo;
   248     TRACE( RDebug::Printf( "CMemSpyEngineHelperHeap::OutputHeapDataUserL() - checksum1: 0x%08x", heapInfo.AsRHeap().Statistics().StatsFree().Checksum() ) );
   256     TRACE( RDebug::Printf( "CMemSpyEngineHelperHeap::OutputHeapDataUserL() - checksum1: 0x%08x", heapInfo.AsRHeap().Statistics().StatsFree().Checksum() ) );
   249     GetHeapInfoUserL( aThread.Process().Id(), aThread.Id(), heapInfo, &freeCells );
   257     GetHeapInfoUserL(aThread.Process().Id(), aThread.Id(), heapInfo, &cells, ETrue);
   250     TRACE( RDebug::Printf( "CMemSpyEngineHelperHeap::OutputHeapDataUserL() - checksum2: 0x%08x", heapInfo.AsRHeap().Statistics().StatsFree().Checksum() ) );
   258     TRACE( RDebug::Printf( "CMemSpyEngineHelperHeap::OutputHeapDataUserL() - checksum2: 0x%08x", heapInfo.AsRHeap().Statistics().StatsFree().Checksum() ) );
   251 
   259 
   252     // Get the heap data
   260     // Get the heap data
   253     const TFullName pName( aThread.FullName() );
   261     const TFullName pName( aThread.FullName() );
   254     OutputHeapDataUserL( aThread.Process().Id(), aThread.Id(), pName, heapInfo, aCreateDataStream, &freeCells );
   262     OutputHeapDataUserL( aThread.Process().Id(), aThread.Id(), pName, heapInfo, aCreateDataStream, &cells );
   255     CleanupStack::PopAndDestroy( &freeCells );
   263     CleanupStack::PopAndDestroy( &cells );
   256 
   264 
   257     // Resume process
   265     // Resume process
   258     CleanupStack::PopAndDestroy();
   266     CleanupStack::PopAndDestroy();
   259     }
   267     }
   260 
   268 
   261 
   269 
   262 EXPORT_C void CMemSpyEngineHelperHeap::OutputHeapDataUserL( const TProcessId& aPid, const TThreadId& aTid, const TDesC& aThreadName, const TMemSpyHeapInfo& aInfo, const RArray<TMemSpyDriverFreeCell>* aFreeCells )
   270 EXPORT_C void CMemSpyEngineHelperHeap::OutputHeapDataUserL(const TProcessId& aPid, const TThreadId& aTid, const TDesC& aThreadName, const TMemSpyHeapInfo& aInfo, const RArray<TMemSpyDriverCell>* aCells)
   263     {
   271     {
   264     OutputHeapDataUserL( aPid, aTid, aThreadName, aInfo, ETrue, aFreeCells );
   272     OutputHeapDataUserL(aPid, aTid, aThreadName, aInfo, ETrue, aCells);
   265     }
   273     }
   266 
   274 
   267 
   275 void CMemSpyEngineHelperHeap::OutputHeapDataUserL( const TProcessId& aPid, const TThreadId& aTid, const TDesC& aThreadName, const TMemSpyHeapInfo& aInfo, TBool aCreateDataStream, const RArray<TMemSpyDriverCell>* aCells )
   268 void CMemSpyEngineHelperHeap::OutputHeapDataUserL( const TProcessId& aPid, const TThreadId& aTid, const TDesC& aThreadName, const TMemSpyHeapInfo& aInfo, TBool aCreateDataStream, const RArray<TMemSpyDriverFreeCell>* aFreeCells )
       
   269     {
   276     {
   270     TBuf<KMaxFullName + 100> printFormat;
   277     TBuf<KMaxFullName + 100> printFormat;
   271 
   278 
   272     // Begin a new data stream
   279     // Begin a new data stream
   273     if  ( aCreateDataStream )
   280     if  ( aCreateDataStream )
   289 
   296 
   290     // Set overall prefix
   297     // Set overall prefix
   291     iEngine.Sink().OutputPrefixSetFormattedLC( KMemSpyPrefixHeapData, &aThreadName );
   298     iEngine.Sink().OutputPrefixSetFormattedLC( KMemSpyPrefixHeapData, &aThreadName );
   292 
   299 
   293     // Info section
   300     // Info section
   294     OutputHeapInfoL( aInfo, aThreadName, aFreeCells );
   301     OutputHeapInfoL( aInfo, aThreadName, aCells );
   295 
   302 
   296     // Code segments (needed for map file reading...)
   303     // Code segments (needed for map file reading...)
   297     _LIT(KCellListCodeSegInfoFormat, "CodeSegs - ");
   304     _LIT(KCellListCodeSegInfoFormat, "CodeSegs - ");
   298     iEngine.HelperCodeSegment().OutputCodeSegmentsL( aPid, printFormat, KCellListCodeSegInfoFormat, '-', ETrue );
   305     iEngine.HelperCodeSegment().OutputCodeSegmentsL( aPid, printFormat, KCellListCodeSegInfoFormat, '-', ETrue );
   299 
   306 
   313     // a mismatch in free cell information).
   320     // a mismatch in free cell information).
   314     const TUint32 checksum = aInfo.AsRHeap().Statistics().StatsFree().Checksum();
   321     const TUint32 checksum = aInfo.AsRHeap().Statistics().StatsFree().Checksum();
   315     TRACE( RDebug::Printf( "CMemSpyEngineHelperHeap::OutputHeapDataUserL() - checksum: 0x%08x", checksum ) );
   322     TRACE( RDebug::Printf( "CMemSpyEngineHelperHeap::OutputHeapDataUserL() - checksum: 0x%08x", checksum ) );
   316 
   323 
   317     TInt r = iEngine.Driver().GetHeapData( aTid, checksum, pData, readAddress, remaining );
   324     TInt r = iEngine.Driver().GetHeapData( aTid, checksum, pData, readAddress, remaining );
   318     if  ( r == KErrNone )
   325 	TUint prevEndAddress = readAddress + pData.Length();
   319         {
   326     if (r == KErrNone)
   320         while ( r == KErrNone )
   327         {
       
   328         while (r == KErrNone)
   321             {
   329             {
       
   330 			if (readAddress > prevEndAddress)
       
   331 				{
       
   332 				// We've hit a discontinuity, ie one or more unmapped pages
       
   333 				_LIT(KBreak, "........");
       
   334 				iEngine.Sink().OutputLineL(KBreak);
       
   335 				}
   322             _LIT(KHeapDumpDataFormat, "%S");
   336             _LIT(KHeapDumpDataFormat, "%S");
   323             iEngine.Sink().OutputBinaryDataL( KHeapDumpDataFormat, pData.Ptr(), (const TUint8*) readAddress, pData.Length() );
   337             iEngine.Sink().OutputBinaryDataL(KHeapDumpDataFormat, pData.Ptr(), (const TUint8*) readAddress, pData.Length());
   324             if  ( remaining > 0 )
   338 			readAddress += pData.Length();
   325                 r = iEngine.Driver().GetHeapDataNext( aTid, pData, readAddress, remaining );
   339             if (remaining > 0)
       
   340 				{
       
   341 				prevEndAddress = readAddress;
       
   342                 r = iEngine.Driver().GetHeapDataNext(aTid, pData, readAddress, remaining);
       
   343 				}
   326             else
   344             else
   327                 break;
   345                 break;
   328             }
   346             }
   329         }
   347         }
   330     else
   348     else
   363 
   381 
   364 
   382 
   365 
   383 
   366 
   384 
   367 
   385 
   368 
   386 EXPORT_C void CMemSpyEngineHelperHeap::OutputHeapInfoL( const TMemSpyHeapInfo& aInfo, const TDesC& aThreadName, const RArray<TMemSpyDriverCell>* aCells )
   369 
   387 	{
   370 EXPORT_C void CMemSpyEngineHelperHeap::OutputHeapInfoL( const TMemSpyHeapInfo& aInfo, const TDesC& aThreadName, const RArray<TMemSpyDriverFreeCell>* aFreeCells )
   388     CMemSpyEngineOutputList* list = NewHeapSummaryExtendedLC(aInfo, aCells);
   371     {
       
   372     CMemSpyEngineOutputList* list = NewHeapSummaryExtendedLC( aInfo, aFreeCells );
       
   373 
   389 
   374     // Format the thread name according to upper/lower case request parameters
   390     // Format the thread name according to upper/lower case request parameters
   375     _LIT( KOverallCaption1, "HEAP INFO FOR THREAD '%S'");
   391     _LIT( KOverallCaption1, "HEAP INFO FOR THREAD '%S'");
   376     list->InsertItemFormatUCL( 0, KOverallCaption1, &aThreadName );
   392     list->InsertItemFormatUCL( 0, KOverallCaption1, &aThreadName );
   377     list->InsertUnderlineForItemAtL( 0 );
   393     list->InsertUnderlineForItemAtL( 0 );
   414 
   430 
   415 void CMemSpyEngineHelperHeap::OutputCSVEntryL( TInt aIndex, const TMemSpyHeapInfo& aInfo, const TDesC& aThreadName, const TDesC& aProcessName )
   431 void CMemSpyEngineHelperHeap::OutputCSVEntryL( TInt aIndex, const TMemSpyHeapInfo& aInfo, const TDesC& aThreadName, const TDesC& aProcessName )
   416     {
   432     {
   417     const TMemSpyHeapInfoRHeap& rHeapInfo = aInfo.AsRHeap();
   433     const TMemSpyHeapInfoRHeap& rHeapInfo = aInfo.AsRHeap();
   418     const TMemSpyHeapMetaDataRHeap& rHeapMetaData = rHeapInfo.MetaData();
   434     const TMemSpyHeapMetaDataRHeap& rHeapMetaData = rHeapInfo.MetaData();
   419     const TMemSpyHeapObjectDataRHeap& rHeapObjectData = rHeapInfo.ObjectData();
       
   420     const TMemSpyHeapStatisticsRHeap& rHeapStats = rHeapInfo.Statistics();
   435     const TMemSpyHeapStatisticsRHeap& rHeapStats = rHeapInfo.Statistics();
   421 
   436 
   422     // Example:
   437     // Example:
   423     //
   438     //
   424     //  <ENTRY_001>
   439     //  <ENTRY_001>
   454     iEngine.Sink().OutputLineFormattedL( KFmtFieldContent,
   469     iEngine.Sink().OutputLineFormattedL( KFmtFieldContent,
   455                                          &KFmtFields,
   470                                          &KFmtFields,
   456                                          aIndex,
   471                                          aIndex,
   457                                          aInfo.Tid(),
   472                                          aInfo.Tid(),
   458                                          rHeapMetaData.ChunkHandle(),
   473                                          rHeapMetaData.ChunkHandle(),
   459                                          rHeapObjectData.Base(),
   474                                          /*rHeapObjectData.Base(),*/ rHeapMetaData.iAllocatorAddress,
   460                                          rHeapObjectData.Size(),
   475                                          /*rHeapObjectData.Size(),*/ rHeapMetaData.iHeapSize,
   461                                          rHeapObjectData.iMinLength,
   476                                          /*rHeapObjectData.iMinLength,*/ rHeapMetaData.iMinHeapSize,
   462                                          rHeapObjectData.iMaxLength,
   477                                          /*rHeapObjectData.iMaxLength,*/ rHeapMetaData.iMaxHeapSize,
   463                                          rHeapObjectData.iFree.next,
   478                                          /*rHeapObjectData.iFree.next,*/ NULL,
   464                                          rHeapObjectData.iFree.len,
   479                                          /*rHeapObjectData.iFree.len,*/ 0,
   465                                          rHeapStats.StatsFree().TypeCount(),
   480                                          rHeapStats.StatsFree().TypeCount(),
   466                                          rHeapStats.StatsFree().TypeSize(),
   481                                          rHeapStats.StatsFree().TypeSize(),
   467                                          rHeapStats.StatsFree().SlackSpaceCellSize(),
   482                                          rHeapStats.StatsFree().SlackSpaceCellSize(),
   468                                          rHeapStats.StatsFree().LargestCellSize(),
   483                                          rHeapStats.StatsFree().LargestCellSize(),
   469                                          rHeapStats.StatsAllocated().LargestCellSize(),
   484                                          rHeapStats.StatsAllocated().LargestCellSize(),
   470                                          rHeapObjectData.iCellCount,
   485                                          /*rHeapObjectData.iCellCount,*/ rHeapStats.StatsAllocated().TypeCount(),
   471                                          rHeapObjectData.iMinCell,
   486                                          /*rHeapObjectData.iMinCell,*/ 0,
   472                                          rHeapObjectData.iTotalAllocSize,
   487                                          /*rHeapObjectData.iTotalAllocSize,*/ rHeapStats.StatsAllocated().TypeSize(),
   473                                          rHeapMetaData.IsSharedHeap(),
   488                                          rHeapMetaData.IsSharedHeap(),
   474                                          &KFmtFields,
   489                                          &KFmtFields,
   475                                          aIndex
   490                                          aIndex
   476                                          );
   491                                          );
   477     
   492     
   517     if  ( aIncludeKernel )
   532     if  ( aIncludeKernel )
   518         {
   533         {
   519         // Get kernel heap info
   534         // Get kernel heap info
   520         GetHeapInfoKernelL( info );
   535         GetHeapInfoKernelL( info );
   521 
   536 
   522         if ( info.Type() == TMemSpyHeapInfo::ETypeRHeap )
   537         if ( info.Type() != TMemSpyHeapInfo::ETypeUnknown )
   523             {
   538             {
   524             TName threadName;
   539             TName threadName;
   525             MemSpyEngineUtils::GetKernelHeapThreadAndProcessNames( threadName, processName );
   540             MemSpyEngineUtils::GetKernelHeapThreadAndProcessNames( threadName, processName );
   526             OutputCSVEntryL( index++, info, threadName, processName );
   541             OutputCSVEntryL( index++, info, threadName, processName );
   527             }
   542             }
   544                 const TInt error = iEngine.Driver().GetHeapInfoUser( info, thread.Id() );
   559                 const TInt error = iEngine.Driver().GetHeapInfoUser( info, thread.Id() );
   545                 if ( error == KErrNone )
   560                 if ( error == KErrNone )
   546                     {
   561                     {
   547                     UpdateSharedHeapInfoL( process.Id(), thread.Id(), info );
   562                     UpdateSharedHeapInfoL( process.Id(), thread.Id(), info );
   548                     }
   563                     }
   549                 if  ( error == KErrNone && info.Type() == TMemSpyHeapInfo::ETypeRHeap )
   564                 if  ( error == KErrNone && info.Type() != TMemSpyHeapInfo::ETypeUnknown )
   550                     {
   565                     {
   551                     OutputCSVEntryL( index++, info, threadName, processName );
   566                     OutputCSVEntryL( index++, info, threadName, processName );
   552                     }
   567                     }
   553                 }
   568                 }
   554     
   569     
   575 
   590 
   576 
   591 
   577 
   592 
   578 
   593 
   579 
   594 
   580 EXPORT_C void CMemSpyEngineHelperHeap::GetHeapInfoUserL( const TProcessId& aProcess, const TThreadId& aThread, TMemSpyHeapInfo& aInfo, RArray<TMemSpyDriverFreeCell>* aFreeCells )
   595 EXPORT_C void CMemSpyEngineHelperHeap::GetHeapInfoUserL(const TProcessId& aProcess, const TThreadId& aThread, TMemSpyHeapInfo& aInfo, RArray<TMemSpyDriverFreeCell>* aFreeCells)
       
   596     {
       
   597 	GetHeapInfoUserL(aProcess, aThread, aInfo, aFreeCells, EFalse);
       
   598 	}
       
   599 
       
   600 EXPORT_C void CMemSpyEngineHelperHeap::GetHeapInfoUserL(const TProcessId& aProcess, const TThreadId& aThread, TMemSpyHeapInfo& aInfo, RArray<TMemSpyDriverCell>* aCells, TBool aCollectAllocatedCellsAsWellAsFree)
   581     {
   601     {
   582     iEngine.ProcessSuspendLC( aProcess );
   602     iEngine.ProcessSuspendLC( aProcess );
   583     TRACE( RDebug::Printf( "CMemSpyEngineHelperHeap::GetHeapInfoUserL() - checksum1: 0x%08x", aInfo.AsRHeap().Statistics().StatsFree().Checksum() ) );
   603     TRACE( RDebug::Printf( "CMemSpyEngineHelperHeap::GetHeapInfoUserL() - checksum1: 0x%08x", aInfo.AsRHeap().Statistics().StatsFree().Checksum() ) );
   584     
   604     
   585     TInt r = KErrNone;
   605     TInt r = KErrNone;
   586     //
   606     //
   587     if  ( aFreeCells )
   607     if  (aCells)
   588         {
   608         {
   589         r = iEngine.Driver().GetHeapInfoUser( aInfo, aThread, *aFreeCells );
   609         r = iEngine.Driver().GetHeapInfoUser( aInfo, aThread, *aCells, aCollectAllocatedCellsAsWellAsFree);
   590         }
   610         }
   591     else
   611     else
   592         {
   612         {
   593         r = iEngine.Driver().GetHeapInfoUser( aInfo, aThread );
   613         r = iEngine.Driver().GetHeapInfoUser( aInfo, aThread );
   594         }
   614         }
   734 
   754 
   735     // Dump section
   755     // Dump section
   736     _LIT(KHeaderDump, "Heap Data");
   756     _LIT(KHeaderDump, "Heap Data");
   737     iEngine.Sink().OutputSectionHeadingL( KHeaderDump, '-' );
   757     iEngine.Sink().OutputSectionHeadingL( KHeaderDump, '-' );
   738 
   758 
   739     _LIT(KHeapDumpDataFormat, "%S");
   759     /*TOMSCI TODO this stuff needs fixing
       
   760 	_LIT(KHeapDumpDataFormat, "%S");
   740     const TUint8* heapBaseAddress = info.AsRHeap().ObjectData().Base();
   761     const TUint8* heapBaseAddress = info.AsRHeap().ObjectData().Base();
   741     iEngine.Sink().OutputBinaryDataL( KHeapDumpDataFormat, data->Ptr(), heapBaseAddress, data->Length() );
   762     iEngine.Sink().OutputBinaryDataL( KHeapDumpDataFormat, data->Ptr(), heapBaseAddress, data->Length() );
       
   763 	*/
   742 
   764 
   743     CleanupStack::PopAndDestroy(); // clear prefix
   765     CleanupStack::PopAndDestroy(); // clear prefix
   744     CleanupStack::PopAndDestroy( data );
   766     CleanupStack::PopAndDestroy( data );
   745     CleanupStack::PopAndDestroy( &freeCells );
   767     CleanupStack::PopAndDestroy( &freeCells );
   746 
   768 
   793     if ( aInfo.Type() == TMemSpyHeapInfo::ETypeUnknown )
   815     if ( aInfo.Type() == TMemSpyHeapInfo::ETypeUnknown )
   794         {
   816         {
   795         _LIT( KItem0_Type_Unknown, "Unknown" );
   817         _LIT( KItem0_Type_Unknown, "Unknown" );
   796         list->AddItemL( KItem0, KItem0_Type_Unknown );
   818         list->AddItemL( KItem0, KItem0_Type_Unknown );
   797         }
   819         }
   798     else if ( aInfo.Type() == TMemSpyHeapInfo::ETypeRHeap )
   820     else
   799         {
   821         {
   800         const TMemSpyHeapInfoRHeap& rHeap = aInfo.AsRHeap();
   822         const TMemSpyHeapInfoRHeap& rHeap = aInfo.AsRHeap();
   801         const TMemSpyHeapMetaDataRHeap& metaData = rHeap.MetaData();
   823         const TMemSpyHeapMetaDataRHeap& metaData = rHeap.MetaData();
   802         const TMemSpyHeapObjectDataRHeap& objectData = rHeap.ObjectData();
       
   803         const TMemSpyHeapStatisticsRHeap& statistics = rHeap.Statistics();
   824         const TMemSpyHeapStatisticsRHeap& statistics = rHeap.Statistics();
   804 
   825 
   805         _LIT( KItem0_Type_RHeap, "RHeap" );
   826         _LIT( KItem0_Type_RHeap, "RHeap" );
   806         list->AddItemL( KItem0, KItem0_Type_RHeap );
   827         _LIT( KItem0_Type_RHybridHeap, "RHybridHeap" );
       
   828 		if (aInfo.Type() == TMemSpyHeapInfo::ETypeRHeap)
       
   829 			{
       
   830 	        list->AddItemL( KItem0, KItem0_Type_RHeap );
       
   831 			}
       
   832 		else
       
   833 			{
       
   834 	        list->AddItemL( KItem0, KItem0_Type_RHybridHeap );
       
   835 			}
   807 
   836 
   808         // Heap size is the size of the heap minus the size of the embedded (in-place) RHeap. 
   837         // Heap size is the size of the heap minus the size of the embedded (in-place) RHeap. 
   809         _LIT( KItem1, "Heap size" );
   838         _LIT( KItem1, "Heap size" );
   810         list->AddItemL( KItem1, objectData.Size() );
   839         list->AddItemL(KItem1, metaData.iHeapSize);
   811 
   840 
   812         _LIT( KItem8b, "Heap base address" );
   841         _LIT( KItem8b, "Allocator address" );
   813         list->AddItemHexL( KItem8b, (TUint) objectData.Base() );
   842         list->AddItemHexL( KItem8b, (TUint)metaData.iAllocatorAddress );
   814         
   843         
   815         _LIT( KItem1b, "Shared" );
   844         _LIT( KItem1b, "Shared" );
   816         list->AddItemYesNoL( KItem1b, metaData.IsSharedHeap() );
   845         list->AddItemYesNoL( KItem1b, metaData.IsSharedHeap() );
   817 
   846 
   818         // This is the size (rounded to the page) of memory associated with
   847         // This is the size (rounded to the page) of memory associated with
   843         list->AddItemL( KItem7, statistics.StatsFree().SlackSpaceCellSize() );
   872         list->AddItemL( KItem7, statistics.StatsFree().SlackSpaceCellSize() );
   844 
   873 
   845         // Fragmentation is a measurement of free space scattered throughout the heap, but ignoring
   874         // Fragmentation is a measurement of free space scattered throughout the heap, but ignoring
   846         // any slack space at the end (which can often be recovered, to the granularity of one page of ram)
   875         // any slack space at the end (which can often be recovered, to the granularity of one page of ram)
   847         _LIT( KItem8a, "Fragmentation" );
   876         _LIT( KItem8a, "Fragmentation" );
   848         list->AddItemPercentageL( KItem8a, objectData.Size(), ( statistics.StatsFree().TypeSize()  - statistics.StatsFree().SlackSpaceCellSize() ) );
   877         list->AddItemPercentageL( KItem8a, metaData.iHeapSize, ( statistics.StatsFree().TypeSize()  - statistics.StatsFree().SlackSpaceCellSize() ) );
   849 
   878 
   850         _LIT( KItem13, "Header size (A)" );
       
   851         list->AddItemL( KItem13, metaData.HeaderSizeAllocated() );
       
   852 
       
   853         _LIT( KItem14, "Header size (F)" );
       
   854         list->AddItemL( KItem14, metaData.HeaderSizeFree() );
       
   855 
       
   856         _LIT( KItem9a, "Overhead (alloc)" );
       
   857         const TInt allocOverhead = metaData.HeaderSizeAllocated() * statistics.StatsAllocated().TypeCount();
       
   858         list->AddItemL( KItem9a, allocOverhead );
       
   859 
       
   860         _LIT( KItem9b, "Overhead (free)" );
       
   861         const TInt freeOverhead = metaData.HeaderSizeFree() * statistics.StatsFree().TypeCount();
       
   862         list->AddItemL( KItem9b, freeOverhead );
       
   863 
   879 
   864         _LIT( KItem9c, "Overhead (total)" );
   880         _LIT( KItem9c, "Overhead (total)" );
   865         const TInt totalOverhead = freeOverhead + allocOverhead;
   881 		const TInt totalOverhead = metaData.iHeapSize - statistics.StatsAllocated().TypeSize();
   866         list->AddItemL( KItem9c, totalOverhead );
   882         list->AddItemL( KItem9c, totalOverhead );
   867 
   883 
   868         _LIT( KItem9d, "Overhead" );
   884         _LIT( KItem9d, "Overhead" );
   869         list->AddItemPercentageL( KItem9d, objectData.Size(), totalOverhead  );
   885         list->AddItemPercentageL( KItem9d, metaData.iHeapSize, totalOverhead  );
   870 
   886 
   871         _LIT( KItem10, "Min. length" );
   887         _LIT( KItem10, "Min. length" );
   872         list->AddItemL( KItem10, objectData.iMinLength );
   888         list->AddItemL( KItem10, metaData.iMinHeapSize );
   873 
   889 
   874         _LIT( KItem11, "Max. length" );
   890         _LIT( KItem11, "Max. length" );
   875         list->AddItemL( KItem11, objectData.iMaxLength );
   891         list->AddItemL( KItem11, metaData.iMaxHeapSize );
   876 
   892 
   877         _LIT( KItem12, "Debug Allocator Library" );
   893         _LIT( KItem12, "Debug Allocator Library" );
   878         list->AddItemYesNoL( KItem12, metaData.IsDebugAllocator() );
   894         list->AddItemYesNoL( KItem12, metaData.IsDebugAllocator() );
   879         }
   895         }
   880 
   896 
   881     return list;
   897     return list;
   882     }
   898     }
   883 
   899 
   884 
   900 
   885 EXPORT_C CMemSpyEngineOutputList* CMemSpyEngineHelperHeap::NewHeapSummaryExtendedLC( const TMemSpyHeapInfo& aInfo, const RArray<TMemSpyDriverFreeCell>* aFreeCells )
   901 EXPORT_C CMemSpyEngineOutputList* CMemSpyEngineHelperHeap::NewHeapSummaryExtendedLC( const TMemSpyHeapInfo& aInfo, const RArray<TMemSpyDriverCell>* aCells )
   886     {
   902 	{
   887     CMemSpyEngineOutputList* list = CMemSpyEngineOutputList::NewLC( iEngine.Sink() );
   903     CMemSpyEngineOutputList* list = CMemSpyEngineOutputList::NewLC( iEngine.Sink() );
   888     //
   904     //
   889     AppendMetaDataL( aInfo, *list );
   905     AppendMetaDataL( aInfo, *list );
   890     AppendObjectDataL( aInfo, *list );
       
   891     AppendStatisticsL( aInfo, *list );
   906     AppendStatisticsL( aInfo, *list );
   892     //
   907     //
   893     if  ( aFreeCells )
   908     if  ( aCells )
   894         {
   909         {
   895         AppendFreeCellsL( *aFreeCells, *list );
   910         AppendCellsL( *aCells, *list );
   896         }
   911         }
   897     //
   912     //
   898     return list;
   913     return list;
   899     }
   914     }
   900 
   915 
   901 
   916 
   902 //cigasto: not formatted - raw heap info 
   917 //cigasto: not formatted - raw heap info 
   903 EXPORT_C TMemSpyHeapData CMemSpyEngineHelperHeap::NewHeapRawInfo( const TMemSpyHeapInfo& aInfo )
   918 EXPORT_C TMemSpyHeapData CMemSpyEngineHelperHeap::NewHeapRawInfo( const TMemSpyHeapInfo& aInfo )
   904 	{
   919 	{
       
   920 	_LIT(KUnknown, "Unknown");
   905 	TMemSpyHeapData list;
   921 	TMemSpyHeapData list;
       
   922 	list.iType.Copy(KUnknown);
   906 
   923 
   907 	// Heap type	
   924 	// Heap type	
   908 	if ( aInfo.Type() == TMemSpyHeapInfo::ETypeUnknown )
   925 	if (aInfo.Type() != TMemSpyHeapInfo::ETypeUnknown)
   909 		{
       
   910 		_LIT( KItem0_Type_Unknown, "Unknown" );
       
   911 		list.iType.Append( KItem0_Type_Unknown );
       
   912 		}
       
   913 	else if ( aInfo.Type() == TMemSpyHeapInfo::ETypeRHeap )
       
   914 		{
   926 		{
   915 		const TMemSpyHeapInfoRHeap& rHeap = aInfo.AsRHeap();
   927 		const TMemSpyHeapInfoRHeap& rHeap = aInfo.AsRHeap();
   916 		const TMemSpyHeapMetaDataRHeap& metaData = rHeap.MetaData();
   928 		const TMemSpyHeapMetaDataRHeap& metaData = rHeap.MetaData();
   917 		const TMemSpyHeapObjectDataRHeap& objectData = rHeap.ObjectData();
       
   918 		const TMemSpyHeapStatisticsRHeap& statistics = rHeap.Statistics();
   929 		const TMemSpyHeapStatisticsRHeap& statistics = rHeap.Statistics();
   919 
   930 
   920 		_LIT( KItem0_Type_RHeap, "RHeap" );
   931 		_LIT(KRHeap, "RHeap");
   921 		list.iType.Append( KItem0_Type_RHeap );
   932 		_LIT(KRHybridHeap, "RHybridHeap");
   922 
   933 		switch (aInfo.Type())
   923 	    // Heap size is the size of the heap minus the size of the embedded (in-place) RHeap. 	    
   934 			{
   924 	    list.iSize = objectData.Size();
   935 			case TMemSpyHeapInfo::ETypeRHeap:
   925 	    list.iBaseAddress = (TUint) objectData.Base();	        
   936 				list.iType.Copy(KRHeap);
       
   937 				break;
       
   938 			case TMemSpyHeapInfo::ETypeRHybridHeap:
       
   939 				list.iType.Copy(KRHybridHeap);
       
   940 				break;
       
   941 			default:
       
   942 				break;
       
   943 			}
       
   944 
       
   945 	    // Heap size is the total amount of memory committed to the heap, which includes the size of the embedded (in-place) RHeap/RHybridHeap.
       
   946 	    list.iSize = metaData.iHeapSize;
       
   947 	    list.iBaseAddress = (TUint)metaData.iAllocatorAddress; // TODO we can't do the base address any more, allocator address is the closest thing
   926 	    list.iShared = metaData.IsSharedHeap();
   948 	    list.iShared = metaData.IsSharedHeap();
   927 	    list.iChunkSize = metaData.ChunkSize();
   949 	    list.iChunkSize = metaData.ChunkSize();
   928 	    list.iAllocationsCount = statistics.StatsAllocated().TypeCount();
   950 	    list.iAllocationsCount = statistics.StatsAllocated().TypeCount();
   929 	    list.iFreeCount = statistics.StatsFree().TypeCount();
   951 	    list.iFreeCount = statistics.StatsFree().TypeCount();
   930 	    list.iBiggestAllocation = statistics.StatsAllocated().LargestCellSize();
   952 	    list.iBiggestAllocation = statistics.StatsAllocated().LargestCellSize();
   931 	    list.iBiggestFree = statistics.StatsFree().LargestCellSize();
   953 	    list.iBiggestFree = statistics.StatsFree().LargestCellSize();
   932 	    list.iTotalAllocations =  statistics.StatsAllocated().TypeSize();	        
   954 	    list.iTotalAllocations =  statistics.StatsAllocated().TypeSize();	        
   933 	    list.iTotalFree =  statistics.StatsFree().TypeSize();
   955 	    list.iTotalFree =  statistics.StatsFree().TypeSize();
   934 	    list.iSlackFreeSpace = statistics.StatsFree().SlackSpaceCellSize();
   956 	    list.iSlackFreeSpace = statistics.StatsFree().SlackSpaceCellSize();
   935 	    list.iFragmentation = statistics.StatsFree().TypeSize() - statistics.StatsFree().SlackSpaceCellSize(); //to calculate percentage value use iSize as 100% value
   957 	    list.iFragmentation = statistics.StatsFree().TypeSize() - statistics.StatsFree().SlackSpaceCellSize(); //to calculate percentage value use iSize as 100% value
   936 	    list.iHeaderSizeA = metaData.HeaderSizeAllocated();
   958 	    list.iHeaderSizeA = 0; //metaData.HeaderSizeAllocated();
   937 	    list.iHeaderSizeF = metaData.HeaderSizeFree();
   959 	    list.iHeaderSizeF = 0; //metaData.HeaderSizeFree();
   938 	    TInt allocOverhead = metaData.HeaderSizeAllocated() * statistics.StatsAllocated().TypeCount();
   960 	    TInt allocOverhead = rHeap.Overhead(); //metaData.HeaderSizeAllocated() * statistics.StatsAllocated().TypeCount();
   939 	    list.iAllocationOverhead = allocOverhead;
   961 	    list.iAllocationOverhead = allocOverhead;
   940 	    TInt freeOverhead = metaData.HeaderSizeFree() * statistics.StatsFree().TypeCount();
   962 	    //TInt freeOverhead = metaData.HeaderSizeFree() * statistics.StatsFree().TypeCount();
   941 	    list.iFreeOverhead = freeOverhead;
   963 	    list.iFreeOverhead = 0; // TODO there is no way of calculating this
   942 	    list.iTotalOverhead = freeOverhead + allocOverhead;
   964 	    list.iTotalOverhead = allocOverhead; // freeOverhead + allocOverhead
   943 	    list.iOverhead = freeOverhead + allocOverhead; //to calculate percentage value use iSize as 100% value    
   965 	    list.iOverhead = allocOverhead; //freeOverhead + allocOverhead; //to calculate percentage value use iSize as 100% value    
   944 	    list.iMinLength = objectData.iMinLength;
   966 	    list.iMinLength = metaData.iMinHeapSize;
   945 	    list.iMaxLength = objectData.iMaxLength;
   967 	    list.iMaxLength = metaData.iMaxHeapSize;
   946 	    list.iDebugAllocatorLibrary = metaData.IsDebugAllocator();
   968 	    list.iDebugAllocatorLibrary = metaData.IsDebugAllocator();
   947 		}
   969 		}
   948 
   970 
   949 	return list;
   971 	return list;
   950 	}
   972 	}
   999     aList.AddItemL( KOverallCaption1 );
  1021     aList.AddItemL( KOverallCaption1 );
  1000     aList.AddUnderlineForPreviousItemL( '=', 0 );
  1022     aList.AddUnderlineForPreviousItemL( '=', 0 );
  1001 
  1023 
  1002     // Type
  1024     // Type
  1003     _LIT( KMetaData_Type,  "Type:" );
  1025     _LIT( KMetaData_Type,  "Type:" );
  1004     if ( aInfo.Type() != TMemSpyHeapInfo::ETypeRHeap )
  1026     if ( aInfo.Type() == TMemSpyHeapInfo::ETypeUnknown )
  1005         {
  1027         {
  1006         _LIT( KMetaData_Type_Unknown,  "Unknown" );
  1028         _LIT( KMetaData_Type_Unknown,  "Unknown" );
  1007         aList.AddItemL( KMetaData_Type, KMetaData_Type_Unknown );
  1029         aList.AddItemL( KMetaData_Type, KMetaData_Type_Unknown );
  1008         }
  1030         }
  1009     else
  1031     else
  1010         {
  1032         {
  1011         const TMemSpyHeapMetaDataRHeap& metaData = rHeap.MetaData();
  1033         const TMemSpyHeapMetaDataRHeap& metaData = rHeap.MetaData();
  1012     
  1034     
  1013         // Type
  1035         // Type
  1014         _LIT( KMetaData_Type_RHeap,  "Symbian OS RHeap" );
  1036         _LIT( KMetaData_Type_RHeap,  "Symbian OS RHeap" );
  1015         aList.AddItemL( KMetaData_Type, KMetaData_Type_RHeap );
  1037         _LIT( KMetaData_Type_RHybridHeap,  "Symbian OS RHybridHeap" );
       
  1038 		if (aInfo.Type() == TMemSpyHeapInfo::ETypeRHeap)
       
  1039 			{
       
  1040 	        aList.AddItemL( KMetaData_Type, KMetaData_Type_RHeap );
       
  1041 			}
       
  1042 		else
       
  1043 			{
       
  1044 			aList.AddItemL( KMetaData_Type, KMetaData_Type_RHybridHeap );
       
  1045 			}
  1016 
  1046 
  1017         // VTable
  1047         // VTable
  1018         _LIT( KMetaData_VTable,  "VTable:" );
  1048         //_LIT( KMetaData_VTable,  "VTable:" );
  1019         aList.AddItemHexL( KMetaData_VTable, metaData.VTable() );
  1049         //aList.AddItemHexL( KMetaData_VTable, metaData.VTable() );
  1020 
  1050 
  1021         // Object size
  1051         // Object size
  1022         _LIT( KMetaData_ObjectSize,  "Object Size:" );
  1052         //_LIT( KMetaData_ObjectSize,  "Object Size:" );
  1023         aList.AddItemL( KMetaData_ObjectSize, metaData.ClassSize() );
  1053         //aList.AddItemL( KMetaData_ObjectSize, metaData.ClassSize() );
  1024 
  1054 
  1025         // Chunk name
  1055         // Chunk name
  1026         _LIT( KMetaData_ChunkName,  "Chunk Name:" );
  1056         _LIT( KMetaData_ChunkName,  "Chunk Name:" );
  1027         TPtrC pChunkName( metaData.ChunkName() );
  1057         TPtrC pChunkName( metaData.ChunkName() );
  1028         aList.AddItemL( KMetaData_ChunkName, pChunkName );
  1058         aList.AddItemL( KMetaData_ChunkName, pChunkName );
  1037 
  1067 
  1038         // Debug allocator
  1068         // Debug allocator
  1039         _LIT( KMetaData_DebugAllocator,  "Debug Allocator:" );
  1069         _LIT( KMetaData_DebugAllocator,  "Debug Allocator:" );
  1040         aList.AddItemYesNoL( KMetaData_DebugAllocator, metaData.IsDebugAllocator() );
  1070         aList.AddItemYesNoL( KMetaData_DebugAllocator, metaData.IsDebugAllocator() );
  1041 
  1071 
  1042         // Cell header overhead (free cells)
       
  1043         _LIT( KMetaData_CellHeaderOverheadFree,  "Overhead (Free):" );
       
  1044         aList.AddItemL( KMetaData_CellHeaderOverheadFree, metaData.HeaderSizeFree() );
       
  1045 
       
  1046         // Cell header overhead (allocated cells)
       
  1047         _LIT( KMetaData_CellHeaderOverheadAlloc,  "Overhead (Alloc):" );
       
  1048         aList.AddItemL( KMetaData_CellHeaderOverheadAlloc, metaData.HeaderSizeAllocated() );
       
  1049 
       
  1050         // Shared Heap
  1072         // Shared Heap
  1051         _LIT( KMetaData_Shared,  "Shared:" );
  1073         _LIT( KMetaData_Shared,  "Shared:" );
  1052         aList.AddItemYesNoL( KMetaData_Shared, metaData.IsSharedHeap() );
  1074         aList.AddItemYesNoL( KMetaData_Shared, metaData.IsSharedHeap() );
  1053 
  1075 
  1054         // Add ROM info
  1076         // Add ROM info
  1056         }
  1078         }
  1057 
  1079 
  1058     aList.AddBlankItemL( 1 );
  1080     aList.AddBlankItemL( 1 );
  1059     }
  1081     }
  1060 
  1082 
  1061 
       
  1062 void CMemSpyEngineHelperHeap::AppendObjectDataL( const TMemSpyHeapInfo& aInfo, CMemSpyEngineOutputList& aList )
       
  1063     {
       
  1064     if ( aInfo.Type() == TMemSpyHeapInfo::ETypeRHeap )
       
  1065         {
       
  1066         const TMemSpyHeapInfoRHeap& rHeap = aInfo.AsRHeap();
       
  1067         const TMemSpyHeapObjectDataRHeap& objectData = rHeap.ObjectData();
       
  1068 
       
  1069         // Make caption
       
  1070         _LIT( KOverallCaption1, "RAllocator" );
       
  1071         aList.AddItemL( KOverallCaption1 );
       
  1072         aList.AddUnderlineForPreviousItemL( '=', 0 );
       
  1073 
       
  1074         // RAllocator
       
  1075         _LIT( KObjectData_RAllocator_iAccessCount,  "RAllocator::iAccessCount" );
       
  1076         aList.AddItemL( KObjectData_RAllocator_iAccessCount, objectData.iAccessCount );
       
  1077         _LIT( KObjectData_RAllocator_iHandleCount,  "RAllocator::iHandleCount" );
       
  1078         aList.AddItemL( KObjectData_RAllocator_iHandleCount, objectData.iHandleCount );
       
  1079         _LIT( KObjectData_RAllocator_iHandles,  "RAllocator::iHandles" );
       
  1080         aList.AddItemL( KObjectData_RAllocator_iHandles, objectData.iHandles );
       
  1081         _LIT( KObjectData_RAllocator_iFlags,  "RAllocator::iFlags" );
       
  1082         aList.AddItemHexL( KObjectData_RAllocator_iFlags, objectData.iFlags );
       
  1083         _LIT( KObjectData_RAllocator_iCellCount,  "RAllocator::iCellCount" );
       
  1084         aList.AddItemL( KObjectData_RAllocator_iCellCount, objectData.iCellCount );
       
  1085         _LIT( KObjectData_RAllocator_iTotalAllocSize,  "RAllocator::iTotalAllocSize" );
       
  1086         aList.AddItemL( KObjectData_RAllocator_iTotalAllocSize, objectData.iTotalAllocSize );
       
  1087 
       
  1088         aList.AddBlankItemL( 1 );
       
  1089 
       
  1090         // Make caption
       
  1091         _LIT( KOverallCaption2, "RHeap" );
       
  1092         aList.AddItemL( KOverallCaption2 );
       
  1093         aList.AddUnderlineForPreviousItemL( '=', 0 );
       
  1094 
       
  1095         // RHeap
       
  1096         _LIT( KObjectData_RHeap_iMinLength,  "RHeap::iMinLength" );
       
  1097         aList.AddItemL( KObjectData_RHeap_iMinLength, objectData.iMinLength );
       
  1098         _LIT( KObjectData_RHeap_iMaxLength,  "RHeap::iMaxLength" );
       
  1099         aList.AddItemL( KObjectData_RHeap_iMaxLength, objectData.iMaxLength );
       
  1100         _LIT( KObjectData_RHeap_iOffset,  "RHeap::iOffset" );
       
  1101         aList.AddItemL( KObjectData_RHeap_iOffset, objectData.iOffset );
       
  1102         _LIT( KObjectData_RHeap_iGrowBy,  "RHeap::iGrowBy" );
       
  1103         aList.AddItemL( KObjectData_RHeap_iGrowBy, objectData.iGrowBy );
       
  1104         _LIT( KObjectData_RHeap_iChunkHandle,  "RHeap::iChunkHandle" );
       
  1105         aList.AddItemHexL( KObjectData_RHeap_iChunkHandle, objectData.iChunkHandle );
       
  1106         _LIT( KObjectData_RHeap_iBase,  "RHeap::iBase" );
       
  1107         aList.AddItemL( KObjectData_RHeap_iBase, objectData.iBase );
       
  1108         _LIT( KObjectData_RHeap_iTop,  "RHeap::iTop" );
       
  1109         aList.AddItemL( KObjectData_RHeap_iTop, objectData.iTop );
       
  1110         _LIT( KObjectData_RHeap_iAlign,  "RHeap::iAlign" );
       
  1111         aList.AddItemL( KObjectData_RHeap_iAlign, objectData.iAlign );
       
  1112         _LIT( KObjectData_RHeap_iMinCell,  "RHeap::iMinCell" );
       
  1113         aList.AddItemL( KObjectData_RHeap_iMinCell, objectData.iMinCell );
       
  1114         _LIT( KObjectData_RHeap_iPageSize,  "RHeap::iPageSize" );
       
  1115         aList.AddItemL( KObjectData_RHeap_iPageSize, objectData.iPageSize );
       
  1116         _LIT( KObjectData_RHeap_iFree_next,  "RHeap::iFree.next" );
       
  1117         aList.AddItemL( KObjectData_RHeap_iFree_next, objectData.iFree.next );
       
  1118         _LIT( KObjectData_RHeap_iFree_len,  "RHeap::iFree.len" );
       
  1119         aList.AddItemL( KObjectData_RHeap_iFree_len, objectData.iFree.len );
       
  1120         _LIT( KObjectData_RHeap_iNestingLevel,  "RHeap::iNestingLevel" );
       
  1121         aList.AddItemL( KObjectData_RHeap_iNestingLevel, objectData.iNestingLevel );
       
  1122         _LIT( KObjectData_RHeap_iAllocCount,  "RHeap::iAllocCount" );
       
  1123         aList.AddItemL( KObjectData_RHeap_iAllocCount, objectData.iAllocCount );
       
  1124         _LIT( KObjectData_RHeap_iFailType,  "RHeap::iFailType" );
       
  1125         aList.AddItemL( KObjectData_RHeap_iFailType, (TInt) objectData.iFailType );
       
  1126         _LIT( KObjectData_RHeap_iFailRate,  "RHeap::iFailRate" );
       
  1127         aList.AddItemL( KObjectData_RHeap_iFailRate, objectData.iFailRate );
       
  1128         _LIT( KObjectData_RHeap_iFailed,  "RHeap::iFailed" );
       
  1129         aList.AddItemTrueFalseL( KObjectData_RHeap_iFailed, objectData.iFailed );
       
  1130         _LIT( KObjectData_RHeap_iFailAllocCount,  "RHeap::iFailAllocCount" );
       
  1131         aList.AddItemL( KObjectData_RHeap_iFailAllocCount, objectData.iFailAllocCount );
       
  1132         _LIT( KObjectData_RHeap_iRand,  "RHeap::iRand" );
       
  1133         aList.AddItemL( KObjectData_RHeap_iRand, objectData.iRand );
       
  1134         _LIT( KObjectData_RHeap_iTestData,  "RHeap::iTestData" );
       
  1135         aList.AddItemL( KObjectData_RHeap_iTestData, objectData.iTestData );
       
  1136 
       
  1137         aList.AddBlankItemL( 1 );
       
  1138         }
       
  1139     }
       
  1140 
       
  1141 
       
  1142 void CMemSpyEngineHelperHeap::AppendStatisticsL( const TMemSpyHeapInfo& aInfo, CMemSpyEngineOutputList& aList )
  1083 void CMemSpyEngineHelperHeap::AppendStatisticsL( const TMemSpyHeapInfo& aInfo, CMemSpyEngineOutputList& aList )
  1143     {
  1084     {
  1144     if ( aInfo.Type() == TMemSpyHeapInfo::ETypeRHeap )
  1085     if (aInfo.Type() != TMemSpyHeapInfo::ETypeUnknown)
  1145         {
  1086         {
  1146         const TMemSpyHeapInfoRHeap& rHeap = aInfo.AsRHeap();
  1087         const TMemSpyHeapInfoRHeap& rHeap = aInfo.AsRHeap();
  1147         const TMemSpyHeapStatisticsRHeap& rHeapStats = rHeap.Statistics();
  1088         const TMemSpyHeapStatisticsRHeap& rHeapStats = rHeap.Statistics();
  1148 
  1089 
  1149         // Shared captions
  1090         // Shared captions
  1159 
  1100 
  1160         aList.AddItemL( KStatsData_CellCount, rHeapStats.StatsFree().TypeCount() );
  1101         aList.AddItemL( KStatsData_CellCount, rHeapStats.StatsFree().TypeCount() );
  1161         aList.AddItemL( KStatsData_CellSize, rHeapStats.StatsFree().TypeSize() );
  1102         aList.AddItemL( KStatsData_CellSize, rHeapStats.StatsFree().TypeSize() );
  1162         aList.AddItemL( KStatsData_LargestCellAddress, rHeapStats.StatsFree().LargestCellAddress() );
  1103         aList.AddItemL( KStatsData_LargestCellAddress, rHeapStats.StatsFree().LargestCellAddress() );
  1163         aList.AddItemL( KStatsData_LargestCellSize, rHeapStats.StatsFree().LargestCellSize() );
  1104         aList.AddItemL( KStatsData_LargestCellSize, rHeapStats.StatsFree().LargestCellSize() );
  1164         _LIT( KStatsData_Free_SlackCellAddress,  "Slack:" );
  1105 		if (aInfo.Type() == TMemSpyHeapInfo::ETypeRHeap)
  1165         aList.AddItemL( KStatsData_Free_SlackCellAddress, rHeapStats.StatsFree().SlackSpaceCellAddress() );
  1106 			{
  1166         _LIT( KStatsData_Free_SlackCellSize,  "Slack size:" );
  1107 			_LIT( KStatsData_Free_SlackCellAddress,  "Slack:" );
  1167         aList.AddItemL( KStatsData_Free_SlackCellSize, rHeapStats.StatsFree().SlackSpaceCellSize() );
  1108 			aList.AddItemL( KStatsData_Free_SlackCellAddress, rHeapStats.StatsFree().SlackSpaceCellAddress() );
       
  1109 			_LIT( KStatsData_Free_SlackCellSize,  "Slack size:" );
       
  1110 			aList.AddItemL( KStatsData_Free_SlackCellSize, rHeapStats.StatsFree().SlackSpaceCellSize() );
       
  1111 			}
  1168         _LIT( KStatsData_Free_Checksum,  "Checksum:" );
  1112         _LIT( KStatsData_Free_Checksum,  "Checksum:" );
  1169         aList.AddItemHexL( KStatsData_Free_Checksum, rHeapStats.StatsFree().Checksum() );
  1113         aList.AddItemHexL( KStatsData_Free_Checksum, rHeapStats.StatsFree().Checksum() );
  1170 
  1114 
  1171         aList.AddBlankItemL( 1 );
  1115         aList.AddBlankItemL( 1 );
  1172 
  1116 
  1179         aList.AddItemL( KStatsData_CellSize, rHeapStats.StatsAllocated().TypeSize() );
  1123         aList.AddItemL( KStatsData_CellSize, rHeapStats.StatsAllocated().TypeSize() );
  1180         aList.AddItemL( KStatsData_LargestCellAddress, rHeapStats.StatsAllocated().LargestCellAddress() );
  1124         aList.AddItemL( KStatsData_LargestCellAddress, rHeapStats.StatsAllocated().LargestCellAddress() );
  1181         aList.AddItemL( KStatsData_LargestCellSize, rHeapStats.StatsAllocated().LargestCellSize() );
  1125         aList.AddItemL( KStatsData_LargestCellSize, rHeapStats.StatsAllocated().LargestCellSize() );
  1182 
  1126 
  1183         aList.AddBlankItemL( 1 );
  1127         aList.AddBlankItemL( 1 );
  1184 
  1128          }
  1185         // Common
  1129     }
  1186         _LIT( KOverallCaption3, "Common Statistics" );
  1130 
  1187         aList.AddItemL( KOverallCaption3 );
  1131 
  1188         aList.AddUnderlineForPreviousItemL( '=', 0 );
  1132 void CMemSpyEngineHelperHeap::AppendCellsL(const RArray<TMemSpyDriverCell>& aCells, CMemSpyEngineOutputList& aList)
  1189 
  1133     {
  1190         _LIT( KStatsData_Common_TotalCellCount,  "Total cell count:" );
  1134     // For reasons that may or may not turn out to be sensible, we separate free and allocated cells in the output data
  1191         aList.AddItemL( KStatsData_Common_TotalCellCount, rHeapStats.StatsCommon().TotalCellCount() );
  1135 
  1192 
       
  1193         _LIT( KStatsData_Common_TotalSize,  "Total cell size:" );
       
  1194         aList.AddItemL( KStatsData_Common_TotalSize, rHeapStats.StatsAllocated().TypeSize() + rHeapStats.StatsFree().TypeSize() );
       
  1195 
       
  1196         aList.AddBlankItemL( 1 );
       
  1197         }
       
  1198     }
       
  1199 
       
  1200 
       
  1201 void CMemSpyEngineHelperHeap::AppendFreeCellsL( const RArray<TMemSpyDriverFreeCell>& aFreeCells, CMemSpyEngineOutputList& aList )
       
  1202     {
       
  1203     // Free space
       
  1204     _LIT( KOverallCaption1, "Free Cell List" );
  1136     _LIT( KOverallCaption1, "Free Cell List" );
  1205     aList.AddItemL( KOverallCaption1 );
  1137     aList.AddItemL( KOverallCaption1 );
  1206     aList.AddUnderlineForPreviousItemL( '=', 0 );
  1138     aList.AddUnderlineForPreviousItemL( '=', 0 );
  1207 
  1139 
  1208     TBuf<128> caption;
  1140     TBuf<128> caption;
  1209     _LIT( KCaptionFormat, "FC %04d" );
  1141     _LIT( KCaptionFormat, "FC %04d" );
  1210     _LIT( KValueFormat, "0x%08x %8d %1d" );
  1142     _LIT( KValueFormat, "0x%08x %8d %d" );
  1211 
  1143 
  1212     const TInt count = aFreeCells.Count();
  1144 	TBool foundAllocatedCells = EFalse;
       
  1145     const TInt count = aCells.Count();
  1213     for( TInt i=0; i<count; i++ )
  1146     for( TInt i=0; i<count; i++ )
  1214         {
  1147         {
  1215         const TMemSpyDriverFreeCell& cell = aFreeCells[ i ];
  1148         const TMemSpyDriverCell& cell = aCells[ i ];
  1216         caption.Format( KCaptionFormat, i + 1 );
  1149 		if (cell.iType & EMemSpyDriverAllocatedCellMask)
  1217         aList.AddItemFormatL( caption, KValueFormat, cell.iAddress, cell.iLength, cell.iType );
  1150 			{
  1218         }
  1151 			foundAllocatedCells = ETrue;
  1219     }
  1152 			}
  1220 
  1153 		else if (cell.iType & EMemSpyDriverFreeCellMask)
       
  1154 			{
       
  1155 	        caption.Format( KCaptionFormat, i + 1 );
       
  1156 		    aList.AddItemFormatL( caption, KValueFormat, cell.iAddress, cell.iLength, cell.iType );
       
  1157 			}
       
  1158         }
       
  1159 
       
  1160 	if (foundAllocatedCells)
       
  1161 		{
       
  1162         aList.AddBlankItemL( 1 );
       
  1163 		_LIT( KOverallCaption1, "Allocated Cell List" );
       
  1164 		aList.AddItemL( KOverallCaption1 );
       
  1165 		aList.AddUnderlineForPreviousItemL( '=', 0 );
       
  1166 
       
  1167 		TBuf<128> caption;
       
  1168 		_LIT( KCaptionFormat, "AC %04d" );
       
  1169 		_LIT( KValueFormat, "0x%08x %8d %d" );
       
  1170 
       
  1171 		for (TInt i = 0; i < count; i++)
       
  1172 			{
       
  1173 			const TMemSpyDriverCell& cell = aCells[ i ];
       
  1174 			if (cell.iType & EMemSpyDriverAllocatedCellMask)
       
  1175 				{
       
  1176 				caption.Format( KCaptionFormat, i + 1 );
       
  1177 				aList.AddItemFormatL( caption, KValueFormat, cell.iAddress, cell.iLength, cell.iType );
       
  1178 				}
       
  1179 			}
       
  1180 		}
       
  1181     }
  1221 
  1182 
  1222 void CMemSpyEngineHelperHeap::UpdateSharedHeapInfoL( const TProcessId& aProcess, const TThreadId& aThread, TMemSpyHeapInfo& aInfo )
  1183 void CMemSpyEngineHelperHeap::UpdateSharedHeapInfoL( const TProcessId& aProcess, const TThreadId& aThread, TMemSpyHeapInfo& aInfo )
  1223     {
  1184     {
  1224     RArray<TThreadId> threads;
  1185     RArray<TThreadId> threads;
  1225     CleanupClosePushL( threads );
  1186     CleanupClosePushL( threads );