sysanadatacapture/piprofiler/piprofiler/plugins/GeneralsPlugin/inc/GppSamplerImpl.h
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 #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 GppSamplerImpl
       
    39 {
       
    40 public:
       
    41 
       
    42 	GppSamplerImpl();
       
    43 	~GppSamplerImpl();
       
    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 
       
    62     TInt    iGppSamplingPeriod;
       
    63 	TUint8	tempBuf[512];
       
    64 	TUint	iLastPc;
       
    65 	
       
    66 	TBool	iIsaSample;
       
    67 	TInt	knownIsaTasks[256];
       
    68 	TUint8	knownIsaTaskCount;
       
    69 	TInt*	isaOsTaskRunningAddr;
       
    70 	void	Reset();
       
    71     TUint32 iSampleCount;
       
    72 	   
       
    73 	PROFILER_DEFINE_ISA_TASK_NAME_ARRAY
       
    74 
       
    75 private:
       
    76 	enum TState {EStop,ERunning,EStopping};
       
    77 
       
    78 	const TUint* iInterruptStack;
       
    79 	
       
    80 	TUint		iLastThread;
       
    81 	TUint		iRepeat;
       
    82 	TUint32 	iStartTime;
       
    83 	
       
    84 	RPropertyRef iIsaStartAddr;
       
    85 	RPropertyRef iIsaEndAddr;
       
    86 	RPropertyRef iIsaPluginStatus;
       
    87 	RPropertyRef iIsaOsTaskRunning;
       
    88 	TInt 		iIsaStatus;
       
    89 	TInt 		iIsaStart;
       
    90 	TInt 		iIsaEnd;
       
    91 };
       
    92 
       
    93 struct TProfilerGppSamplerData
       
    94 {
       
    95 //public:
       
    96 	TUint32		lastPcValue;
       
    97 	TUint32		sampleNumber;
       
    98     TInt        samplingPeriod;
       
    99 };
       
   100 
       
   101 template <int BufferSize>
       
   102 class DProfilerGppSampler : public DProfilerGenericSampler<BufferSize>
       
   103 {
       
   104 public:
       
   105 	DProfilerGppSampler();
       
   106 	~DProfilerGppSampler();
       
   107 
       
   108 	struct TProfilerGppSamplerData* GetExportData();
       
   109 	void	Sample();
       
   110 	TInt	Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset);
       
   111 	TInt 	GetPeriod();
       
   112 	
       
   113 private:
       
   114 	GppSamplerImpl gppSamplerImpl;
       
   115 	struct TProfilerGppSamplerData exportData;
       
   116 
       
   117 };
       
   118 
       
   119 /*
       
   120  *	
       
   121  *	GPP sampler implementation
       
   122  *	
       
   123  */
       
   124 
       
   125 template <int BufferSize>
       
   126 DProfilerGppSampler<BufferSize>::DProfilerGppSampler() :
       
   127 	DProfilerGenericSampler<BufferSize>(PROFILER_GPP_SAMPLER_ID) 
       
   128     {
       
   129 	LOGSTRING2("CProfilerGppSampler<%d>::CProfilerGppSampler",BufferSize);
       
   130     }
       
   131 
       
   132 template <int BufferSize>
       
   133 DProfilerGppSampler<BufferSize>::~DProfilerGppSampler()
       
   134     {
       
   135 	LOGSTRING2("CProfilerGppSampler<%d>::~CProfilerGppSampler",BufferSize);		
       
   136     }
       
   137 
       
   138 template <int BufferSize>
       
   139 TInt DProfilerGppSampler<BufferSize>::Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset)
       
   140         {
       
   141 	LOGSTRING2("CProfilerGppSampler<%d>::Reset - calling superclass reset",BufferSize);
       
   142 	DProfilerGenericSampler<BufferSize>::Reset(aStream, 0);
       
   143 	LOGSTRING2("CProfilerGppSampler<%d>::Reset - called superclass reset",BufferSize);
       
   144 
       
   145 	this->gppSamplerImpl.Reset();
       
   146 	
       
   147 	this->gppSamplerImpl.iGppSamplingPeriod = this->iSamplingPeriod;
       
   148 	this->gppSamplerImpl.iSampleCount = 0;
       
   149 	this->exportData.sampleNumber = 0;
       
   150 	this->exportData.lastPcValue = 0;
       
   151     this->exportData.samplingPeriod = this->gppSamplerImpl.iGppSamplingPeriod;
       
   152 
       
   153 	TInt length = gppSamplerImpl.CreateFirstSample();
       
   154 	LOGSTRING3("CProfilerGPPSampler<%d>::Reset - got first sample, size %d",BufferSize,length);	
       
   155 	
       
   156 	this->iSampleBuffer->AddSample(gppSamplerImpl.tempBuf,length);
       
   157 
       
   158 	// check if sampling period > 1 ms
       
   159 	// NOTE: feature supported in Performance Investigator 2.01 and above
       
   160 	if(this->gppSamplerImpl.iGppSamplingPeriod > 1)
       
   161 	    {
       
   162         // For Address/Thread (GPP) version 2.01 or above, the first word is the sampling period in milliseconds
       
   163         TUint8* w = gppSamplerImpl.tempBuf;
       
   164         
       
   165         (*w++) = (this->gppSamplerImpl.iGppSamplingPeriod >> 24) & 0xFF;
       
   166         (*w++) = (this->gppSamplerImpl.iGppSamplingPeriod >> 16) & 0xFF;
       
   167         (*w++) = (this->gppSamplerImpl.iGppSamplingPeriod >>  8) & 0xFF;
       
   168         (*w++) = (this->gppSamplerImpl.iGppSamplingPeriod) & 0xFF;
       
   169         
       
   170         this->iSampleBuffer->AddSample(gppSamplerImpl.tempBuf,4);
       
   171 	    }
       
   172 	
       
   173 	LOGSTRING2("CProfilerGPPSampler<%d>::Reset finished",BufferSize);
       
   174 	return KErrNone;
       
   175     }
       
   176 
       
   177 template <int BufferSize>
       
   178 void DProfilerGppSampler<BufferSize>::Sample()
       
   179     {
       
   180 	LOGSTRING2("CProfilerGppSampler<%d>::Sample",BufferSize);
       
   181 	
       
   182 	if(this->gppSamplerImpl.iSampleCount % 1000 == 0) 
       
   183 	    {
       
   184 		Kern::Printf(("PIPROF SAMPLE TICK, #%d"),exportData.sampleNumber);
       
   185 	    }
       
   186 	
       
   187 	TInt length = gppSamplerImpl.SampleImpl();
       
   188 
       
   189     this->gppSamplerImpl.iSampleCount++;
       
   190 	this->exportData.sampleNumber += this->gppSamplerImpl.iGppSamplingPeriod;
       
   191 	this->exportData.lastPcValue = gppSamplerImpl.iLastPc;
       
   192 
       
   193 	if(length > 0)
       
   194         {
       
   195         this->iSampleBuffer->AddSample(gppSamplerImpl.tempBuf,length);
       
   196         }
       
   197 
       
   198 	LOGSTRING3("CProfilerGppSampler<%d>::Sample - length %d",BufferSize,length);
       
   199 
       
   200 	return;
       
   201     }
       
   202 
       
   203 
       
   204 template <int BufferSize>
       
   205 struct TProfilerGppSamplerData* DProfilerGppSampler<BufferSize>::GetExportData()
       
   206     {
       
   207 	LOGSTRING2("CProfilerGppSampler<%d>::GetExportData",BufferSize);
       
   208 	return &(this->exportData);	
       
   209     }
       
   210 
       
   211 template <int BufferSize>
       
   212 TInt DProfilerGppSampler<BufferSize>::GetPeriod()
       
   213     {
       
   214 	return this->gppSamplerImpl.iGppSamplingPeriod;
       
   215     }
       
   216 
       
   217 #endif