perfsrv/piprofiler/engine/src/ProfilerEngine.cpp
changeset 62 1c2bb2fc7c87
parent 51 98307c651589
equal deleted inserted replaced
56:aa2539c91954 62:1c2bb2fc7c87
    93  *
    93  *
    94  *	CProfiler class implementation
    94  *	CProfiler class implementation
    95  *
    95  *
    96  */
    96  */
    97 // --------------------------------------------------------------------------------------------
    97 // --------------------------------------------------------------------------------------------
    98 CProfiler* CProfiler::NewLC(const TDesC& aSettingsFile)
    98 CProfiler* CProfiler::NewLC(const TDesC& aSettingsFile, TBool aBootMode)
    99     {
    99     {
   100 	CProfiler* self = new(ELeave) CProfiler(aSettingsFile);
   100 	CProfiler* self = new(ELeave) CProfiler(aSettingsFile ,aBootMode);
   101 	CleanupStack::PushL(self);
   101 	CleanupStack::PushL(self);
   102 	self->ConstructL();
   102 	self->ConstructL();
       
   103 	
       
   104 	LOGTEXT(_L("CProfiler::NewLC - done"));
   103 	return self;
   105 	return self;
   104     }
   106     }
   105 
   107 
   106 // --------------------------------------------------------------------------------------------
   108 // --------------------------------------------------------------------------------------------
   107 CProfiler::CProfiler(const TDesC& aSettingsFile) : 
   109 CProfiler::CProfiler(const TDesC& aSettingsFile, TBool aBootMode) : 
   108     iSettingsFileLocation(aSettingsFile)
   110     iSettingsFileLocation(aSettingsFile),
       
   111     iBootMode(aBootMode)
   109 	{
   112 	{
   110 	// define property for Profiler Engine status, UI may read it for control purposes
   113 	// define property for Profiler Engine status, UI may read it for control purposes
   111 	if ( RProperty::Define(KEngineStatusPropertyCat, 
   114 	if ( RProperty::Define(KEngineStatusPropertyCat, 
   112 	        EProfilerEngineStatus, 
   115 	        EProfilerEngineStatus, 
   113 	        RProperty::EInt, 
   116 	        RProperty::EInt, 
   188 		iUserStream = NULL;
   191 		iUserStream = NULL;
   189 		}
   192 		}
   190 
   193 
   191 	// close engine status property
   194 	// close engine status property
   192 	iEngineStatus.Close();
   195 	iEngineStatus.Close();
   193 	if (RProperty::Delete(KEngineStatusPropertyCat, EProfilerEngineStatus) != KErrNotFound)
   196 	TInt ret = RProperty::Delete(KEngineStatusPropertyCat, EProfilerEngineStatus);
   194 	    {
   197 	if ( ret != KErrNone)
   195 	    LOGTEXT(_L("CProfiler::~CProfiler - cannot close status property"));
   198 	    {
       
   199 	    LOGSTRING2("CProfiler::~CProfiler - cannot close status property %d", ret);
       
   200 
   196 	    }
   201 	    }
   197     // close engine update property
   202     // close engine update property
   198     iUpdateStatus.Close();
   203     iUpdateStatus.Close();
   199     if (RProperty::Delete(KEngineStatusPropertyCat, EProfilerErrorStatus) != KErrNotFound)
   204     ret = RProperty::Delete(KEngineStatusPropertyCat, EProfilerErrorStatus); 
   200         {
   205     if (ret != KErrNone)
   201         LOGTEXT(_L("CProfiler::~CProfiler - cannot close update property"));
   206         {
       
   207         LOGSTRING2("CProfiler::~CProfiler - cannot close update property %d",ret);
   202         }
   208         }
   203     
   209     
   204     // close server process
   210     // close server process
   205     if (iServer)
   211     if (iServer)
   206         {
   212         {
   220 
   226 
   221 // --------------------------------------------------------------------------------------------
   227 // --------------------------------------------------------------------------------------------
   222 void CProfiler::ConstructL()
   228 void CProfiler::ConstructL()
   223     {
   229     {
   224 	LOGTEXT(_L("CProfiler::ConstructL - Enter"));
   230 	LOGTEXT(_L("CProfiler::ConstructL - Enter"));
   225 	TInt err(0);
   231     TInt err(0);
   226 	TLex lex;
   232 	TLex lex;
       
   233 
       
   234 	if(iBootMode)
       
   235 	    {
       
   236         LOGSTRING("boot mode enabled");
       
   237 	    }
       
   238 	else
       
   239 	    {
       
   240         LOGSTRING("normal mode enabled");
       
   241 	    }
   227 	
   242 	
   228 	if ( iSettingsFileLocation.CompareF(KNullDesC) != 0 )
   243 	if ( iSettingsFileLocation.CompareF(KNullDesC) != 0 )
   229 	    {
   244 	    {
   230         lex=(iSettingsFileLocation);
   245         lex=(iSettingsFileLocation);
   231         // parse the first command line argument, the command itself
   246         // parse the first command line argument, the command itself
   234         if(lex.TokenLength() != 0)
   249         if(lex.TokenLength() != 0)
   235             {
   250             {
   236             // there is another item in the list
   251             // there is another item in the list
   237             TPtrC filename = lex.MarkedToken();
   252             TPtrC filename = lex.MarkedToken();
   238             LOGSTRING2("filename %S", &filename);
   253             LOGSTRING2("filename %S", &filename);
   239             lex.SkipSpace();
   254 
   240             lex.Mark();
   255            }
   241             lex.SkipCharacters();
   256 	    }
   242             if(lex.TokenLength() != 0)
   257 	else
   243                 {
   258 	    {
   244                 TPtrC boot = lex.MarkedToken();
   259         LOGSTRING("CProfiler::ConstructL - Enter - settingsfilelocation null");
   245                 LOGTEXT(_L("boot mode"));
       
   246                 }
       
   247             }
       
   248 	    }
   260 	    }
   249 	
   261 	
   250     // create new sampler stream instance
   262     // create new sampler stream instance
   251     iUserStream = CProfilerSampleStream::NewL(KStreamBufferSize);
   263     iUserStream = CProfilerSampleStream::NewL(KStreamBufferSize);
   252     if(!iUserStream)
   264     if(!iUserStream)
   257 	
   269 	
   258     // engine status checker
   270     // engine status checker
   259     iErrorChecker = CProfilerErrorChecker::NewL();
   271     iErrorChecker = CProfilerErrorChecker::NewL();
   260     iErrorChecker->SetObserver(this);
   272     iErrorChecker->SetObserver(this);
   261 
   273 
   262 	// create and initiate plug-in controller instances
   274     // create and initiate plug-in controller instances
   263     iSamplerHandler = CSamplerController::NewL(*iUserStream);
   275     iSamplerHandler = CSamplerController::NewL(*iUserStream, iBootMode);
   264     iWriterHandler = CWriterController::NewL(*iUserStream);
   276     LOGSTRING("CSamplerController started from ProfilerEngine");
   265     
   277     iWriterHandler = CWriterController::NewL(*iUserStream, iBootMode);
       
   278     LOGSTRING("CWriterController started from ProfilerEngine");
   266     iWriterHandler->InitialiseWriterListL();
   279     iWriterHandler->InitialiseWriterListL();
   267     
   280     LOGSTRING("WriterList initialised started from ProfilerEngine");
   268     // set engine as an observer to sampler controller to get the notification of plugin load has ended
   281     // set engine as an observer to sampler controller to get the notification of plugin load has ended
   269     iSamplerHandler->SetObserver(this);
   282     iSamplerHandler->SetObserver(this);
   270     
   283     
   271     // default settings from sampler plugins, maximum 20 sampler plugins
   284     // default settings from sampler plugins, maximum 20 sampler plugins
   272     iDefaultSamplerAttributesArray = new(ELeave) CArrayFixFlat<TSamplerAttributes>(20); 
   285     iDefaultSamplerAttributesArray = new(ELeave) CArrayFixFlat<TSamplerAttributes>(20); 
   297 			User::Leave(err);
   310 			User::Leave(err);
   298 		    }
   311 		    }
   299 		else break;
   312 		else break;
   300 	    }
   313 	    }
   301 
   314 
       
   315 	if(err != KErrNone) 
       
   316 	    {
       
   317 		User::Leave(err);
       
   318 	    }
       
   319 
   302 	// set settings file loading preferences
   320 	// set settings file loading preferences
   303 	iSettingsFileLoaded = EFalse;
   321 	iSettingsFileLoaded = EFalse;
   304 
   322 
   305 	// change status property to idle since initialization successfull
   323 	// change status property to idle since initialization successfull
   306 	iState = RProfiler::EIdle;
   324 	iState = RProfiler::EIdle;
   340         // load default settings file
   358         // load default settings file
   341         LoadSettingsL();
   359         LoadSettingsL();
   342 
   360 
   343         iSettingsFileLoaded = ETrue;
   361         iSettingsFileLoaded = ETrue;
   344         }
   362         }
   345     
   363     LOGSTRING("CProfiler::HandleSamplerControllerReadyL rendezvous");
   346     // notify engine's launcher(UI or PIProfilerLauncher) to continue launch
   364     // notify engine's launcher(UI or PIProfilerLauncher) to continue launch
   347     RProcess::Rendezvous(KErrNone); 
   365     RProcess::Rendezvous(KErrNone); 
   348     }
   366     }
   349 
   367 
   350 void CProfiler::NotifyRequesterForSettingsUpdate()
   368 void CProfiler::NotifyRequesterForSettingsUpdate()
   379 // ----------------------------------------------------------------------------
   397 // ----------------------------------------------------------------------------
   380 // Gets a value from settings file for certain attribute.
   398 // Gets a value from settings file for certain attribute.
   381 // ----------------------------------------------------------------------------
   399 // ----------------------------------------------------------------------------
   382 void CProfiler::DoGetValueFromSettingsArray(CDesC8ArrayFlat* aLineArray, const TDesC8& aAttribute, TDes8& aValue)
   400 void CProfiler::DoGetValueFromSettingsArray(CDesC8ArrayFlat* aLineArray, const TDesC8& aAttribute, TDes8& aValue)
   383     {
   401     {
   384     LOGTEXT(_L("CProfiler::DoGetValueFromSettingsFile()"));
   402     LOGTEXT(_L("CProfiler::DoGetValueFromSettingsArray()"));
   385     _LIT8(KSettingItemSeparator, "=");
   403     _LIT8(KSettingItemSeparator, "=");
   386     
   404     
   387     // read a line of given array
   405     // read a line of given array
   388     for (TInt i=0; i<aLineArray->MdcaCount(); i++)
   406     for (TInt i=0; i<aLineArray->MdcaCount(); i++)
   389         {
   407         {
   402         }
   420         }
   403     }
   421     }
   404 
   422 
   405 void CProfiler::DoGetValueFromSettingsArray(CDesC8ArrayFlat* aLineArray, const TDesC8& aAttribute, TInt& aValue)
   423 void CProfiler::DoGetValueFromSettingsArray(CDesC8ArrayFlat* aLineArray, const TDesC8& aAttribute, TInt& aValue)
   406     {
   424     {
   407     LOGTEXT(_L("CProfiler::DoGetValueFromSettingsFile()"));
   425     LOGTEXT(_L("CProfiler::DoGetValueFromSettingsFile() TLex"));
   408     _LIT8(KSettingItemSeparator, "=");
   426     _LIT8(KSettingItemSeparator, "=");
   409     
   427     
   410     // read a line of given array
   428     // read a line of given array
   411     for (TInt i=0; i<aLineArray->MdcaCount(); i++)
   429     for (TInt i=0; i<aLineArray->MdcaCount(); i++)
   412         {
   430         {
   684 
   702 
   685 // --------------------------------------------------------------------------------------------
   703 // --------------------------------------------------------------------------------------------
   686 void CProfiler::UpdateSavedGeneralAttributes(CDesC8ArrayFlat* aSavedAttributes)
   704 void CProfiler::UpdateSavedGeneralAttributes(CDesC8ArrayFlat* aSavedAttributes)
   687     {
   705     {
   688     // get saved general settings
   706     // get saved general settings
       
   707     LOGSTRING("CProfiler::UpdateSavedGeneralAttributes");
   689     DoGetValueFromSettingsArray(aSavedAttributes, KGenericTraceOutput, iGeneralAttributes.iTraceOutput);
   708     DoGetValueFromSettingsArray(aSavedAttributes, KGenericTraceOutput, iGeneralAttributes.iTraceOutput);
   690     DoGetValueFromSettingsArray(aSavedAttributes, KGenericTraceFilePrefix, iGeneralAttributes.iTraceFilePrefix);
   709     DoGetValueFromSettingsArray(aSavedAttributes, KGenericTraceFilePrefix, iGeneralAttributes.iTraceFilePrefix);
   691     DoGetValueFromSettingsArray(aSavedAttributes, KGenericTraceFileSaveDrive, iGeneralAttributes.iSaveFileDrive);
   710     DoGetValueFromSettingsArray(aSavedAttributes, KGenericTraceFileSaveDrive, iGeneralAttributes.iSaveFileDrive);
   692     DoGetValueFromSettingsArray(aSavedAttributes, KGenericTimedProfilingPeriod, iGeneralAttributes.iTimedSamplingPeriod);
   711     DoGetValueFromSettingsArray(aSavedAttributes, KGenericTimedProfilingPeriod, iGeneralAttributes.iTimedSamplingPeriod);
   693     }
   712     }
   894     TBuf8<384> line;
   913     TBuf8<384> line;
   895     
   914     
   896     // connect to file server
   915     // connect to file server
   897     err = fs.Connect();
   916     err = fs.Connect();
   898     if( err != KErrNone )
   917     if( err != KErrNone )
   899         {
   918     {
   900         // failed to write settings to settings file
   919         // failed to write settings to settings file
       
   920         RDebug::Printf("FS connect failed");
   901         return;
   921         return;
   902         }
   922     }
   903     
   923     
   904     // create and set the private path
   924     // create and set the private path
   905     fs.CreatePrivatePath(EDriveC);
   925     fs.CreatePrivatePath(EDriveC);
   906     fs.SetSessionToPrivate(EDriveC);
   926     fs.SetSessionToPrivate(EDriveC);
   907   
   927   
   908     // create the new settings file
   928     // create the new settings file
   909     err = settingsFile.Replace(fs, iSettingsFileLocation, EFileWrite);
   929     err = settingsFile.Replace(fs, iSettingsFileLocation, EFileWrite);
   910     if(err != KErrNone)
   930     if(err != KErrNone)
   911         return;
   931         {
   912     
   932         RDebug::Printf("Settingsfile replace failed");
   913     CleanupClosePushL(settingsFile);  
   933         fs.Close();
   914 
   934         return;     
       
   935         }
       
   936     
   915     // write the header
   937     // write the header
   916     line.Copy(KPIProfilerSettingsHeader);
   938     line.Copy(KPIProfilerSettingsHeader);
   917     line.Append(KNewLineSeparator);
   939     line.Append(KNewLineSeparator);
   918     line.Append(KNewLineSeparator);
   940     line.Append(KNewLineSeparator);
   919     settingsFile.Write(line);
   941     settingsFile.Write(line);
   994     iSamplerHandler->GetSamplerAttributesL(iDefaultSamplerAttributesArray);
  1016     iSamplerHandler->GetSamplerAttributesL(iDefaultSamplerAttributesArray);
   995     
  1017     
   996     // call CSamplerController to write all sampler settings
  1018     // call CSamplerController to write all sampler settings
   997     iSamplerHandler->ComposeAttributesToSettingsFileFormat(settingsFile, iDefaultSamplerAttributesArray);
  1019     iSamplerHandler->ComposeAttributesToSettingsFileFormat(settingsFile, iDefaultSamplerAttributesArray);
   998     
  1020     
   999     CleanupStack::PopAndDestroy(); //settingsFile
  1021     settingsFile.Close();
  1000     // close file
  1022     // close file
  1001     fs.Close();
  1023     fs.Close();
  1002     }
  1024     }
  1003 
  1025 
  1004 TInt CProfiler::CheckOldProfilerRunning()
  1026 TInt CProfiler::CheckOldProfilerRunning()
  1392 	LOGTEXT(_L("CPServer::NewL - Enter"));
  1414 	LOGTEXT(_L("CPServer::NewL - Enter"));
  1393 	CPServer* self = new(ELeave) CPServer(aPriority, aEngine);
  1415 	CPServer* self = new(ELeave) CPServer(aPriority, aEngine);
  1394 	CleanupStack::PushL(self);
  1416 	CleanupStack::PushL(self);
  1395 	self->StartL(KProfilerName);
  1417 	self->StartL(KProfilerName);
  1396 	CleanupStack::Pop();
  1418 	CleanupStack::Pop();
  1397 	LOGTEXT(_L("CPSession::NewL - Exit"));
  1419 	LOGTEXT(_L("CPServer::NewL - Exit "));
  1398 	return self;
  1420 	return self;
  1399     }
  1421     }
  1400 
  1422 
  1401 // --------------------------------------------------------------------------------------------
  1423 // --------------------------------------------------------------------------------------------
  1402 CPServer::CPServer(TInt aPriority, MProfilerEngine& aEngine)
  1424 CPServer::CPServer(TInt aPriority, MProfilerEngine& aEngine)
  1422  * Static methods for controlling the profiler
  1444  * Static methods for controlling the profiler
  1423  * through command line
  1445  * through command line
  1424  *
  1446  *
  1425  */
  1447  */
  1426 // --------------------------------------------------------------------------------------------
  1448 // --------------------------------------------------------------------------------------------
  1427 static void RunEngineServerL(const TDesC& aSettingsFile)
  1449 static void RunEngineServerL(const TDesC& aSettingsFile, TBool aBoot)
  1428     {
  1450     {
  1429 	RDebug::Print(_L("Profiler: RunEngineServerL() - Install active scheduler"));
  1451 	LOGSTRING("Profiler: RunEngineServerL() - Install active scheduler");
  1430 	CActiveScheduler* pS = new CActiveScheduler;
  1452 	CActiveScheduler* pS = new CActiveScheduler;
  1431 	CActiveScheduler::Install(pS);
  1453 	CActiveScheduler::Install(pS);
  1432 	CProfiler* p = CProfiler::NewLC(aSettingsFile);
  1454 	CProfiler* p = CProfiler::NewLC(aSettingsFile, aBoot);
       
  1455 	
       
  1456 	LOGSTRING("Profiler: RunEngineServerL() - Starting active scheduler");
  1433 	CActiveScheduler::Start();
  1457 	CActiveScheduler::Start();
  1434 	p->Finalise();
  1458 	p->Finalise();
       
  1459 	LOGSTRING("Profiler: RunEngineServerL() - profiler finalised");
  1435 	CleanupStack::PopAndDestroy(p);
  1460 	CleanupStack::PopAndDestroy(p);
  1436 	delete pS;
  1461 	delete pS;
       
  1462 	LOGSTRING("Profiler: RunEngineServerL() - done");
  1437     }
  1463     }
  1438 
  1464 
  1439 // --------------------------------------------------------------------------------------------
  1465 // --------------------------------------------------------------------------------------------
  1440 static TInt TestSettingsFile(const TDesC& configFile)
  1466 static TInt TestSettingsFile(const TDesC& configFile)
  1441     {
  1467     {
  1475     }
  1501     }
  1476 
  1502 
  1477 // --------------------------------------------------------------------------------------------
  1503 // --------------------------------------------------------------------------------------------
  1478 GLDEF_C TInt E32Main()
  1504 GLDEF_C TInt E32Main()
  1479     {
  1505     {
       
  1506     LOGSTRING("Profiler: E32Main()");
  1480     // parse command line arguments 
  1507     // parse command line arguments 
  1481     TBuf<256> c;
  1508     TBuf<256> c;
  1482     TInt err(KErrNone);
  1509     TInt err(KErrNone);
  1483     
  1510     _LIT(KBootMeasurement,"*boot");
       
  1511     
       
  1512     TBool myBoot(EFalse);
  1484     // copy the full command line with arguments into a buffer
  1513     // copy the full command line with arguments into a buffer
  1485     User::CommandLine(c);
  1514     User::CommandLine(c);
  1486 
  1515 
       
  1516     // parse command line for boot mode. filename boot
       
  1517     
       
  1518             
       
  1519     if (c.Match(KBootMeasurement) != KErrNotFound)
       
  1520        {
       
  1521        LOGTEXT(_L("ParseCommandAndExecute Found keyword boot"));
       
  1522        myBoot = ETrue;
       
  1523        }    
       
  1524     
       
  1525     TBuf<256> temp;
       
  1526     temp.Append(c);
       
  1527     TLex lex(temp);
       
  1528     lex.Mark();
       
  1529     lex.SkipCharacters();
       
  1530     
       
  1531     TPtrC token;
  1487     TBuf<256> fileName;
  1532     TBuf<256> fileName;
  1488     fileName.Append(c); // only one settings param should be
  1533     
  1489     LOGSTRING3("Filename is %S, response %d 1", &fileName, err);
  1534     if(lex.TokenLength() != 0)
  1490     err = TestSettingsFile(fileName);
  1535         {
  1491     if(err != KErrNone)
  1536         TPtrC token = lex.MarkedToken();
  1492         {
  1537         LOGSTRING2("E32 Main Token 1 %S",&token);
  1493         LOGSTRING3("Filename is %S, response %d 2", &fileName, err);
  1538         fileName.Append(token); // only one settings param should be
  1494         // settings file does not exist, copy null desc to file name
  1539         LOGSTRING3("Filename is #%S#, response %d 1", &fileName, err);
  1495         fileName.Copy(KNullDesC);
  1540         err = TestSettingsFile(fileName);
  1496         }
  1541         if(err != KErrNone)
  1497 
  1542             {
  1498     LOGSTRING3("Filename is %S, response %d 3", &fileName, err);
  1543             LOGSTRING3("Filename is #%S#, response %d 2", &fileName, err);
  1499     
  1544             // settings file does not exist, copy null desc to file name
       
  1545             fileName.Copy(KNullDesC);
       
  1546             }
       
  1547         }
       
  1548     else
       
  1549         {
       
  1550         LOGTEXT(_L("E32 Main Problem 1 in parsing command line"));
       
  1551         }
       
  1552 
  1500     // if no command line arguments found just start the profiler process
  1553     // if no command line arguments found just start the profiler process
  1501     __UHEAP_MARK;
  1554     __UHEAP_MARK;
  1502     CTrapCleanup* cleanup = CTrapCleanup::New();
  1555     CTrapCleanup* cleanup = CTrapCleanup::New();
  1503     TInt ret(KErrNoMemory);
  1556     TInt ret(KErrNoMemory);
       
  1557     err = KErrNoMemory;
  1504     if( cleanup )
  1558     if( cleanup )
  1505         {
  1559         {
  1506         TRAPD( ret, RunEngineServerL(fileName) );
  1560         TRAPD(err ,RunEngineServerL(fileName, myBoot));
  1507         RDebug::Print(_L("Profiler: E32Main() - ret %d"), ret);
  1561         LOGSTRING3("Profiler: E32Main() - ret %d err %d", ret,err);
  1508         delete cleanup;
  1562         if(err != KErrNone)
       
  1563             {
       
  1564             RDebug::Print(_L("if Profiler: E32Main() - ret %d err %d"), ret,err);
       
  1565             ret = err;
       
  1566             delete cleanup;
       
  1567             }
       
  1568         else
       
  1569             {
       
  1570             LOGSTRING3("else Profiler: E32Main() - ret %d err %d", ret,err);
       
  1571             ret = err;
       
  1572             delete cleanup;    
       
  1573             }
  1509         } 
  1574         } 
  1510     __UHEAP_MARKEND;
  1575     __UHEAP_MARKEND;
  1511 
  1576 
  1512     return ret;
  1577     return ret;
  1513     } 
  1578     }