perfsrv/piprofiler/engine/src/SamplerController.cpp
changeset 62 1c2bb2fc7c87
parent 51 98307c651589
equal deleted inserted replaced
56:aa2539c91954 62:1c2bb2fc7c87
    30 _LIT8(KSettingsText, " settings");
    30 _LIT8(KSettingsText, " settings");
    31 _LIT(KNewLine, "\n");
    31 _LIT(KNewLine, "\n");
    32 _LIT(KEquals, "=");
    32 _LIT(KEquals, "=");
    33 _LIT(KCommentSeparator, " ; ");
    33 _LIT(KCommentSeparator, " ; ");
    34 
    34 
    35 CSamplerController* CSamplerController::NewL(CProfilerSampleStream& aStream)
    35 // forward declarations
    36     {
    36 
    37     CSamplerController* self = new( ELeave ) CSamplerController(aStream);
    37 
       
    38 
       
    39 CSamplerController* CSamplerController::NewL(CProfilerSampleStream& aStream, TBool aBootMode)
       
    40     {
       
    41     CSamplerController* self = new( ELeave ) CSamplerController(aStream, aBootMode);
    38     CleanupStack::PushL( self );
    42     CleanupStack::PushL( self );
    39     self->ConstructL( );
    43     self->ConstructL( );
    40     CleanupStack::Pop( self );
    44     CleanupStack::Pop( self );
    41     return self;
    45     return self;
    42     }
    46     }
    46 	// initiate sampler plugin list
    50 	// initiate sampler plugin list
    47 	InitialiseSamplerListL();
    51 	InitialiseSamplerListL();
    48 	}
    52 	}
    49 
    53 
    50 
    54 
    51 CSamplerController::CSamplerController(CProfilerSampleStream& aStream) : 
    55 CSamplerController::CSamplerController(CProfilerSampleStream& aStream, TBool aBootMode) : 
    52     iStream(aStream)
    56     iStream(aStream),
       
    57     iScBootMode(aBootMode)
    53 	{
    58 	{
       
    59     
    54 	}
    60 	}
    55 
    61 
    56 void CSamplerController::InitialiseSamplerListL()
    62 void CSamplerController::InitialiseSamplerListL()
    57     {
    63     {
    58     // create new sampler plugin array
    64     // create new sampler plugin array    
    59     iPluginArray = new (ELeave) CArrayPtrFlat<CSamplerPluginInterface>( KMaxSamplerPluginCount );
    65      iPluginArray = new (ELeave) CArrayPtrFlat<CSamplerPluginInterface>( KMaxSamplerPluginCount );
    60     
    66              
    61     // create plugin loader instance
    67      // create plugin loader instance
    62     iPluginLoader = CSamplerPluginLoader::NewL();
    68      iPluginLoader = CSamplerPluginLoader::NewL(iScBootMode);
    63     
    69      
    64     // register sampler controller to get notifications of succesfull plugin load
    70      // register sampler controller to get notifications of succesfull plugin load
    65     iPluginLoader->SetObserver( this );
    71      iPluginLoader->SetObserver( this );
    66     
    72     if (iScBootMode)
    67     // load sampler plugins asynchronously
    73             {
    68     iPluginLoader->LoadAsyncL( iPluginArray );
    74             LOGSTRING("CSamplerController boot mode");
    69     
    75             // load sampler rlibrary
    70     LOGTEXT(_L(" RSamplerController::InitialiseUserSideSamplerList - exit"));	
    76             iPluginLoader->LoadRlibraryL(iPluginArray);
       
    77             }
       
    78         else
       
    79             {
       
    80             LOGSTRING("CSamplerController not boot mode");
       
    81 
       
    82             // load sampler plugins asynchronously
       
    83             iPluginLoader->LoadAsyncL( iPluginArray );
       
    84             }   
       
    85     LOGTEXT(_L("CSamplerController::InitialiseUserSideSamplerList - exit"));	
    71     }
    86     }
    72 
    87 
    73 CSamplerController::~CSamplerController()
    88 CSamplerController::~CSamplerController()
    74 	{
    89 	{
    75 	LOGTEXT(_L("CSamplerController::~CSamplerController - entry" ));
    90 	LOGTEXT(_L("CSamplerController::~CSamplerController - entry" ));
    95 	    {
   110 	    {
    96 	    iPluginLoader->AbortAsyncLoad();
   111 	    iPluginLoader->AbortAsyncLoad();
    97 	    delete iPluginLoader;
   112 	    delete iPluginLoader;
    98 	    iPluginLoader = NULL;
   113 	    iPluginLoader = NULL;
    99 	    }
   114 	    }
   100     
   115 	
       
   116     if( iPlug )
       
   117         {
       
   118         iPlug->StopSampling();
       
   119         delete iPlug;
       
   120         iPlug= NULL;
       
   121         LOGSTRING("iPlug deleted, sampling stopped");
       
   122         }
       
   123 	if ( iLibrary )
       
   124 	    {
       
   125         iLibrary->Close();
       
   126         delete iLibrary;
       
   127         iLibrary = NULL;
       
   128 	    }
       
   129 	REComSession::FinalClose();
       
   130 	
   101 	LOGTEXT(_L("CSamplerController::~CSamplerController - exit" ));
   131 	LOGTEXT(_L("CSamplerController::~CSamplerController - exit" ));
   102 	}
   132 	}
   103 
   133 
   104 void CSamplerController::SetObserver(MSamplerControllerObserver* aObserver)
   134 void CSamplerController::SetObserver(MSamplerControllerObserver* aObserver)
   105     {
   135     {
   106     iObserver = aObserver;
   136     iObserver = aObserver;
   107     }
   137     }
   108     
   138     
   109 TInt CSamplerController::UpdateSavedSamplerAttributesL(CDesC8ArrayFlat* aSavedLineArray, CArrayFixFlat<TSamplerAttributes>* aAttributes)
   139 TInt CSamplerController::UpdateSavedSamplerAttributesL(CDesC8ArrayFlat* aSavedLineArray, CArrayFixFlat<TSamplerAttributes>* aAttributes)
   110     {
   140     {
       
   141     LOGSTRING("CSamplerController::UpdateSavedSamplerAttributesL");
   111     TInt err(KErrNone);
   142     TInt err(KErrNone);
   112     TInt count(iPluginArray->Count());
   143     if( iPluginArray )
   113     // all plugins get their own settings among whole lump of setting strings
       
   114     CSamplerPluginInterface* plugin = NULL;
       
   115     
       
   116     // loop through the plugin array
       
   117     for(TInt i(0);i<count;i++)
       
   118         {
   144         {
   119         // get each plugin at a time
   145         TInt count(iPluginArray->Count());
   120         plugin = iPluginArray->At(i);
   146         // all plugins get their own settings among whole lump of setting strings
   121         
   147         CSamplerPluginInterface* plugin = NULL;
   122         // call each plugin to sort out its own settings 
   148         
   123         err = plugin->ConvertRawSettingsToAttributes(aSavedLineArray);
   149         // loop through the plugin array
   124         
   150         for(TInt i(0);i<count;i++)
   125         // get plugin specific attributes, array may contain attributes of several sub samplers
   151             {
   126         plugin->GetAttributesL(aAttributes); 
   152             // get each plugin at a time
       
   153             plugin = iPluginArray->At(i);
       
   154             
       
   155             // call each plugin to sort out its own settings 
       
   156             err = plugin->ConvertRawSettingsToAttributes(aSavedLineArray);
       
   157             
       
   158             // get plugin specific attributes, array may contain attributes of several sub samplers
       
   159             plugin->GetAttributesL(aAttributes); 
       
   160             }
   127         }
   161         }
   128     
       
   129     return err;
   162     return err;
   130     }
   163     }
   131 
   164 
   132 TInt CSamplerController::SetSamplerSettingsL(TInt aUid, TSamplerAttributes& aAttributes)
   165 TInt CSamplerController::SetSamplerSettingsL(TInt aUid, TSamplerAttributes& aAttributes)
   133     {
   166     {
   167     {
   200     {
   168     // temporary buffer for a setting line
   201     // temporary buffer for a setting line
   169     TBuf<384> settingLine;
   202     TBuf<384> settingLine;
   170     TBuf8<384> settingLine8;
   203     TBuf8<384> settingLine8;
   171     TInt itemCount(0);
   204     TInt itemCount(0);
   172     TBuf<266> tBuf;
   205     //TBuf<266> tBuf;
   173     
   206     
   174     TSamplerAttributes attr;
   207     TSamplerAttributes attr;
   175     
   208     
   176     for(TInt i(0);i<aAttrArray->Count();i++)
   209     for(TInt i(0);i<aAttrArray->Count();i++)
   177         {
   210         {
   367     }
   400     }
   368 
   401 
   369 
   402 
   370 void CSamplerController::HandlePluginLoaded( KSamplerPluginLoaderStatus aStatus )
   403 void CSamplerController::HandlePluginLoaded( KSamplerPluginLoaderStatus aStatus )
   371     {
   404     {
   372     
   405     LOGSTRING("CSamplerController::HandlePluginLoaded");
   373     // process status value
   406     // process status value
   374     switch(aStatus)
   407     switch(aStatus)
   375         {
   408         {
   376         case 0:
   409         case ESamplerSuccess:
   377             LOGSTRING2("RSamplerController - one plugin loaded, status: %d", aStatus);
   410             LOGSTRING2("RSamplerController - one plugin loaded, status: %d", aStatus);
   378             break;
   411             break;
   379         case 1:
   412         case ESamplerFail:
   380             LOGSTRING2("RSamplerController - a plugin load failed: %d", aStatus);
   413             LOGSTRING2("RSamplerController - a plugin load failed: %d", aStatus);
   381             break;
   414             break;
   382         case 2:
   415         case ESamplerAborted:
   383             LOGSTRING2("RSamplerController - plugin loading aborted: %d", aStatus);
   416             LOGSTRING2("RSamplerController - plugin loading aborted: %d", aStatus);
   384             break;
   417             break;
   385         case 3:
   418         case ESamplerFinished:
   386             LOGSTRING2("RSamplerController - all plugins loaded: %d", aStatus);
   419             LOGSTRING2("RSamplerController - all plugins loaded: %d", aStatus);
   387             TRAPD(err, iPluginLoader->SortPluginsL(iPluginArray));
   420             TRAPD(err, iPluginLoader->SortPluginsL(iPluginArray));
   388             if(err != KErrNone)
   421             if(err != KErrNone)
   389                 {
   422                 {
   390                 LOGTEXT(_L("Sampler controller unable to sort plugins"));
   423                 LOGTEXT(_L("Sampler controller unable to sort plugins"));
   395             if(result != KErrNone)
   428             if(result != KErrNone)
   396                 {
   429                 {
   397                 LOGTEXT(_L("Failed to notify engine"));
   430                 LOGTEXT(_L("Failed to notify engine"));
   398                 }
   431                 }
   399             break;
   432             break;
   400         case 4:
   433         case ESamplerError:
   401             LOGSTRING2("RSamplerController - error in loading plugins: %d", aStatus);
   434             LOGSTRING2("RSamplerController - error in loading plugins: %d", aStatus);
   402             break;
   435             break;
   403         default:
   436         default:
   404             break;
   437             break;
   405         }
   438         }
   471 		// stop kernel mode samplers
   504 		// stop kernel mode samplers
   472     	for(;i<iPluginArray->Count();i++)
   505     	for(;i<iPluginArray->Count();i++)
   473     		{
   506     		{
   474 			plugin = iPluginArray->At(i); 
   507 			plugin = iPluginArray->At(i); 
   475 			TUint32 id = plugin->Id(-1).iUid;
   508 			TUint32 id = plugin->Id(-1).iUid;
   476             LOGSTRING2(" CSamplerController::StopSamplerPlugins - traceId = %d",
   509             LOGSTRING2(" CSamplerController::StopSamplerPlugins - traceId = 0x%x",id);
   477                         id);
       
   478             // stop only started samplers
   510             // stop only started samplers
   479             if(plugin->Enabled())
   511             if(plugin->Enabled())
   480                 {
   512                 {
   481                 // stop selected plugin
   513                 // stop selected plugin
   482                 plugin->StopSampling();
   514                 plugin->StopSampling();
   484                 if(plugin->GetSamplerType() == PROFILER_USER_MODE_SAMPLER)
   516                 if(plugin->GetSamplerType() == PROFILER_USER_MODE_SAMPLER)
   485                     {
   517                     {
   486                     LOGTEXT(_L(" CSamplerController::StopSamplerPlugins - flushing user mode sampler stream"));
   518                     LOGTEXT(_L(" CSamplerController::StopSamplerPlugins - flushing user mode sampler stream"));
   487                     plugin->Flush();
   519                     plugin->Flush();
   488                     }
   520                     }
       
   521                 }
       
   522             else
       
   523                 {
       
   524                 LOGSTRING2("CSamplerController::StopSamplerPlugins - plugin id 0x%x not enabled",id);
   489                 }
   525                 }
   490             count++;
   526             count++;
   491     		}
   527     		}
   492 		}
   528 		}
   493 	return count; 	
   529 	return count;