perfsrv/piprofiler/plugins/GeneralsPlugin/inc/GppSamplerImpl.h
changeset 62 1c2bb2fc7c87
parent 51 98307c651589
equal deleted inserted replaced
56:aa2539c91954 62:1c2bb2fc7c87
    94 	TInt 		iIsaStatus;
    94 	TInt 		iIsaStatus;
    95 	TInt 		iIsaStart;
    95 	TInt 		iIsaStart;
    96 	TInt 		iIsaEnd;
    96 	TInt 		iIsaEnd;
    97 	TUint32     iMask;
    97 	TUint32     iMask;
    98 	TUint32     iCpuSelector;
    98 	TUint32     iCpuSelector;
       
    99 	TInt        iPrevTS;   // previous sample's timestamp
    99 };
   100 };
   100 
   101 
   101 struct TProfilerGppSamplerData
   102 struct TProfilerGppSamplerData
   102 {
   103 {
   103 //public:
   104 //public:
   116     DProfilerGppSampler(TInt aCpuNumber);
   117     DProfilerGppSampler(TInt aCpuNumber);
   117 #endif
   118 #endif
   118 	~DProfilerGppSampler();
   119 	~DProfilerGppSampler();
   119 
   120 
   120 	struct TProfilerGppSamplerData* GetExportData();
   121 	struct TProfilerGppSamplerData* GetExportData();
   121 	void	Sample();
   122 	void	Sample(TAny* aPtr);
   122 	TInt	Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset);
   123 	TInt	Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset);
   123 	TInt 	GetPeriod();
   124 	TInt 	GetPeriod();
   124 	
   125 	
   125 private:
   126 private:
   126 	DGppSamplerImpl gppSamplerImpl;
   127 	DGppSamplerImpl iGppSamplerImpl;
   127 	struct TProfilerGppSamplerData exportData;
   128 	struct TProfilerGppSamplerData iExportData;
   128 #ifdef __SMP__
   129 #ifdef __SMP__
   129 	TInt   iCpuNumber;
   130 	TInt   iCpuNumber;
   130 #endif
   131 #endif
   131 };
   132 };
   132 
   133 
   138 #ifndef __SMP__
   139 #ifndef __SMP__
   139 template <int BufferSize>
   140 template <int BufferSize>
   140 DProfilerGppSampler<BufferSize>::DProfilerGppSampler() :
   141 DProfilerGppSampler<BufferSize>::DProfilerGppSampler() :
   141 	DProfilerGenericSampler<BufferSize>(PROFILER_GPP_SAMPLER_ID) 
   142 	DProfilerGenericSampler<BufferSize>(PROFILER_GPP_SAMPLER_ID) 
   142     {
   143     {
   143 	LOGSTRING2("CProfilerGppSampler<%d>::CProfilerGppSampler",BufferSize);
   144 	LOGSTRING2("DProfilerGppSampler<%d>::CProfilerGppSampler",BufferSize);
   144     }
   145     }
   145 #else
   146 #else
   146 template <int BufferSize>
   147 template <int BufferSize>
   147 DProfilerGppSampler<BufferSize>::DProfilerGppSampler(TInt aCpuNumber) :
   148 DProfilerGppSampler<BufferSize>::DProfilerGppSampler(TInt aCpuNumber) :
   148     DProfilerGenericSampler<BufferSize>(PROFILER_GPP_SAMPLER_ID+(aCpuNumber*20)), iCpuNumber(aCpuNumber) 
   149     DProfilerGenericSampler<BufferSize>(PROFILER_GPP_SAMPLER_ID+(aCpuNumber*20)), iCpuNumber(aCpuNumber) 
   149     {
   150     {
   150     LOGSTRING2("CProfilerGppSampler<%d>::CProfilerGppSampler",BufferSize);
   151     LOGSTRING3("DProfilerGppSampler<%d>::DProfilerGppSampler, cpu %d",BufferSize, iCpuNumber);
   151     }
   152     }
   152 #endif
   153 #endif
   153 
   154 
   154 template <int BufferSize>
   155 template <int BufferSize>
   155 DProfilerGppSampler<BufferSize>::~DProfilerGppSampler()
   156 DProfilerGppSampler<BufferSize>::~DProfilerGppSampler()
   156     {
   157     {
   157 	LOGSTRING2("CProfilerGppSampler<%d>::~CProfilerGppSampler",BufferSize);		
   158 	LOGSTRING2("DProfilerGppSampler<%d>::~CProfilerGppSampler",BufferSize);		
   158     }
   159     }
   159 
   160 
   160 template <int BufferSize>
   161 template <int BufferSize>
   161 TInt DProfilerGppSampler<BufferSize>::Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset)
   162 TInt DProfilerGppSampler<BufferSize>::Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset)
   162         {
   163         {
   163 	LOGSTRING2("CProfilerGppSampler<%d>::Reset - calling superclass reset",BufferSize);
   164 	LOGSTRING2("DProfilerGppSampler<%d>::Reset - calling superclass reset",BufferSize);
   164 	DProfilerGenericSampler<BufferSize>::Reset(aStream, 0);
   165 	DProfilerGenericSampler<BufferSize>::Reset(aStream, 0);
   165 	LOGSTRING2("CProfilerGppSampler<%d>::Reset - called superclass reset",BufferSize);
   166 	LOGSTRING2("DProfilerGppSampler<%d>::Reset - called superclass reset",BufferSize);
   166 
   167 
   167 	this->gppSamplerImpl.Reset();
   168 	iGppSamplerImpl.Reset();
   168 	
   169 	
   169 #ifdef __SMP__
   170 #ifdef __SMP__
   170 	this->gppSamplerImpl.iCpuNumber = this->iCpuNumber;
   171 	iGppSamplerImpl.iCpuNumber = iCpuNumber;
   171 	
   172 	
   172 	// set common start time for all CPU samplers
   173 	// set common start time for all CPU samplers
   173 	this->gppSamplerImpl.iStartTime = aSyncOffset;
   174 	iGppSamplerImpl.iStartTime = aSyncOffset;
   174 #endif
   175 #endif
   175 	this->gppSamplerImpl.iGppSamplingPeriod = this->iSamplingPeriod;
   176 	iGppSamplerImpl.iGppSamplingPeriod = DProfilerGenericSampler<BufferSize>::iSamplingPeriod;
   176 	this->gppSamplerImpl.iSampleCount = 0;
   177 	iGppSamplerImpl.iSampleCount = 0;
   177 	this->exportData.sampleNumber = 0;
   178 	iExportData.sampleNumber = 0;
   178 	this->exportData.lastPcValue = 0;
   179 	iExportData.lastPcValue = 0;
   179     this->exportData.samplingPeriod = this->gppSamplerImpl.iGppSamplingPeriod;
   180     iExportData.samplingPeriod = iGppSamplerImpl.iGppSamplingPeriod;
   180 
   181 
   181 	TInt length = gppSamplerImpl.CreateFirstSample();
   182 	TInt length = iGppSamplerImpl.CreateFirstSample();
   182 	LOGSTRING3("CProfilerGPPSampler<%d>::Reset - got first sample, size %d",BufferSize,length);	
   183 
   183 	
   184 	LOGSTRING3("DProfilerGPPSampler<%d>::Reset - got first sample, size %d",BufferSize,length);
   184 	this->iSampleBuffer->AddSample(gppSamplerImpl.tempBuf,length);
   185 	
       
   186 	//DProfilerGenericSampler<BufferSize>::iSampleBuffer->AddSample(iGppSamplerImpl.tempBuf,length);
       
   187 	this->iSampleBuffer->AddSample(iGppSamplerImpl.tempBuf,length);
   185 
   188 
   186 	// check if sampling period > 1 ms
   189 	// check if sampling period > 1 ms
   187 	// NOTE: feature supported in Performance Investigator 2.01 and above
   190 	// NOTE: feature supported in Performance Investigator 2.01 and above
   188 	if(this->gppSamplerImpl.iGppSamplingPeriod > 1)
   191 	if(iGppSamplerImpl.iGppSamplingPeriod > 1)
   189 	    {
   192 	    {
   190         // For Address/Thread (GPP) version 2.01 or above, the first word is the sampling period in milliseconds
   193         // For Address/Thread (GPP) version 2.01 or above, the first word is the sampling period in milliseconds
   191         TUint8* w = gppSamplerImpl.tempBuf;
   194         TUint8* w(iGppSamplerImpl.tempBuf);
   192         
   195         
   193         (*w++) = (this->gppSamplerImpl.iGppSamplingPeriod >> 24) & 0xFF;
   196         (*w++) = (iGppSamplerImpl.iGppSamplingPeriod >> 24) & 0xFF;
   194         (*w++) = (this->gppSamplerImpl.iGppSamplingPeriod >> 16) & 0xFF;
   197         (*w++) = (iGppSamplerImpl.iGppSamplingPeriod >> 16) & 0xFF;
   195         (*w++) = (this->gppSamplerImpl.iGppSamplingPeriod >>  8) & 0xFF;
   198         (*w++) = (iGppSamplerImpl.iGppSamplingPeriod >>  8) & 0xFF;
   196         (*w++) = (this->gppSamplerImpl.iGppSamplingPeriod) & 0xFF;
   199         (*w++) = (iGppSamplerImpl.iGppSamplingPeriod) & 0xFF;
   197         
   200         
   198         this->iSampleBuffer->AddSample(gppSamplerImpl.tempBuf,4);
   201         //DProfilerGenericSampler<BufferSize>::iSampleBuffer->AddSample(iGppSamplerImpl.tempBuf,4);
       
   202         this->iSampleBuffer->AddSample(iGppSamplerImpl.tempBuf,4);
   199 	    }
   203 	    }
   200 	
   204 	
   201 	LOGSTRING2("CProfilerGPPSampler<%d>::Reset finished",BufferSize);
   205 	LOGSTRING2("DProfilerGPPSampler<%d>::Reset finished",BufferSize);
   202 	return KErrNone;
   206 	return KErrNone;
   203     }
   207     }
   204 
   208 
   205 template <int BufferSize>
   209 template <int BufferSize>
   206 void DProfilerGppSampler<BufferSize>::Sample()
   210 void DProfilerGppSampler<BufferSize>::Sample(TAny* aPtr)
   207     {
   211     {
   208 	LOGSTRING2("CProfilerGppSampler<%d>::Sample",BufferSize);
   212     LOGSTRING2("DProfilerGppSampler<%d>::Sample",BufferSize);
   209 //	if(this->gppSamplerImpl.iSampleCount % 1000 == 0) 
   213 
   210 //	    {
   214 	TInt length(iGppSamplerImpl.SampleImpl());
   211 //#ifdef __SMP__
   215 
   212 //	    if(this->iCpuNumber == 0)  // print sample tick only from CPU 0 context
   216     iGppSamplerImpl.iSampleCount++;
   213 //	        {
   217 	iExportData.sampleNumber += iGppSamplerImpl.iGppSamplingPeriod;
   214 //#endif
   218 	iExportData.lastPcValue = iGppSamplerImpl.iLastPc;
   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 
   219 
   227 	if(length > 0)
   220 	if(length > 0)
   228         {
   221         {
   229         this->iSampleBuffer->AddSample(gppSamplerImpl.tempBuf,length);
   222 	    TInt ret(this->iSampleBuffer->AddSample(iGppSamplerImpl.tempBuf,length));
       
   223         if (ret != 0)
       
   224             {
       
   225             Kern::Printf(("DProfilerGppSampler<%d>::Sample() - add to sample buffer failed, loosing data, error = %d"),BufferSize,ret);
       
   226             }
   230         }
   227         }
   231 
   228 	LOGSTRING3("DProfilerGppSampler<%d>::Sample - length %d",BufferSize,length);
   232 	LOGSTRING3("CProfilerGppSampler<%d>::Sample - length %d",BufferSize,length);
       
   233 
       
   234 	return;
   229 	return;
   235     }
   230     }
   236 
   231 
   237 
   232 
   238 template <int BufferSize>
   233 template <int BufferSize>
   239 struct TProfilerGppSamplerData* DProfilerGppSampler<BufferSize>::GetExportData()
   234 struct TProfilerGppSamplerData* DProfilerGppSampler<BufferSize>::GetExportData()
   240     {
   235     {
   241 	LOGSTRING2("CProfilerGppSampler<%d>::GetExportData",BufferSize);
   236 	LOGSTRING2("DProfilerGppSampler<%d>::GetExportData",BufferSize);
   242 	return &(this->exportData);	
   237 	return &(iExportData);	
   243     }
   238     }
   244 
   239 
   245 template <int BufferSize>
   240 template <int BufferSize>
   246 TInt DProfilerGppSampler<BufferSize>::GetPeriod()
   241 TInt DProfilerGppSampler<BufferSize>::GetPeriod()
   247     {
   242     {
   248 	return this->gppSamplerImpl.iGppSamplingPeriod;
   243 	return iGppSamplerImpl.iGppSamplingPeriod;
   249     }
   244     }
   250 
   245 
   251 #endif
   246 #endif