memspy/Engine/Source/Helpers/MemSpyEngineHelperHeap.cpp
branchRCL_3
changeset 49 7fdc9a71d314
parent 44 52e343bb8f80
child 59 8ad140f3dd41
equal deleted inserted replaced
46:e26895079d7c 49:7fdc9a71d314
    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                                          rHeapMetaData.iAllocatorAddress,
   460                                          rHeapObjectData.Size(),
   475                                          rHeapMetaData.iHeapSize,
   461                                          rHeapObjectData.iMinLength,
   476                                          rHeapMetaData.iMinHeapSize,
   462                                          rHeapObjectData.iMaxLength,
   477                                          rHeapMetaData.iMaxHeapSize,
   463                                          rHeapObjectData.iFree.next,
   478                                          NULL, // there's no longer a free list so we can't return the next ptr
   464                                          rHeapObjectData.iFree.len,
   479                                          0, // there's no longer a free list so we can't return it's length
   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                                          rHeapStats.StatsAllocated().TypeCount(),
   471                                          rHeapObjectData.iMinCell,
   486                                          0, // min cell no longer makes sense
   472                                          rHeapObjectData.iTotalAllocSize,
   487                                          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 
       
   917 //cigasto: not formatted - raw heap info 
       
   918 EXPORT_C TMemSpyHeapData CMemSpyEngineHelperHeap::NewHeapRawInfo( const TMemSpyHeapInfo& aInfo )
       
   919 	{
       
   920 	_LIT(KUnknown, "Unknown");
       
   921 	TMemSpyHeapData list;
       
   922 	list.iType.Copy(KUnknown);
       
   923 
       
   924 	// Heap type	
       
   925 	if (aInfo.Type() != TMemSpyHeapInfo::ETypeUnknown)
       
   926 		{
       
   927 		const TMemSpyHeapInfoRHeap& rHeap = aInfo.AsRHeap();
       
   928 		const TMemSpyHeapMetaDataRHeap& metaData = rHeap.MetaData();
       
   929 		const TMemSpyHeapStatisticsRHeap& statistics = rHeap.Statistics();
       
   930 
       
   931 		_LIT(KRHeap, "RHeap");
       
   932 		_LIT(KRHybridHeap, "RHybridHeap");
       
   933 		switch (aInfo.Type())
       
   934 			{
       
   935 			case TMemSpyHeapInfo::ETypeRHeap:
       
   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
       
   948 	    list.iShared = metaData.IsSharedHeap();
       
   949 	    list.iChunkSize = metaData.ChunkSize();
       
   950 	    list.iAllocationsCount = statistics.StatsAllocated().TypeCount();
       
   951 	    list.iFreeCount = statistics.StatsFree().TypeCount();
       
   952 	    list.iBiggestAllocation = statistics.StatsAllocated().LargestCellSize();
       
   953 	    list.iBiggestFree = statistics.StatsFree().LargestCellSize();
       
   954 	    list.iTotalAllocations =  statistics.StatsAllocated().TypeSize();	        
       
   955 	    list.iTotalFree =  statistics.StatsFree().TypeSize();
       
   956 	    list.iSlackFreeSpace = statistics.StatsFree().SlackSpaceCellSize();
       
   957 	    list.iFragmentation = statistics.StatsFree().TypeSize() - statistics.StatsFree().SlackSpaceCellSize(); //to calculate percentage value use iSize as 100% value
       
   958 	    list.iHeaderSizeA = 0; //metaData.HeaderSizeAllocated();
       
   959 	    list.iHeaderSizeF = 0; //metaData.HeaderSizeFree();
       
   960 	    TInt allocOverhead = rHeap.Overhead(); //metaData.HeaderSizeAllocated() * statistics.StatsAllocated().TypeCount();
       
   961 	    list.iAllocationOverhead = allocOverhead;
       
   962 	    //TInt freeOverhead = metaData.HeaderSizeFree() * statistics.StatsFree().TypeCount();
       
   963 	    list.iFreeOverhead = 0; // TODO there is no way of calculating this
       
   964 	    list.iTotalOverhead = allocOverhead; // freeOverhead + allocOverhead
       
   965 	    list.iOverhead = allocOverhead; //freeOverhead + allocOverhead; //to calculate percentage value use iSize as 100% value    
       
   966 	    list.iMinLength = metaData.iMinHeapSize;
       
   967 	    list.iMaxLength = metaData.iMaxHeapSize;
       
   968 	    list.iDebugAllocatorLibrary = metaData.IsDebugAllocator();
       
   969 		}
       
   970 
       
   971 	return list;
       
   972 	}
   902 
   973 
   903 
   974 
   904 
   975 
   905 
   976 
   906 
   977 
   950     aList.AddItemL( KOverallCaption1 );
  1021     aList.AddItemL( KOverallCaption1 );
   951     aList.AddUnderlineForPreviousItemL( '=', 0 );
  1022     aList.AddUnderlineForPreviousItemL( '=', 0 );
   952 
  1023 
   953     // Type
  1024     // Type
   954     _LIT( KMetaData_Type,  "Type:" );
  1025     _LIT( KMetaData_Type,  "Type:" );
   955     if ( aInfo.Type() != TMemSpyHeapInfo::ETypeRHeap )
  1026     if ( aInfo.Type() == TMemSpyHeapInfo::ETypeUnknown )
   956         {
  1027         {
   957         _LIT( KMetaData_Type_Unknown,  "Unknown" );
  1028         _LIT( KMetaData_Type_Unknown,  "Unknown" );
   958         aList.AddItemL( KMetaData_Type, KMetaData_Type_Unknown );
  1029         aList.AddItemL( KMetaData_Type, KMetaData_Type_Unknown );
   959         }
  1030         }
   960     else
  1031     else
   961         {
  1032         {
   962         const TMemSpyHeapMetaDataRHeap& metaData = rHeap.MetaData();
  1033         const TMemSpyHeapMetaDataRHeap& metaData = rHeap.MetaData();
   963     
  1034     
   964         // Type
  1035         // Type
   965         _LIT( KMetaData_Type_RHeap,  "Symbian OS RHeap" );
  1036         _LIT( KMetaData_Type_RHeap,  "Symbian OS RHeap" );
   966         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 			}
   967 
  1046 
   968         // VTable
  1047         // VTable
   969         _LIT( KMetaData_VTable,  "VTable:" );
  1048         //_LIT( KMetaData_VTable,  "VTable:" );
   970         aList.AddItemHexL( KMetaData_VTable, metaData.VTable() );
  1049         //aList.AddItemHexL( KMetaData_VTable, metaData.VTable() );
   971 
  1050 
   972         // Object size
  1051         // Object size
   973         _LIT( KMetaData_ObjectSize,  "Object Size:" );
  1052         //_LIT( KMetaData_ObjectSize,  "Object Size:" );
   974         aList.AddItemL( KMetaData_ObjectSize, metaData.ClassSize() );
  1053         //aList.AddItemL( KMetaData_ObjectSize, metaData.ClassSize() );
   975 
  1054 
   976         // Chunk name
  1055         // Chunk name
   977         _LIT( KMetaData_ChunkName,  "Chunk Name:" );
  1056         _LIT( KMetaData_ChunkName,  "Chunk Name:" );
   978         TPtrC pChunkName( metaData.ChunkName() );
  1057         TPtrC pChunkName( metaData.ChunkName() );
   979         aList.AddItemL( KMetaData_ChunkName, pChunkName );
  1058         aList.AddItemL( KMetaData_ChunkName, pChunkName );
   988 
  1067 
   989         // Debug allocator
  1068         // Debug allocator
   990         _LIT( KMetaData_DebugAllocator,  "Debug Allocator:" );
  1069         _LIT( KMetaData_DebugAllocator,  "Debug Allocator:" );
   991         aList.AddItemYesNoL( KMetaData_DebugAllocator, metaData.IsDebugAllocator() );
  1070         aList.AddItemYesNoL( KMetaData_DebugAllocator, metaData.IsDebugAllocator() );
   992 
  1071 
   993         // Cell header overhead (free cells)
       
   994         _LIT( KMetaData_CellHeaderOverheadFree,  "Overhead (Free):" );
       
   995         aList.AddItemL( KMetaData_CellHeaderOverheadFree, metaData.HeaderSizeFree() );
       
   996 
       
   997         // Cell header overhead (allocated cells)
       
   998         _LIT( KMetaData_CellHeaderOverheadAlloc,  "Overhead (Alloc):" );
       
   999         aList.AddItemL( KMetaData_CellHeaderOverheadAlloc, metaData.HeaderSizeAllocated() );
       
  1000 
       
  1001         // Shared Heap
  1072         // Shared Heap
  1002         _LIT( KMetaData_Shared,  "Shared:" );
  1073         _LIT( KMetaData_Shared,  "Shared:" );
  1003         aList.AddItemYesNoL( KMetaData_Shared, metaData.IsSharedHeap() );
  1074         aList.AddItemYesNoL( KMetaData_Shared, metaData.IsSharedHeap() );
  1004 
  1075 
  1005         // Add ROM info
  1076         // Add ROM info
  1007         }
  1078         }
  1008 
  1079 
  1009     aList.AddBlankItemL( 1 );
  1080     aList.AddBlankItemL( 1 );
  1010     }
  1081     }
  1011 
  1082 
  1012 
       
  1013 void CMemSpyEngineHelperHeap::AppendObjectDataL( const TMemSpyHeapInfo& aInfo, CMemSpyEngineOutputList& aList )
       
  1014     {
       
  1015     if ( aInfo.Type() == TMemSpyHeapInfo::ETypeRHeap )
       
  1016         {
       
  1017         const TMemSpyHeapInfoRHeap& rHeap = aInfo.AsRHeap();
       
  1018         const TMemSpyHeapObjectDataRHeap& objectData = rHeap.ObjectData();
       
  1019 
       
  1020         // Make caption
       
  1021         _LIT( KOverallCaption1, "RAllocator" );
       
  1022         aList.AddItemL( KOverallCaption1 );
       
  1023         aList.AddUnderlineForPreviousItemL( '=', 0 );
       
  1024 
       
  1025         // RAllocator
       
  1026         _LIT( KObjectData_RAllocator_iAccessCount,  "RAllocator::iAccessCount" );
       
  1027         aList.AddItemL( KObjectData_RAllocator_iAccessCount, objectData.iAccessCount );
       
  1028         _LIT( KObjectData_RAllocator_iHandleCount,  "RAllocator::iHandleCount" );
       
  1029         aList.AddItemL( KObjectData_RAllocator_iHandleCount, objectData.iHandleCount );
       
  1030         _LIT( KObjectData_RAllocator_iHandles,  "RAllocator::iHandles" );
       
  1031         aList.AddItemL( KObjectData_RAllocator_iHandles, objectData.iHandles );
       
  1032         _LIT( KObjectData_RAllocator_iFlags,  "RAllocator::iFlags" );
       
  1033         aList.AddItemHexL( KObjectData_RAllocator_iFlags, objectData.iFlags );
       
  1034         _LIT( KObjectData_RAllocator_iCellCount,  "RAllocator::iCellCount" );
       
  1035         aList.AddItemL( KObjectData_RAllocator_iCellCount, objectData.iCellCount );
       
  1036         _LIT( KObjectData_RAllocator_iTotalAllocSize,  "RAllocator::iTotalAllocSize" );
       
  1037         aList.AddItemL( KObjectData_RAllocator_iTotalAllocSize, objectData.iTotalAllocSize );
       
  1038 
       
  1039         aList.AddBlankItemL( 1 );
       
  1040 
       
  1041         // Make caption
       
  1042         _LIT( KOverallCaption2, "RHeap" );
       
  1043         aList.AddItemL( KOverallCaption2 );
       
  1044         aList.AddUnderlineForPreviousItemL( '=', 0 );
       
  1045 
       
  1046         // RHeap
       
  1047         _LIT( KObjectData_RHeap_iMinLength,  "RHeap::iMinLength" );
       
  1048         aList.AddItemL( KObjectData_RHeap_iMinLength, objectData.iMinLength );
       
  1049         _LIT( KObjectData_RHeap_iMaxLength,  "RHeap::iMaxLength" );
       
  1050         aList.AddItemL( KObjectData_RHeap_iMaxLength, objectData.iMaxLength );
       
  1051         _LIT( KObjectData_RHeap_iOffset,  "RHeap::iOffset" );
       
  1052         aList.AddItemL( KObjectData_RHeap_iOffset, objectData.iOffset );
       
  1053         _LIT( KObjectData_RHeap_iGrowBy,  "RHeap::iGrowBy" );
       
  1054         aList.AddItemL( KObjectData_RHeap_iGrowBy, objectData.iGrowBy );
       
  1055         _LIT( KObjectData_RHeap_iChunkHandle,  "RHeap::iChunkHandle" );
       
  1056         aList.AddItemHexL( KObjectData_RHeap_iChunkHandle, objectData.iChunkHandle );
       
  1057         _LIT( KObjectData_RHeap_iBase,  "RHeap::iBase" );
       
  1058         aList.AddItemL( KObjectData_RHeap_iBase, objectData.iBase );
       
  1059         _LIT( KObjectData_RHeap_iTop,  "RHeap::iTop" );
       
  1060         aList.AddItemL( KObjectData_RHeap_iTop, objectData.iTop );
       
  1061         _LIT( KObjectData_RHeap_iAlign,  "RHeap::iAlign" );
       
  1062         aList.AddItemL( KObjectData_RHeap_iAlign, objectData.iAlign );
       
  1063         _LIT( KObjectData_RHeap_iMinCell,  "RHeap::iMinCell" );
       
  1064         aList.AddItemL( KObjectData_RHeap_iMinCell, objectData.iMinCell );
       
  1065         _LIT( KObjectData_RHeap_iPageSize,  "RHeap::iPageSize" );
       
  1066         aList.AddItemL( KObjectData_RHeap_iPageSize, objectData.iPageSize );
       
  1067         _LIT( KObjectData_RHeap_iFree_next,  "RHeap::iFree.next" );
       
  1068         aList.AddItemL( KObjectData_RHeap_iFree_next, objectData.iFree.next );
       
  1069         _LIT( KObjectData_RHeap_iFree_len,  "RHeap::iFree.len" );
       
  1070         aList.AddItemL( KObjectData_RHeap_iFree_len, objectData.iFree.len );
       
  1071         _LIT( KObjectData_RHeap_iNestingLevel,  "RHeap::iNestingLevel" );
       
  1072         aList.AddItemL( KObjectData_RHeap_iNestingLevel, objectData.iNestingLevel );
       
  1073         _LIT( KObjectData_RHeap_iAllocCount,  "RHeap::iAllocCount" );
       
  1074         aList.AddItemL( KObjectData_RHeap_iAllocCount, objectData.iAllocCount );
       
  1075         _LIT( KObjectData_RHeap_iFailType,  "RHeap::iFailType" );
       
  1076         aList.AddItemL( KObjectData_RHeap_iFailType, (TInt) objectData.iFailType );
       
  1077         _LIT( KObjectData_RHeap_iFailRate,  "RHeap::iFailRate" );
       
  1078         aList.AddItemL( KObjectData_RHeap_iFailRate, objectData.iFailRate );
       
  1079         _LIT( KObjectData_RHeap_iFailed,  "RHeap::iFailed" );
       
  1080         aList.AddItemTrueFalseL( KObjectData_RHeap_iFailed, objectData.iFailed );
       
  1081         _LIT( KObjectData_RHeap_iFailAllocCount,  "RHeap::iFailAllocCount" );
       
  1082         aList.AddItemL( KObjectData_RHeap_iFailAllocCount, objectData.iFailAllocCount );
       
  1083         _LIT( KObjectData_RHeap_iRand,  "RHeap::iRand" );
       
  1084         aList.AddItemL( KObjectData_RHeap_iRand, objectData.iRand );
       
  1085         _LIT( KObjectData_RHeap_iTestData,  "RHeap::iTestData" );
       
  1086         aList.AddItemL( KObjectData_RHeap_iTestData, objectData.iTestData );
       
  1087 
       
  1088         aList.AddBlankItemL( 1 );
       
  1089         }
       
  1090     }
       
  1091 
       
  1092 
       
  1093 void CMemSpyEngineHelperHeap::AppendStatisticsL( const TMemSpyHeapInfo& aInfo, CMemSpyEngineOutputList& aList )
  1083 void CMemSpyEngineHelperHeap::AppendStatisticsL( const TMemSpyHeapInfo& aInfo, CMemSpyEngineOutputList& aList )
  1094     {
  1084     {
  1095     if ( aInfo.Type() == TMemSpyHeapInfo::ETypeRHeap )
  1085     if (aInfo.Type() != TMemSpyHeapInfo::ETypeUnknown)
  1096         {
  1086         {
  1097         const TMemSpyHeapInfoRHeap& rHeap = aInfo.AsRHeap();
  1087         const TMemSpyHeapInfoRHeap& rHeap = aInfo.AsRHeap();
  1098         const TMemSpyHeapStatisticsRHeap& rHeapStats = rHeap.Statistics();
  1088         const TMemSpyHeapStatisticsRHeap& rHeapStats = rHeap.Statistics();
  1099 
  1089 
  1100         // Shared captions
  1090         // Shared captions
  1110 
  1100 
  1111         aList.AddItemL( KStatsData_CellCount, rHeapStats.StatsFree().TypeCount() );
  1101         aList.AddItemL( KStatsData_CellCount, rHeapStats.StatsFree().TypeCount() );
  1112         aList.AddItemL( KStatsData_CellSize, rHeapStats.StatsFree().TypeSize() );
  1102         aList.AddItemL( KStatsData_CellSize, rHeapStats.StatsFree().TypeSize() );
  1113         aList.AddItemL( KStatsData_LargestCellAddress, rHeapStats.StatsFree().LargestCellAddress() );
  1103         aList.AddItemL( KStatsData_LargestCellAddress, rHeapStats.StatsFree().LargestCellAddress() );
  1114         aList.AddItemL( KStatsData_LargestCellSize, rHeapStats.StatsFree().LargestCellSize() );
  1104         aList.AddItemL( KStatsData_LargestCellSize, rHeapStats.StatsFree().LargestCellSize() );
  1115         _LIT( KStatsData_Free_SlackCellAddress,  "Slack:" );
  1105 		if (aInfo.Type() == TMemSpyHeapInfo::ETypeRHeap)
  1116         aList.AddItemL( KStatsData_Free_SlackCellAddress, rHeapStats.StatsFree().SlackSpaceCellAddress() );
  1106 			{
  1117         _LIT( KStatsData_Free_SlackCellSize,  "Slack size:" );
  1107 			_LIT( KStatsData_Free_SlackCellAddress,  "Slack:" );
  1118         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 			}
  1119         _LIT( KStatsData_Free_Checksum,  "Checksum:" );
  1112         _LIT( KStatsData_Free_Checksum,  "Checksum:" );
  1120         aList.AddItemHexL( KStatsData_Free_Checksum, rHeapStats.StatsFree().Checksum() );
  1113         aList.AddItemHexL( KStatsData_Free_Checksum, rHeapStats.StatsFree().Checksum() );
  1121 
  1114 
  1122         aList.AddBlankItemL( 1 );
  1115         aList.AddBlankItemL( 1 );
  1123 
  1116 
  1130         aList.AddItemL( KStatsData_CellSize, rHeapStats.StatsAllocated().TypeSize() );
  1123         aList.AddItemL( KStatsData_CellSize, rHeapStats.StatsAllocated().TypeSize() );
  1131         aList.AddItemL( KStatsData_LargestCellAddress, rHeapStats.StatsAllocated().LargestCellAddress() );
  1124         aList.AddItemL( KStatsData_LargestCellAddress, rHeapStats.StatsAllocated().LargestCellAddress() );
  1132         aList.AddItemL( KStatsData_LargestCellSize, rHeapStats.StatsAllocated().LargestCellSize() );
  1125         aList.AddItemL( KStatsData_LargestCellSize, rHeapStats.StatsAllocated().LargestCellSize() );
  1133 
  1126 
  1134         aList.AddBlankItemL( 1 );
  1127         aList.AddBlankItemL( 1 );
  1135 
  1128          }
  1136         // Common
  1129     }
  1137         _LIT( KOverallCaption3, "Common Statistics" );
  1130 
  1138         aList.AddItemL( KOverallCaption3 );
  1131 
  1139         aList.AddUnderlineForPreviousItemL( '=', 0 );
  1132 void CMemSpyEngineHelperHeap::AppendCellsL(const RArray<TMemSpyDriverCell>& aCells, CMemSpyEngineOutputList& aList)
  1140 
  1133     {
  1141         _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
  1142         aList.AddItemL( KStatsData_Common_TotalCellCount, rHeapStats.StatsCommon().TotalCellCount() );
  1135 
  1143 
       
  1144         _LIT( KStatsData_Common_TotalSize,  "Total cell size:" );
       
  1145         aList.AddItemL( KStatsData_Common_TotalSize, rHeapStats.StatsAllocated().TypeSize() + rHeapStats.StatsFree().TypeSize() );
       
  1146 
       
  1147         aList.AddBlankItemL( 1 );
       
  1148         }
       
  1149     }
       
  1150 
       
  1151 
       
  1152 void CMemSpyEngineHelperHeap::AppendFreeCellsL( const RArray<TMemSpyDriverFreeCell>& aFreeCells, CMemSpyEngineOutputList& aList )
       
  1153     {
       
  1154     // Free space
       
  1155     _LIT( KOverallCaption1, "Free Cell List" );
  1136     _LIT( KOverallCaption1, "Free Cell List" );
  1156     aList.AddItemL( KOverallCaption1 );
  1137     aList.AddItemL( KOverallCaption1 );
  1157     aList.AddUnderlineForPreviousItemL( '=', 0 );
  1138     aList.AddUnderlineForPreviousItemL( '=', 0 );
  1158 
  1139 
  1159     TBuf<128> caption;
  1140     TBuf<128> caption;
  1160     _LIT( KCaptionFormat, "FC %04d" );
  1141     _LIT( KCaptionFormat, "FC %04d" );
  1161     _LIT( KValueFormat, "0x%08x %8d %1d" );
  1142     _LIT( KValueFormat, "0x%08x %8d %d" );
  1162 
  1143 
  1163     const TInt count = aFreeCells.Count();
  1144 	TBool foundAllocatedCells = EFalse;
       
  1145     const TInt count = aCells.Count();
  1164     for( TInt i=0; i<count; i++ )
  1146     for( TInt i=0; i<count; i++ )
  1165         {
  1147         {
  1166         const TMemSpyDriverFreeCell& cell = aFreeCells[ i ];
  1148         const TMemSpyDriverCell& cell = aCells[ i ];
  1167         caption.Format( KCaptionFormat, i + 1 );
  1149 		if (cell.iType & EMemSpyDriverAllocatedCellMask)
  1168         aList.AddItemFormatL( caption, KValueFormat, cell.iAddress, cell.iLength, cell.iType );
  1150 			{
  1169         }
  1151 			foundAllocatedCells = ETrue;
  1170     }
  1152 			}
  1171 
  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     }
  1172 
  1182 
  1173 void CMemSpyEngineHelperHeap::UpdateSharedHeapInfoL( const TProcessId& aProcess, const TThreadId& aThread, TMemSpyHeapInfo& aInfo )
  1183 void CMemSpyEngineHelperHeap::UpdateSharedHeapInfoL( const TProcessId& aProcess, const TThreadId& aThread, TMemSpyHeapInfo& aInfo )
  1174     {
  1184     {
  1175     RArray<TThreadId> threads;
  1185     RArray<TThreadId> threads;
  1176     CleanupClosePushL( threads );
  1186     CleanupClosePushL( threads );