piprofiler/plugins/GeneralsPlugin/inc/GppSamplerImpl.h
changeset 22 a009639409f5
equal deleted inserted replaced
17:67c6ff54ec25 22:a009639409f5
       
     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 #ifndef PROFILER_GPP_SAMPLER_H
       
    20 #define PROFILER_GPP_SAMPLER_H
       
    21 
       
    22 #include "GeneralsConfig.h"
       
    23 
       
    24 #include <e32cmn.h>
       
    25 
       
    26 #include <piprofiler/ProfilerGenericClassesKrn.h>
       
    27 #include <piprofiler/ProfilerTraces.h>
       
    28 
       
    29 // for RPropertyRef
       
    30 #include <sproperty.h> 
       
    31 #include <e32cmn.h>
       
    32 
       
    33 /*
       
    34  *	
       
    35  *	GPP sampler definition
       
    36  *	
       
    37  */
       
    38 class DGppSamplerImpl //: public DBase
       
    39 {
       
    40 public:
       
    41 
       
    42 	DGppSamplerImpl();
       
    43 	~DGppSamplerImpl();
       
    44 
       
    45 	TUint8* EncodeTag(TUint8* aPtr);
       
    46 	TUint8* EncodeInt(TUint8* aPtr,TInt aValue);
       
    47 	TUint8* EncodeUint(TUint8* aPtr,TUint aValue);
       
    48 	TUint8* EncodeText(TUint8* aPtr, const TDesC& aDes);
       
    49 
       
    50 	TUint8* EncodeName(TUint8* aPtr, DObject& aObject,TUint32 id);
       
    51 	TUint8* EncodeThread(TUint8* aPtr, DThread& aThread);
       
    52 
       
    53 	TBool	IsaTaskKnown(TUint8 task);
       
    54 	TUint8* EncodeIsaTask(TUint8* aPtr, TUint task);
       
    55 	TUint8* EncodeIsaName(TUint8* aPtr, TUint task,TBool process);
       
    56 	
       
    57 	TUint8* EncodeRepeat(TUint8* aPtr);
       
    58 
       
    59 	TInt	CreateFirstSample();
       
    60 	TInt	SampleImpl();
       
    61 #ifdef __SMP__
       
    62     TSpinLock* LockPtr();
       
    63 #endif
       
    64     TInt    iGppSamplingPeriod;
       
    65 	TUint8	tempBuf[512];
       
    66 	TUint	iLastPc;
       
    67 	
       
    68 	TBool	iIsaSample;
       
    69 	TInt	knownIsaTasks[256];
       
    70 	TUint8	knownIsaTaskCount;
       
    71 	TInt*	isaOsTaskRunningAddr;
       
    72 	void	Reset();
       
    73     TUint32 iSampleCount;
       
    74 #ifdef __SMP__
       
    75     TInt        iCpuNumber;
       
    76     TUint32     iStartTime;
       
    77 #endif	   
       
    78 	PROFILER_DEFINE_ISA_TASK_NAME_ARRAY
       
    79 
       
    80 private:
       
    81 	enum TState {EStop,ERunning,EStopping};
       
    82 
       
    83 	const TUint* iInterruptStack;
       
    84 	
       
    85 	TUint		iLastThread;
       
    86 	TUint		iRepeat;
       
    87 #ifndef __SMP__
       
    88 	TUint32 	iStartTime;
       
    89 #endif
       
    90 	RPropertyRef iIsaStartAddr;
       
    91 	RPropertyRef iIsaEndAddr;
       
    92 	RPropertyRef iIsaPluginStatus;
       
    93 	RPropertyRef iIsaOsTaskRunning;
       
    94 	TInt 		iIsaStatus;
       
    95 	TInt 		iIsaStart;
       
    96 	TInt 		iIsaEnd;
       
    97 	TUint32     iMask;
       
    98 	TUint32     iCpuSelector;
       
    99 };
       
   100 
       
   101 struct TProfilerGppSamplerData
       
   102 {
       
   103 //public:
       
   104 	TUint32		lastPcValue;
       
   105 	TUint32		sampleNumber;
       
   106     TInt        samplingPeriod;
       
   107 };
       
   108 
       
   109 template <int BufferSize>
       
   110 class DProfilerGppSampler : public DProfilerGenericSampler<BufferSize>
       
   111 {
       
   112 public:
       
   113 #ifndef __SMP__
       
   114 	DProfilerGppSampler();
       
   115 #else
       
   116     DProfilerGppSampler(TInt aCpuNumber);
       
   117 #endif
       
   118 	~DProfilerGppSampler();
       
   119 
       
   120 	struct TProfilerGppSamplerData* GetExportData();
       
   121 	void	Sample();
       
   122 	TInt	Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset);
       
   123 	TInt 	GetPeriod();
       
   124 	
       
   125 private:
       
   126 	DGppSamplerImpl gppSamplerImpl;
       
   127 	struct TProfilerGppSamplerData exportData;
       
   128 #ifdef __SMP__
       
   129 	TInt   iCpuNumber;
       
   130 #endif
       
   131 };
       
   132 
       
   133 /*
       
   134  *	
       
   135  *	GPP sampler implementation
       
   136  *	
       
   137  */
       
   138 #ifndef __SMP__
       
   139 template <int BufferSize>
       
   140 DProfilerGppSampler<BufferSize>::DProfilerGppSampler() :
       
   141 	DProfilerGenericSampler<BufferSize>(PROFILER_GPP_SAMPLER_ID) 
       
   142     {
       
   143 	LOGSTRING2("CProfilerGppSampler<%d>::CProfilerGppSampler",BufferSize);
       
   144     }
       
   145 #else
       
   146 template <int BufferSize>
       
   147 DProfilerGppSampler<BufferSize>::DProfilerGppSampler(TInt aCpuNumber) :
       
   148     DProfilerGenericSampler<BufferSize>(PROFILER_GPP_SAMPLER_ID+(aCpuNumber*20)), iCpuNumber(aCpuNumber) 
       
   149     {
       
   150     LOGSTRING2("CProfilerGppSampler<%d>::CProfilerGppSampler",BufferSize);
       
   151     }
       
   152 #endif
       
   153 
       
   154 template <int BufferSize>
       
   155 DProfilerGppSampler<BufferSize>::~DProfilerGppSampler()
       
   156     {
       
   157 	LOGSTRING2("CProfilerGppSampler<%d>::~CProfilerGppSampler",BufferSize);		
       
   158     }
       
   159 
       
   160 template <int BufferSize>
       
   161 TInt DProfilerGppSampler<BufferSize>::Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset)
       
   162         {
       
   163 	LOGSTRING2("CProfilerGppSampler<%d>::Reset - calling superclass reset",BufferSize);
       
   164 	DProfilerGenericSampler<BufferSize>::Reset(aStream, 0);
       
   165 	LOGSTRING2("CProfilerGppSampler<%d>::Reset - called superclass reset",BufferSize);
       
   166 
       
   167 	this->gppSamplerImpl.Reset();
       
   168 	
       
   169 #ifdef __SMP__
       
   170 	this->gppSamplerImpl.iCpuNumber = this->iCpuNumber;
       
   171 	
       
   172 	// set common start time for all CPU samplers
       
   173 	this->gppSamplerImpl.iStartTime = aSyncOffset;
       
   174 #endif
       
   175 	this->gppSamplerImpl.iGppSamplingPeriod = this->iSamplingPeriod;
       
   176 	this->gppSamplerImpl.iSampleCount = 0;
       
   177 	this->exportData.sampleNumber = 0;
       
   178 	this->exportData.lastPcValue = 0;
       
   179     this->exportData.samplingPeriod = this->gppSamplerImpl.iGppSamplingPeriod;
       
   180 
       
   181 	TInt length = gppSamplerImpl.CreateFirstSample();
       
   182 	LOGSTRING3("CProfilerGPPSampler<%d>::Reset - got first sample, size %d",BufferSize,length);	
       
   183 	
       
   184 	this->iSampleBuffer->AddSample(gppSamplerImpl.tempBuf,length);
       
   185 
       
   186 	// check if sampling period > 1 ms
       
   187 	// NOTE: feature supported in Performance Investigator 2.01 and above
       
   188 	if(this->gppSamplerImpl.iGppSamplingPeriod > 1)
       
   189 	    {
       
   190         // For Address/Thread (GPP) version 2.01 or above, the first word is the sampling period in milliseconds
       
   191         TUint8* w = gppSamplerImpl.tempBuf;
       
   192         
       
   193         (*w++) = (this->gppSamplerImpl.iGppSamplingPeriod >> 24) & 0xFF;
       
   194         (*w++) = (this->gppSamplerImpl.iGppSamplingPeriod >> 16) & 0xFF;
       
   195         (*w++) = (this->gppSamplerImpl.iGppSamplingPeriod >>  8) & 0xFF;
       
   196         (*w++) = (this->gppSamplerImpl.iGppSamplingPeriod) & 0xFF;
       
   197         
       
   198         this->iSampleBuffer->AddSample(gppSamplerImpl.tempBuf,4);
       
   199 	    }
       
   200 	
       
   201 	LOGSTRING2("CProfilerGPPSampler<%d>::Reset finished",BufferSize);
       
   202 	return KErrNone;
       
   203     }
       
   204 
       
   205 template <int BufferSize>
       
   206 void DProfilerGppSampler<BufferSize>::Sample()
       
   207     {
       
   208 	LOGSTRING2("CProfilerGppSampler<%d>::Sample",BufferSize);
       
   209 //	if(this->gppSamplerImpl.iSampleCount % 1000 == 0) 
       
   210 //	    {
       
   211 //#ifdef __SMP__
       
   212 //	    if(this->iCpuNumber == 0)  // print sample tick only from CPU 0 context
       
   213 //	        {
       
   214 //#endif
       
   215 //	        Kern::Printf(("PIPROF SAMPLE TICK, #%d"),exportData.sampleNumber);
       
   216 //#ifdef __SMP__
       
   217 //	        }
       
   218 //#endif
       
   219 //	    }
       
   220 	
       
   221 	TInt length(gppSamplerImpl.SampleImpl());
       
   222 
       
   223     this->gppSamplerImpl.iSampleCount++;
       
   224 	this->exportData.sampleNumber += this->gppSamplerImpl.iGppSamplingPeriod;
       
   225 	this->exportData.lastPcValue = gppSamplerImpl.iLastPc;
       
   226 
       
   227 	if(length > 0)
       
   228         {
       
   229         this->iSampleBuffer->AddSample(gppSamplerImpl.tempBuf,length);
       
   230         }
       
   231 
       
   232 	LOGSTRING3("CProfilerGppSampler<%d>::Sample - length %d",BufferSize,length);
       
   233 
       
   234 	return;
       
   235     }
       
   236 
       
   237 
       
   238 template <int BufferSize>
       
   239 struct TProfilerGppSamplerData* DProfilerGppSampler<BufferSize>::GetExportData()
       
   240     {
       
   241 	LOGSTRING2("CProfilerGppSampler<%d>::GetExportData",BufferSize);
       
   242 	return &(this->exportData);	
       
   243     }
       
   244 
       
   245 template <int BufferSize>
       
   246 TInt DProfilerGppSampler<BufferSize>::GetPeriod()
       
   247     {
       
   248 	return this->gppSamplerImpl.iGppSamplingPeriod;
       
   249     }
       
   250 
       
   251 #endif