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