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