memspy/Console/Source/ConsoleMenu.cpp
branchRCL_3
changeset 21 52e343bb8f80
parent 20 ca8a1b6995f6
equal deleted inserted replaced
20:ca8a1b6995f6 21:52e343bb8f80
    37 // User includes
    37 // User includes
    38 #include "ConsoleConstants.h"
    38 #include "ConsoleConstants.h"
    39 #include "ConsoleDWOperation.h"
    39 #include "ConsoleDWOperation.h"
    40 
    40 
    41 
    41 
    42 CMemSpyConsoleMenu::CMemSpyConsoleMenu( RMemSpySession& aSession, CConsoleBase& aConsole )
    42 CMemSpyConsoleMenu::CMemSpyConsoleMenu( CMemSpyEngine& aEngine, CConsoleBase& aConsole )
    43 :   CActive( EPriorityHigh ), iSession( aSession ), iConsole( aConsole ), iOutputType(EOutputTypeDebug)
    43 :   CActive( EPriorityHigh ), iEngine( aEngine ), iConsole( aConsole )
    44     {
    44     {
    45     CActiveScheduler::Add( this );
    45     CActiveScheduler::Add( this );
    46     // TODO: iEngine.SetObserver( this );
    46     iEngine.SetObserver( this );
    47     }
    47     }
    48 
    48 
    49 
    49 
    50 CMemSpyConsoleMenu::~CMemSpyConsoleMenu()
    50 CMemSpyConsoleMenu::~CMemSpyConsoleMenu()
    51     {
    51     {
    52     Cancel();
    52     Cancel();
       
    53     iEngine.SetObserver( NULL );
    53     }
    54     }
    54 
    55 
    55 
    56 
    56 void CMemSpyConsoleMenu::ConstructL()
    57 void CMemSpyConsoleMenu::ConstructL()
    57     {
    58     {
    58     DrawMenuL();
    59     DrawMenuL();
    59     WaitForInput();
    60     WaitForInput();
    60     }
    61     }
    61 
    62 
    62 
    63 
    63 CMemSpyConsoleMenu* CMemSpyConsoleMenu::NewLC( RMemSpySession& aSession, CConsoleBase& aConsole )
    64 CMemSpyConsoleMenu* CMemSpyConsoleMenu::NewLC( CMemSpyEngine& aEngine, CConsoleBase& aConsole )
    64     {
    65     {
    65     CMemSpyConsoleMenu* self = new(ELeave) CMemSpyConsoleMenu( aSession, aConsole );
    66     CMemSpyConsoleMenu* self = new(ELeave) CMemSpyConsoleMenu( aEngine, aConsole );
    66     CleanupStack::PushL( self );
    67     CleanupStack::PushL( self );
    67     self->ConstructL();
    68     self->ConstructL();
    68     return self;
    69     return self;
    69     }
    70     }
    70 
    71 
    73     {
    74     {
    74     iConsole.ClearScreen();
    75     iConsole.ClearScreen();
    75    
    76    
    76     // First line - sink type (defaults to file)
    77     // First line - sink type (defaults to file)
    77     _LIT( KLine1, "1 or T. Toggle output mode between file or trace [%S]" );
    78     _LIT( KLine1, "1 or T. Toggle output mode between file or trace [%S]" );
    78     if  ( iOutputType == EOutputTypeDebug )
    79     if  ( iEngine.SinkType() == ESinkTypeDebug )
    79         {
    80         {
    80         _LIT( KLine1Trace, "Trace" );
    81         _LIT( KLine1Trace, "Trace" );
    81         iConsole.Printf( KLine1, &KLine1Trace );
    82         iConsole.Printf( KLine1, &KLine1Trace );
    82         }
    83         }
    83     else
    84     else
   201     }
   202     }
   202 
   203 
   203 
   204 
   204 void CMemSpyConsoleMenu::OnCmdSinkTypeToggleL()
   205 void CMemSpyConsoleMenu::OnCmdSinkTypeToggleL()
   205     {
   206     {
   206 	iOutputType = iOutputType == EOutputTypeFile ? EOutputTypeDebug : EOutputTypeFile;
   207     if  ( iEngine.SinkType() == ESinkTypeDebug )
       
   208         {
       
   209         iEngine.InstallSinkL( ESinkTypeFile );
       
   210         }
       
   211     else
       
   212         {
       
   213         iEngine.InstallSinkL( ESinkTypeDebug );
       
   214         }
   207     }
   215     }
   208 
   216 
   209 
   217 
   210 void CMemSpyConsoleMenu::OnCmdHeapDataKernelL()
   218 void CMemSpyConsoleMenu::OnCmdHeapDataKernelL()
   211     {
   219     {
   214 #endif
   222 #endif
   215 
   223 
   216     _LIT( KMsg, "Ouputting Kernel data..." );
   224     _LIT( KMsg, "Ouputting Kernel data..." );
   217     RedrawStatusMessage( KMsg );
   225     RedrawStatusMessage( KMsg );
   218 
   226 
   219     iSession.OutputKernelHeapDataL( iOutputType );
   227     iEngine.HelperHeap().OutputHeapDataKernelL();
   220 
   228 
   221     RedrawStatusMessage( KNullDesC );
   229     RedrawStatusMessage( KNullDesC );
   222     }
   230     }
   223 
   231 
   224 
   232 
   229 #endif
   237 #endif
   230 
   238 
   231     _LIT( KMsg, "Ouputting Kernel Object listing..." );
   239     _LIT( KMsg, "Ouputting Kernel Object listing..." );
   232     RedrawStatusMessage( KMsg );
   240     RedrawStatusMessage( KMsg );
   233     //
   241     //
   234     iSession.OutputKernelObjectsL( iOutputType );
   242     CMemSpyEngineHelperKernelContainers& kernelContainerManager = iEngine.HelperKernelContainers();
       
   243     CMemSpyEngineGenericKernelObjectContainer* model = kernelContainerManager.ObjectsAllL();
       
   244     CleanupStack::PushL( model );
       
   245     //
       
   246     CMemSpyEngineOutputSink& sink = iEngine.Sink();
       
   247     model->OutputL( sink );
       
   248     //
       
   249     CleanupStack::PopAndDestroy( model );
   235 
   250 
   236     RedrawStatusMessage( KNullDesC );
   251     RedrawStatusMessage( KNullDesC );
   237     }
   252     }
   238 
   253 
   239 
   254 
   241     {
   256     {
   242 #ifdef _DEBUG
   257 #ifdef _DEBUG
   243     RDebug::Printf( "[MCon] CMemSpyConsoleMenu::OnCmdCSVListingStackL() - START" );
   258     RDebug::Printf( "[MCon] CMemSpyConsoleMenu::OnCmdCSVListingStackL() - START" );
   244 #endif
   259 #endif
   245 
   260 
   246     iSession.OutputCompactStackInfoL( iOutputType );
   261     iEngine.HelperStack().OutputStackInfoForDeviceL();
   247     }
   262     }
   248 
   263 
   249 
   264 
   250 void CMemSpyConsoleMenu::OnCmdCSVListingHeapL()
   265 void CMemSpyConsoleMenu::OnCmdCSVListingHeapL()
   251     {
   266     {
   252 #ifdef _DEBUG
   267 #ifdef _DEBUG
   253     RDebug::Printf( "[MCon] CMemSpyConsoleMenu::OnCmdCSVListingHeapL() - START" );
   268     RDebug::Printf( "[MCon] CMemSpyConsoleMenu::OnCmdCSVListingHeapL() - START" );
   254 #endif
   269 #endif
   255 
   270 
   256     iSession.OutputCompactHeapInfoL( iOutputType );
   271     iEngine.HelperHeap().OutputHeapInfoForDeviceL();
   257     }
   272     }
   258 
   273 
   259 
   274 
   260 void CMemSpyConsoleMenu::OnCmdHeapDataUserL()
   275 void CMemSpyConsoleMenu::OnCmdHeapDataUserL()
   261     {
   276     {
   279         //
   294         //
   280         HBufC* cmdBuf = HBufC::NewLC( KMemSpyMaxInputBufferLength + 10 );
   295         HBufC* cmdBuf = HBufC::NewLC( KMemSpyMaxInputBufferLength + 10 );
   281         TPtr pCmdBuf( cmdBuf->Des() );
   296         TPtr pCmdBuf( cmdBuf->Des() );
   282         pCmdBuf.Copy( iCommandBuffer );
   297         pCmdBuf.Copy( iCommandBuffer );
   283         pCmdBuf.Append( KMemSpyConsoleWildcardCharacter );
   298         pCmdBuf.Append( KMemSpyConsoleWildcardCharacter );
   284         
   299         //
   285         TInt err;
   300         CMemSpyEngineObjectContainer& container = iEngine.Container();
   286         TProcessId procId;
   301         const TInt count = container.Count();
   287         TRAP(err, procId = iSession.GetProcessIdByNameL(pCmdBuf));
   302         TFullName fullThreadName;
   288         //
   303         //
   289         if (err == KErrNone) 
   304         TInt index = 0;
   290         	{
   305 #ifdef _DEBUG
   291         	RArray<CMemSpyApiThread*> threads;
   306         RDebug::Printf( "[MCon] CMemSpyConsoleMenu::OnCmdHeapDataUserL() - procCount: %d", count );
   292         	
   307 #endif
   293         	TRAP(err, iSession.GetThreadsL(procId, threads));
   308 
   294         	if (err == KErrNone)
   309         while( index < count )
   295         		{
   310             {
   296 				_LIT( KProcessingRequest, "** Dumping Heap Data for thread: %S" );     	
   311             CMemSpyProcess& process = container.At( index );
   297 				TFullName fullThreadName;
   312             const TPtrC processName( process.Name() );
   298 				
   313 #ifdef _DEBUG
   299                 for( TInt i=0; i<threads.Count(); i++ )
   314             RDebug::Print( _L("[MCon] CMemSpyConsoleMenu::OnCmdHeapDataUserL() - procName: 0x%08x %S"), &process, &processName );
       
   315 #endif
       
   316 
       
   317             //
       
   318             if  ( processName.MatchF( pCmdBuf ) >= 0 )
       
   319                 {
       
   320                 _LIT( KProcessingRequest, "** Dumping Heap Data for thread: %S" );
       
   321                 const TInt threadCount = process.Count();
       
   322                 for( TInt i=0; i<threadCount; i++ )
   300                     {
   323                     {
   301                     CMemSpyApiThread* thread = threads[i];
   324                     CMemSpyThread& thread = process.At( i );
   302                     //
   325                     //
   303                     fullThreadName = thread->Name();
   326                     fullThreadName = thread.FullName();
   304                     iConsole.Printf( KProcessingRequest, &fullThreadName );
   327                     iConsole.Printf( KProcessingRequest, &fullThreadName );
   305                     iConsole.Write( KMemSpyConsoleNewLine );
   328                     iConsole.Write( KMemSpyConsoleNewLine );
   306                     //
   329                     //
   307                     TRAP_IGNORE( iSession.OutputThreadHeapDataL(iOutputType, thread->Id()) );
   330                     TRAP_IGNORE( iEngine.HelperHeap().OutputHeapDataUserL( thread ) );
   308                     
       
   309                     delete thread;
       
   310                     }
   331                     }
       
   332 
       
   333                 break;
   311                 }
   334                 }
       
   335             
       
   336             ++index;
   312             }
   337             }
   313 
   338 
   314         CleanupStack::PopAndDestroy( cmdBuf );
   339         CleanupStack::PopAndDestroy( cmdBuf );
   315         DrawMenuL();
   340         DrawMenuL();
   316         }
   341         }
   342         //
   367         //
   343         HBufC* cmdBuf = HBufC::NewLC( KMemSpyMaxInputBufferLength + 10 );
   368         HBufC* cmdBuf = HBufC::NewLC( KMemSpyMaxInputBufferLength + 10 );
   344         TPtr pCmdBuf( cmdBuf->Des() );
   369         TPtr pCmdBuf( cmdBuf->Des() );
   345         pCmdBuf.Copy( iCommandBuffer );
   370         pCmdBuf.Copy( iCommandBuffer );
   346         pCmdBuf.Append( KMemSpyConsoleWildcardCharacter );
   371         pCmdBuf.Append( KMemSpyConsoleWildcardCharacter );
   347         
   372         //
   348         TInt err;
   373         CMemSpyEngineObjectContainer& container = iEngine.Container();
   349 		TProcessId procId;
   374         const TInt count = container.Count();
   350 		TRAP(err, procId = iSession.GetProcessIdByNameL(pCmdBuf));
   375         TFullName fullThreadName;
   351 		//
   376         //
   352 		if (err == KErrNone) 
   377         TInt index = 0;
   353 			{
   378         while( index < count )
   354 			RArray<CMemSpyApiThread*> threads;
   379             {
   355 			
   380             CMemSpyProcess& process = container.At( index );
   356 			TRAP(err, iSession.GetThreadsL(procId, threads));
   381             const TPtrC processName( process.Name() );
   357 			if (err == KErrNone)
   382             //
   358 				{
   383             if  ( processName.MatchF( pCmdBuf ) >= 0 )
   359 				_LIT( KProcessingRequest, "** Dumping Heap Cell List for thread: %S" );     	
   384                 {
   360 				TFullName fullThreadName;
   385                 _LIT( KProcessingRequest, "** Dumping Heap Cell List for thread: %S" );
   361 				
   386                 const TInt threadCount = process.Count();
   362 				for( TInt i=0; i<threads.Count(); i++ )
   387                 for( TInt i=0; i<threadCount; i++ )
   363 					{
   388                     {
   364 					CMemSpyApiThread* thread = threads[i];
   389                     CMemSpyThread& thread = process.At( i );
   365 					//
   390                     //
   366 					fullThreadName = thread->Name();
   391                     fullThreadName = thread.FullName();
   367 					iConsole.Printf( KProcessingRequest, &fullThreadName );
   392                     iConsole.Printf( KProcessingRequest, &fullThreadName );
   368 					iConsole.Write( KMemSpyConsoleNewLine );
   393                     iConsole.Write( KMemSpyConsoleNewLine );
   369 					//
   394                     //
   370 					TRAP_IGNORE( iSession.OutputThreadCellListL(iOutputType, thread->Id()) );
   395                     TRAP_IGNORE( iEngine.HelperHeap().OutputCellListingUserL( thread ) );
   371 					
   396                     }
   372 					delete thread;
   397 
   373 					}
   398                 break;
   374 				}
   399                 }
   375 			}
   400             
   376         
   401             ++index;
       
   402             }
       
   403 
   377         CleanupStack::PopAndDestroy( cmdBuf );
   404         CleanupStack::PopAndDestroy( cmdBuf );
   378         DrawMenuL();
   405         DrawMenuL();
   379         }
   406         }
   380     else
   407     else
   381         {
   408         {
   575     }
   602     }
   576 
   603 
   577 
   604 
   578 void CMemSpyConsoleMenu::InitiateMemSpyClientServerOperationL( TInt aOpCode )
   605 void CMemSpyConsoleMenu::InitiateMemSpyClientServerOperationL( TInt aOpCode )
   579     {
   606     {
   580 	// TODO: ....
   607 #ifdef _DEBUG
   581 //#ifdef _DEBUG
   608     RDebug::Printf( "[MCon] CMemSpyConsoleMenu::InitiateMemSpyClientServerOperationL() - START - aOpCode: %d, iRunningDeviceWideOperation: %d", aOpCode, iRunningDeviceWideOperation );
   582 //    RDebug::Printf( "[MCon] CMemSpyConsoleMenu::InitiateMemSpyClientServerOperationL() - START - aOpCode: %d, iRunningDeviceWideOperation: %d", aOpCode, iRunningDeviceWideOperation );
   609 #endif
   583 //#endif
   610     //
   584 //    //
   611     if ( aOpCode == EMemSpyClientServerOpExit )
   585 //    if ( aOpCode == EMemSpyClientServerOpExit )
   612         {
   586 //        {
   613         // Exit console app UI
   587 //        // Exit console app UI
   614         CActiveScheduler::Stop();
   588 //        CActiveScheduler::Stop();
   615         }
   589 //        }
   616     else
   590 //    else
   617         {
   591 //        {
   618         CMemSpyDeviceWideOperations::TOperation op = CMemSpyDeviceWideOperations::EPerEntityGeneralSummary;
   592 //        CMemSpyDeviceWideOperations::TOperation op = CMemSpyDeviceWideOperations::EPerEntityGeneralSummary;
   619         switch( aOpCode )
   593 //        switch( aOpCode )
   620             {
   594 //            {
   621         case EMemSpyClientServerOpSummaryInfo:
   595 //        case EMemSpyClientServerOpSummaryInfo:
   622             op = CMemSpyDeviceWideOperations::EPerEntityGeneralSummary;
   596 //            op = CMemSpyDeviceWideOperations::EPerEntityGeneralSummary;
   623             break;
   597 //            break;
   624         case EMemSpyClientServerOpSummaryInfoDetailed:
   598 //        case EMemSpyClientServerOpSummaryInfoDetailed:
   625             op = CMemSpyDeviceWideOperations::EPerEntityGeneralDetailed;
   599 //            op = CMemSpyDeviceWideOperations::EPerEntityGeneralDetailed;
   626             break;
   600 //            break;
   627         //
   601 //        //
   628         case EMemSpyClientServerOpHeapInfo:
   602 //        case EMemSpyClientServerOpHeapInfo:
   629             op = CMemSpyDeviceWideOperations::EPerEntityHeapInfo;
   603 //            op = CMemSpyDeviceWideOperations::EPerEntityHeapInfo;
   630             break;
   604 //            break;
   631         case EMemSpyClientServerOpHeapCellListing:
   605 //        case EMemSpyClientServerOpHeapCellListing:
   632             op = CMemSpyDeviceWideOperations::EPerEntityHeapCellListing;
   606 //            op = CMemSpyDeviceWideOperations::EPerEntityHeapCellListing;
   633             break;
   607 //            break;
   634         case EMemSpyClientServerOpHeapData:
   608 //        case EMemSpyClientServerOpHeapData:
   635             op = CMemSpyDeviceWideOperations::EPerEntityHeapData;
   609 //            op = CMemSpyDeviceWideOperations::EPerEntityHeapData;
   636             break;
   610 //            break;
   637         //
   611 //        //
   638         case EMemSpyClientServerOpStackInfo:
   612 //        case EMemSpyClientServerOpStackInfo:
   639             op = CMemSpyDeviceWideOperations::EPerEntityStackInfo;
   613 //            op = CMemSpyDeviceWideOperations::EPerEntityStackInfo;
   640             break;
   614 //            break;
   641         case EMemSpyClientServerOpStackDataUser:
   615 //        case EMemSpyClientServerOpStackDataUser:
   642             op = CMemSpyDeviceWideOperations::EPerEntityStackDataUser;
   616 //            op = CMemSpyDeviceWideOperations::EPerEntityStackDataUser;
   643             break;
   617 //            break;
   644         case EMemSpyClientServerOpStackDataKernel:
   618 //        case EMemSpyClientServerOpStackDataKernel:
   645             op = CMemSpyDeviceWideOperations::EPerEntityStackDataKernel;
   619 //            op = CMemSpyDeviceWideOperations::EPerEntityStackDataKernel;
   646             break;
   620 //            break;
   647         
   621 //        
   648         // These are not supported by the console UI
   622 //        // These are not supported by the console UI
   649         default:
   623 //        default:
   650         case EMemSpyClientServerOpBitmapsSave:
   624 //        case EMemSpyClientServerOpBitmapsSave:
   651         case EMemSpyClientServerOpSendToBackground:
   625 //        case EMemSpyClientServerOpSendToBackground:
   652         case EMemSpyClientServerOpBringToForeground:
   626 //        case EMemSpyClientServerOpBringToForeground:
   653             User::Leave( KErrNotSupported );
   627 //            User::Leave( KErrNotSupported );
   654             break;
   628 //            break;
   655             }
   629 //            }
   656 
   630 //
   657         if  ( iRunningDeviceWideOperation )
   631 //        if  ( iRunningDeviceWideOperation )
   658             {
   632 //            {
   659             User::Leave( KErrInUse );
   633 //            User::Leave( KErrInUse );
   660             }
   634 //            }
   661         else
   635 //        else
   662             {
   636 //            {
   663             iRunningDeviceWideOperation = ETrue;
   637 //            iRunningDeviceWideOperation = ETrue;
   664             TRAP_IGNORE( CMemSpyDeviceWideOperationWaiter::ExecuteLD( iEngine, op ) );
   638 //            TRAP_IGNORE( CMemSpyDeviceWideOperationWaiter::ExecuteLD( iEngine, op ) );
   665             iRunningDeviceWideOperation = EFalse;
   639 //            iRunningDeviceWideOperation = EFalse;
   666             }
   640 //            }
   667         }
   641 //        }
   668 
   642 //
   669 #ifdef _DEBUG
   643 //#ifdef _DEBUG
   670     RDebug::Printf( "[MCon] CMemSpyConsoleMenu::InitiateMemSpyClientServerOperationL() - END - aOpCode: %d", aOpCode );
   644 //    RDebug::Printf( "[MCon] CMemSpyConsoleMenu::InitiateMemSpyClientServerOperationL() - END - aOpCode: %d", aOpCode );
   671 #endif
   645 //#endif
   672     }
   646     }
   673 
   647 
   674 
   648 
   675 
   649