sysanadatacapture/piprofiler/piprofiler/plugins/GeneralsPlugin/src/GeneralsPlugin.cpp
changeset 2 6a82cd05fb1e
parent 1 3ff3fecb12fe
equal deleted inserted replaced
1:3ff3fecb12fe 2:6a82cd05fb1e
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18  
       
    19 #include "GeneralsPlugin.h"	
       
    20 #include <piprofiler/EngineUIDs.h>
       
    21 #include <piprofiler/ProfilerTraces.h>
       
    22 
       
    23 const TInt KMaxSamplerAmount = 20;
       
    24 
       
    25 // LITERALS
       
    26 _LIT8(KEnabled, "enabled");
       
    27 _LIT8(KSamplingPeriod, "sampling_period_ms");
       
    28 _LIT8(KBracketOpen, "[");
       
    29 _LIT8(KBracketClose, "]");
       
    30 
       
    31 /*
       
    32  *	
       
    33  *	class CGeneralsPlugin implementation
       
    34  * 
       
    35  */
       
    36  
       
    37 CGeneralsPlugin* CGeneralsPlugin::NewL(const TUid aImplementationUid, TAny* /*aInitParams*/)
       
    38     {
       
    39 	LOGTEXT(_L("CGeneralsPlugin::NewL() - entry"));
       
    40     CGeneralsPlugin* self = new (ELeave) CGeneralsPlugin();
       
    41     CleanupStack::PushL( self );
       
    42     self->ConstructL();
       
    43     CleanupStack::Pop();
       
    44 	LOGTEXT(_L("CGeneralsPlugin::NewL() - exit"));
       
    45     return self;
       
    46     }
       
    47 
       
    48 CGeneralsPlugin::CGeneralsPlugin() :
       
    49 	iVersionDescriptor(&(this->iVersion[1]),0,19)
       
    50 	{
       
    51 	iSamplerType = PROFILER_KERNEL_MODE_SAMPLER;
       
    52 	iSamplerId = PROFILER_GENERALS_SAMPLER_ID;
       
    53 	iBufferHandler = NULL;
       
    54     iEnabled = EFalse;
       
    55 	LOGTEXT(_L("CGeneralsPlugin::CGeneralsPlugin() - constructor"));
       
    56 	}
       
    57 
       
    58 void CGeneralsPlugin::ConstructL() 
       
    59     {
       
    60 	LOGTEXT(_L("CGeneralsPlugin::ConstructL() - entry"));
       
    61 	
       
    62 	// create attribute array
       
    63 	iSamplerAttributes = new(ELeave) CArrayFixFlat<TSamplerAttributes>(KSubSamplerCount);
       
    64 	
       
    65 	TInt err = InitiateSamplerL();
       
    66 	if( err != KErrNone )
       
    67 		{
       
    68 			LOGTEXT(_L("CGeneralsPlugin::ConstructL - LEAVING, failed to load open sampler device"));
       
    69 			User::Leave(err);
       
    70 		}
       
    71 	
       
    72 	// initiate sampler attributes, i.e. settings for modification
       
    73 	InitiateSamplerAttributesL();
       
    74 	
       
    75 	LOGTEXT(_L("CGeneralsPlugin::ConstructL() - exit"));
       
    76     }
       
    77 
       
    78 
       
    79 CGeneralsPlugin::~CGeneralsPlugin()
       
    80 	{
       
    81 	// clean all the members
       
    82 	CleanSampler();	// clean the created sampler
       
    83 	}
       
    84 
       
    85 TInt CGeneralsPlugin::InitiateSamplerL()
       
    86 	{
       
    87 	RThread me;
       
    88 	
       
    89 	LOGTEXT(_L("CGeneralsPlugin::InitiateSamplerL - #1"));
       
    90 
       
    91 	me.SetPriority(EPriorityRealTime);
       
    92 
       
    93 	LOGTEXT(_L("CGeneralsPlugin::InitiateSamplerL - #2"));
       
    94 	
       
    95 	// create 
       
    96 	User::FreeLogicalDevice(KPluginSamplerName);
       
    97 	TInt err(KErrGeneral);
       
    98 	
       
    99 	LOGTEXT(_L("CGeneralsPlugin::InitiateSamplerL - #3"));
       
   100 
       
   101     err = User::LoadLogicalDevice(KPluginSamplerName);
       
   102     if(err != KErrNone)
       
   103         {
       
   104         User::Leave(err);
       
   105         }
       
   106 
       
   107 	LOGTEXT(_L("CGeneralsPlugin::InitiateSamplerL - #4"));
       
   108 	
       
   109 	err = KErrGeneral;
       
   110 
       
   111     err = iGeneralsSampler.Open();
       
   112     if(err != KErrNone)
       
   113         {
       
   114         LOGSTRING2("CGeneralsPlugin::InitiateSamplerL - Could not open sampler device - waiting and trying again: %d", err);
       
   115         User::Leave(err);
       
   116         }
       
   117 
       
   118 	LOGTEXT(_L("CGeneralsPlugin::InitiateSamplerL - #5"));
       
   119 
       
   120 	return err;
       
   121 	}
       
   122 
       
   123 /* 
       
   124  * 
       
   125  * Default sampler attributes
       
   126  * 
       
   127  */
       
   128 void CGeneralsPlugin::InitiateSamplerAttributesL()
       
   129     {
       
   130 
       
   131     // 
       
   132     for(TInt i(0);i<KMaxSamplerAmount;i++)
       
   133         {
       
   134         switch(i)
       
   135             {
       
   136 // Usage:
       
   137 //            TSamplerAttributes(TUint32 aUid,
       
   138 //                    const TDesC8& aShortName,
       
   139 //                    const TDesC& aName,
       
   140 //                    const TDesC& aDescription,
       
   141 //                    TInt aSampleRate,
       
   142 //                    TBool aEnabled,
       
   143 //                    TBool aHidden,
       
   144 //                    TUint32 aItemCount);
       
   145             case PROFILER_GPP_SAMPLER_ID:
       
   146                 {
       
   147                 TSamplerAttributes attr(KSamplerGppPluginUid.iUid,
       
   148                         KGPPShortName(),
       
   149                         KGPPLongName(),
       
   150                         KGPPDescription(),
       
   151                         1,
       
   152                         ETrue,
       
   153                         ETrue,
       
   154                         0);
       
   155                 iSamplerAttributes->AppendL(attr);
       
   156                 break;
       
   157                 }
       
   158             case PROFILER_GFC_SAMPLER_ID:
       
   159                 {
       
   160                 TSamplerAttributes attr2(KSamplerGfcPluginUid.iUid,
       
   161                         KGFCShortName(),
       
   162                         KGFCLongName(),
       
   163                         KGFCDescription(),
       
   164                         -1,
       
   165                         EFalse,
       
   166                         EFalse,
       
   167                         0);
       
   168                 this->iSamplerAttributes->AppendL(attr2);
       
   169                 break;
       
   170                 }
       
   171             case PROFILER_ITT_SAMPLER_ID:
       
   172                 {
       
   173                 TSamplerAttributes attr3(KSamplerIttPluginUid.iUid,
       
   174                         KITTShortName(),
       
   175                         KITTLongName(),
       
   176                         KITTDescription(),
       
   177                         -1,
       
   178                         EFalse,
       
   179                         EFalse,
       
   180                         0);
       
   181                 this->iSamplerAttributes->AppendL(attr3);
       
   182                 break;
       
   183                 }
       
   184             case PROFILER_MEM_SAMPLER_ID:
       
   185                 {
       
   186                 TSamplerAttributes attr4(KSamplerMemPluginUid.iUid,
       
   187                         KMEMShortName(),
       
   188                         KMEMLongName(),
       
   189                         KMEMDescription(),
       
   190                         3000,
       
   191                         EFalse,
       
   192                         EFalse,
       
   193                         0);
       
   194                 this->iSamplerAttributes->AppendL(attr4);
       
   195                 break;
       
   196                 }
       
   197             case PROFILER_PRI_SAMPLER_ID:
       
   198                 {
       
   199                 TSamplerAttributes attr5(KSamplerPriPluginUid.iUid,
       
   200                         KPRIShortName(),
       
   201                         KPRILongName(),
       
   202                         KPRIDescription(),
       
   203                         3000,
       
   204                         EFalse,
       
   205                         EFalse,
       
   206                         0);
       
   207                 this->iSamplerAttributes->AppendL(attr5);
       
   208                 break;
       
   209                 }
       
   210             }
       
   211         }
       
   212     }
       
   213 
       
   214 TInt CGeneralsPlugin::CleanSampler()
       
   215 	{
       
   216     LOGTEXT(_L("CGeneralsPlugin::CleanSampler() - deleting buffer handler"));
       
   217     // release the buffer handler
       
   218     if(iBufferHandler)
       
   219         {
       
   220         iBufferHandler->Cancel();
       
   221         delete iBufferHandler;
       
   222         iBufferHandler = NULL;
       
   223         }
       
   224     
       
   225     LOGTEXT(_L("CGeneralsPlugin::CleanSampler() - closing sampler"));
       
   226 	iGeneralsSampler.Close();
       
   227 	
       
   228 	LOGTEXT(_L("CGeneralsPlugin::CleanSampler() - Freeing sampler device"));
       
   229 	User::FreeLogicalDevice(KPluginSamplerName);
       
   230 	
       
   231 	// release attribute array
       
   232 	if(iSamplerAttributes)
       
   233 	    {
       
   234 	    iSamplerAttributes->Reset();
       
   235 	    }
       
   236     delete iSamplerAttributes;
       
   237     iSamplerAttributes = NULL;
       
   238 
       
   239 	LOGTEXT(_L("CGeneralsPlugin::CleanSampler() - exit"));
       
   240 
       
   241 	return KErrNone;
       
   242 	}
       
   243 
       
   244 // returns setting array
       
   245 void CGeneralsPlugin::GetAttributesL(CArrayFixFlat<TSamplerAttributes>* aAttributes)
       
   246     {
       
   247     TInt count(iSamplerAttributes->Count());
       
   248     // append all sampler attributes to aAttributes array
       
   249     for(TInt i(0);i<count;i++)
       
   250         {
       
   251         aAttributes->AppendL(iSamplerAttributes->At(i));
       
   252         }
       
   253     }
       
   254 
       
   255 TInt CGeneralsPlugin::SetAttributesL(TSamplerAttributes aAttributes)
       
   256     {
       
   257     TSamplerAttributes attr;
       
   258 
       
   259     TInt count(iSamplerAttributes->Count());
       
   260     // loop the sub sampler attributes (by UID)
       
   261     for(TInt i(0);i<count;i++)
       
   262         {
       
   263         attr = iSamplerAttributes->At(i);
       
   264         // if UIDs match replace the old 
       
   265         if(attr.iUid == aAttributes.iUid)
       
   266             {
       
   267             // replace the old attribute container
       
   268             iSamplerAttributes->Delete(i);
       
   269             iSamplerAttributes->InsertL(i, aAttributes);
       
   270             return KErrNone;
       
   271             }
       
   272         }
       
   273     return KErrNotFound;
       
   274     }
       
   275 
       
   276 /* 
       
   277  * Method for parsing and transforming text array settings into TSamplerAttributes (per each sub sampler),
       
   278  * called by CSamplerController class
       
   279  * 
       
   280  * @param array of raw text setting lines, e.g. [gpp]\nenabled=true\nsampling_period_ms=1\n
       
   281  */
       
   282 TInt CGeneralsPlugin::ConvertRawSettingsToAttributes(CDesC8ArrayFlat* aAllSettingsArray)
       
   283     {
       
   284     // local literals
       
   285     _LIT8(KGPPShort, "gpp");
       
   286     _LIT8(KGFCShort, "gfc");
       
   287     _LIT8(KITTShort, "itt");
       
   288     _LIT8(KMEMShort, "mem");
       
   289     _LIT8(KPRIShort, "pri");
       
   290 
       
   291     TInt err(KErrNone);
       
   292     
       
   293     TBuf8<16> samplerSearchName;
       
   294     
       
   295     // loop previous settings, update value if changed
       
   296     for(TInt i(0);i<KSubSamplerCount;i++)
       
   297         {
       
   298         // go through all the sub samplers
       
   299         switch (i)
       
   300             {
       
   301             case 0:
       
   302                 samplerSearchName.Copy(KGPPShort);
       
   303                 break;
       
   304             case 1:
       
   305                 samplerSearchName.Copy(KGFCShort);
       
   306                 break;
       
   307             case 2:
       
   308                 samplerSearchName.Copy(KITTShort);
       
   309                 break;
       
   310             case 3:
       
   311                 samplerSearchName.Copy(KMEMShort);
       
   312                 break;
       
   313             case 4:
       
   314                 samplerSearchName.Copy(KPRIShort);
       
   315                 break;
       
   316             }
       
   317 
       
   318         // get sampler specific settings  
       
   319         err = DoSetSamplerSettings(aAllSettingsArray, samplerSearchName, i);
       
   320         }
       
   321     
       
   322     // returns KErrNone if settings found, otherwise KErrNotFound
       
   323     return err;
       
   324     }
       
   325 
       
   326 /**
       
   327  * Method for searching sampler specific settings among all settings (raw setting lines read from settings file)
       
   328  * 
       
   329  * @param aAllSettings array of all settings from settings file
       
   330  * @param aSamplerName short name of sampler to be searched among the settings
       
   331  * @param aIndex index number of sampler specific sampler attributes (TSamplerAttributes)
       
   332  * @return KErrNone if settings found ok else KErrNotFound
       
   333  */
       
   334 TInt CGeneralsPlugin::DoSetSamplerSettings(CDesC8ArrayFlat* aAllSettings, TDesC8& aSamplerName, TInt aIndex)
       
   335     {
       
   336     // sampler name to be searched among the all settings
       
   337     TBuf8<16> samplerSearch;
       
   338     samplerSearch.Copy(KBracketOpen);
       
   339     samplerSearch.Append(aSamplerName);
       
   340     samplerSearch.Append(KBracketClose);
       
   341     
       
   342     // read a line from ALL settings array
       
   343     for (TInt i(0); i<aAllSettings->MdcaCount(); i++)
       
   344         {
       
   345         // check if this line has a setting block start, i.e. contains [xxx] in it
       
   346         if (aAllSettings->MdcaPoint(i).CompareF(samplerSearch) == 0)
       
   347             {
       
   348             // right settings block found, now loop until the next block is found
       
   349             for(TInt j(i+1);j<aAllSettings->MdcaCount();j++)
       
   350                 {
       
   351                 // check if the next settings block was found
       
   352                 if(aAllSettings->MdcaPoint(j).Left(1).CompareF(KBracketOpen) != 0)
       
   353                     {
       
   354                     // save found setting value directly to its owners attributes
       
   355                     SaveSettingToAttributes(aAllSettings->MdcaPoint(j), aIndex);
       
   356                     }
       
   357                 else
       
   358                     {
       
   359                     // next block found, return KErrNone
       
   360                     return KErrNone;
       
   361                     }
       
   362                 }
       
   363             }
       
   364         }
       
   365     // no settings found for specific sampler
       
   366     return KErrNotFound;
       
   367     }
       
   368 
       
   369 /**
       
   370  * Method for setting a specific descriptor (from settings file) to attribute structure
       
   371  * 
       
   372  * @param aSetting  
       
   373  * @param aName  
       
   374  */
       
   375 void CGeneralsPlugin::SaveSettingToAttributes(const TDesC8& aSetting, TInt aIndex)
       
   376     {
       
   377     // local literals
       
   378     _LIT8(KSettingItemSeparator, "=");
       
   379     
       
   380     // find the equal mark from the setting line
       
   381     TInt sepPos = aSetting.Find(KSettingItemSeparator);
       
   382     // check that '=' is found
       
   383     if (sepPos > 0)
       
   384         {
       
   385         // check that the element matches
       
   386         if (aSetting.Left(sepPos).CompareF(KEnabled) == 0)
       
   387             {
       
   388             TBool en;
       
   389             CSamplerPluginInterface::Str2Bool(aSetting.Right(aSetting.Length()-sepPos-1), en);
       
   390             if(en != iSamplerAttributes->At(aIndex).iEnabled)
       
   391                 {
       
   392                 iSamplerAttributes->At(aIndex).iEnabled = en;
       
   393                 }
       
   394             }
       
   395         else if (aSetting.Left(sepPos).CompareF(KSamplingPeriod) == 0)
       
   396             {
       
   397             TInt sr;
       
   398             CSamplerPluginInterface::Str2Int(aSetting.Right(aSetting.Length()-sepPos-1), sr);
       
   399             if(sr != iSamplerAttributes->At(aIndex).iSampleRate)
       
   400                 {
       
   401                 iSamplerAttributes->At(aIndex).iSampleRate = sr;
       
   402                 }
       
   403             }
       
   404         }
       
   405     }
       
   406 
       
   407 
       
   408 TUid CGeneralsPlugin::Id(TInt aSubId) const
       
   409 	{
       
   410 		if(aSubId == PROFILER_GPP_SAMPLER_ID)		
       
   411 			return KSamplerGppPluginUid;
       
   412 		else if (aSubId == PROFILER_GFC_SAMPLER_ID)		
       
   413 			return KSamplerGfcPluginUid;
       
   414 		else if (aSubId == PROFILER_ITT_SAMPLER_ID)		
       
   415 			return KSamplerIttPluginUid;
       
   416 		else if (aSubId == PROFILER_MEM_SAMPLER_ID)		
       
   417 			return KSamplerMemPluginUid;
       
   418 		else if (aSubId == PROFILER_PRI_SAMPLER_ID)		
       
   419 			return KSamplerPriPluginUid;
       
   420 		else
       
   421 			return KSamplerGeneralsPluginUid;
       
   422 	}
       
   423 
       
   424 TInt CGeneralsPlugin::SubId(TUid aId) const
       
   425 	{
       
   426 /* definitions from ProfilerConfig.h:
       
   427  * 	#define		PROFILER_GPP_SAMPLER_ID			1
       
   428 	#define		PROFILER_GFC_SAMPLER_ID			2
       
   429 	#define		PROFILER_ITT_SAMPLER_ID			3
       
   430 	#define		PROFILER_MEM_SAMPLER_ID			4
       
   431 	#define		PROFILER_PRI_SAMPLER_ID			5
       
   432  */
       
   433 	
       
   434 		if(aId == KSamplerGppPluginUid)		
       
   435 			return PROFILER_GPP_SAMPLER_ID;
       
   436 		else if (aId == KSamplerGfcPluginUid)		
       
   437 			return PROFILER_GFC_SAMPLER_ID;
       
   438 		else if (aId == KSamplerIttPluginUid)		
       
   439 			return PROFILER_ITT_SAMPLER_ID;
       
   440 		else if (aId == KSamplerMemPluginUid)		
       
   441 			return PROFILER_MEM_SAMPLER_ID;
       
   442 		else if (aId == KSamplerPriPluginUid)		
       
   443 			return PROFILER_PRI_SAMPLER_ID;
       
   444 		else
       
   445 			return KErrNotFound;
       
   446 	}
       
   447 
       
   448 TInt CGeneralsPlugin::GetSamplerType()
       
   449 	{
       
   450 	return iSamplerType;
       
   451 	}
       
   452 
       
   453 //TInt CGeneralsPlugin::GetSubCount()
       
   454 //	{
       
   455 //	return (TInt)KSubSamplerCount;
       
   456 //	}
       
   457 
       
   458 
       
   459 TInt CGeneralsPlugin::GetSamplerUidByName(TDesC8& aName)
       
   460 	{
       
   461 	if(aName.Compare(KGPPShortName) == 0)
       
   462 		{
       
   463 			LOGTEXT(_L("GPP trace option"));
       
   464 			return KSamplerGppPluginUid.iUid;
       
   465 		}
       
   466 	else if(aName.Compare(KGFCShortName) == 0)
       
   467 		{
       
   468 			LOGTEXT(_L("GFC trace option"));
       
   469 			return KSamplerGfcPluginUid.iUid;
       
   470 		}
       
   471 	else if(aName.Compare(KITTShortName) == 0)
       
   472 		{
       
   473 			LOGTEXT(_L("ITT trace option"));
       
   474 			return KSamplerIttPluginUid.iUid;
       
   475 		}
       
   476 	else if(aName.Compare(KMEMShortName) == 0)
       
   477 		{
       
   478 			LOGTEXT(_L("MEM trace option"));
       
   479 			return KSamplerMemPluginUid.iUid;
       
   480 		}
       
   481 	else if(aName.Compare(KPRIShortName) == 0)
       
   482 		{
       
   483 			LOGTEXT(_L("PRI trace option"));
       
   484 			return KSamplerPriPluginUid.iUid;
       
   485 		}
       
   486 
       
   487 	return -1;
       
   488 
       
   489 	}
       
   490 
       
   491 void CGeneralsPlugin::GetCaption( TDes& aCaption, TInt aType, TInt aSubId ) const
       
   492     {
       
   493     if(aSubId == -1)
       
   494     	{
       
   495     	aCaption.Copy(_L(""));
       
   496     	return;
       
   497     	}
       
   498     else if(aSubId == KSamplerGppPluginUid.iUid)
       
   499     	{
       
   500 		aCaption.Copy(KGPPShortName);
       
   501     	}
       
   502     else if(aSubId == KSamplerIttPluginUid.iUid)
       
   503     	{
       
   504     	aCaption.Copy(KITTShortName);
       
   505     	}
       
   506     else if(aSubId == KSamplerGfcPluginUid.iUid)
       
   507     	{
       
   508     	aCaption.Copy(KGFCShortName);
       
   509     	}
       
   510     else if(aSubId == KSamplerMemPluginUid.iUid)
       
   511     	{
       
   512     	aCaption.Copy(KMEMShortName);
       
   513     	}
       
   514     else if(aSubId == KSamplerPriPluginUid.iUid)
       
   515     	{
       
   516 		aCaption.Copy(KPRIShortName);
       
   517     	}
       
   518     else
       
   519     	{
       
   520     	aCaption.Copy(KGENShortName);
       
   521     	}
       
   522 
       
   523     aCaption.TrimRight();
       
   524     LOGSTRING2("CGeneralsPlugin::GetCaptionL() - plug-in name: %S", &aCaption);
       
   525     }
       
   526 
       
   527 
       
   528 void CGeneralsPlugin::InstallStreamForActiveTraces(RGeneralsSampler& sampler, CProfilerSampleStream& aStream)
       
   529 	{
       
   530 	// output mode for this trace is stream
       
   531 	if(!iBufferHandler)
       
   532 		{
       
   533 		// stream object has not been created yet
       
   534 		LOGTEXT(_L("CGeneralsPlugin::InstallStreamForActiveTraces - creating stream for trace"));	
       
   535 		
       
   536 		// use a 32KB buffer to transfer data from sampler to client
       
   537 		// commonStream = new RProfilerSampleStream(sampler,totalPrefix,32768);
       
   538 		TRAPD(err, iBufferHandler = CProfilerBufferHandler::NewL(aStream, sampler));
       
   539 		if(err != KErrNone)
       
   540 		    {
       
   541 		    LOGTEXT(_L("CGeneralsPlugin::InstallStreamForActiveTraces() - No memory"));
       
   542 		    return;
       
   543 		    }
       
   544 		}
       
   545 
       
   546 	// initiate receiving of data from the sampler device driver
       
   547 	if(iBufferHandler)
       
   548 		{
       
   549 		iBufferHandler->StartReceivingData();
       
   550 		}
       
   551 }
       
   552 
       
   553 void CGeneralsPlugin::SetSettingsToSamplers()
       
   554     {
       
   555     TSamplerAttributes attr;
       
   556     
       
   557     // loop through the setting attributes
       
   558     for(TInt i(0);i<iSamplerAttributes->Count();i++)
       
   559         {
       
   560         // get the attribute container
       
   561         attr = iSamplerAttributes->At(i);
       
   562         
       
   563         // make changes according to right sampler, NOTE! The old IDs of sub samplers (i+1)!
       
   564         if(attr.iEnabled)
       
   565             {
       
   566             iGeneralsSampler.MarkTraceActive(i+1);
       
   567             
       
   568             // set enabled
       
   569             iEnabled = ETrue;
       
   570             }
       
   571         else
       
   572             {
       
   573             iGeneralsSampler.MarkTraceInactive(i+1);
       
   574             }
       
   575         // set sampling period if available
       
   576         if(attr.iSampleRate != KErrNotFound)
       
   577             {
       
   578             iGeneralsSampler.SetSamplingPeriod(i+1, attr.iSampleRate);
       
   579             }
       
   580         }
       
   581     }
       
   582 
       
   583 TInt CGeneralsPlugin::ResetAndActivateL(CProfilerSampleStream& aStream) 
       
   584     {
       
   585 	// the sampler starting functionality
       
   586 	LOGTEXT(_L("CGeneralsPlugin::ResetAndActivate() - entry"));
       
   587 
       
   588     // now before starting the latest settings must be set to samplers itself
       
   589 	SetSettingsToSamplers();
       
   590 
       
   591 	if(Enabled())
       
   592 	    {
       
   593         LOGTEXT(_L("CGeneralsPlugin::ResetAndActivate() - starting sampling..."));
       
   594         // start sampling process of enabled sub samplers
       
   595         iGeneralsSampler.StartSampling();		
       
   596         LOGTEXT(_L("CGeneralsPlugin::ResetAndActivate() - installing stream for an active trace..."));
       
   597     
       
   598         // install the trace for enabled samplers
       
   599         InstallStreamForActiveTraces(iGeneralsSampler, aStream);
       
   600         LOGSTRING2("CGeneralsPlugin::ResetAndActivate() - stream installed: 0x%x", aStream);
       
   601 	    }
       
   602 	
       
   603 	LOGTEXT(_L("CGeneralsPlugin::ResetAndActivate() - exit"));
       
   604 	return KErrNone;
       
   605     }
       
   606 	
       
   607 TInt CGeneralsPlugin::StopSampling() 
       
   608     {
       
   609     // RDebug::Print(_L("CGeneralsPlugin::StopSampling() - Stopping sampler LDD"));
       
   610 	iGeneralsSampler.StopSampling();
       
   611 	// RDebug::Print(_L("CGeneralsPlugin::StopSampling() - Sampler LDD stopped"));
       
   612 	
       
   613 	// check if bufferhandler has died
       
   614 	if(iBufferHandler)
       
   615 		{
       
   616 		// RDebug::Print(_L("CGeneralsPlugin::StopSampling() - Canceling the buffer handler"));
       
   617 		iBufferHandler->Cancel();
       
   618 		delete iBufferHandler;
       
   619 		iBufferHandler = NULL;
       
   620 		}	
       
   621 	// set enabled
       
   622     iEnabled = EFalse;
       
   623     // RDebug::Print(_L("CGeneralsPlugin::StopSampling() - exit"));
       
   624 	return KErrNone;
       
   625     }
       
   626 
       
   627 
       
   628