20
|
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_PRI_SAMPLER_H
|
|
20 |
#define PROFILER_PRI_SAMPLER_H
|
|
21 |
|
|
22 |
#include "GeneralsConfig.h"
|
|
23 |
|
|
24 |
#include <kern_priv.h>
|
|
25 |
|
|
26 |
#include <piprofiler/ProfilerGenericClassesKrn.h>
|
|
27 |
#include <piprofiler/ProfilerTraces.h>
|
|
28 |
#include "GppSamplerImpl.h"
|
|
29 |
|
|
30 |
// defines the maximum thread amount that is assumed to
|
|
31 |
// be possible with PRI trace
|
|
32 |
const TInt KProfilerMaxThreadAmount = 512;
|
|
33 |
|
|
34 |
/*
|
|
35 |
*
|
|
36 |
* PRI sampler definition
|
|
37 |
*
|
|
38 |
*/
|
|
39 |
|
|
40 |
class DPriSamplerImpl //: public DBase
|
|
41 |
{
|
|
42 |
public:
|
|
43 |
enum EProcessingState
|
|
44 |
{
|
|
45 |
EStartingToProcess,
|
|
46 |
EProcessingNames,
|
|
47 |
EProcessingData,
|
|
48 |
ENothingToProcess
|
|
49 |
};
|
|
50 |
|
|
51 |
DPriSamplerImpl();
|
|
52 |
~DPriSamplerImpl();
|
|
53 |
|
|
54 |
TInt CreateFirstSample();
|
|
55 |
TInt SampleImpl();
|
|
56 |
TBool SampleNeeded();
|
|
57 |
void Reset();
|
|
58 |
TInt ProcessChunks();
|
|
59 |
|
|
60 |
TInt EncodeChunkData(DThread& thread);
|
|
61 |
TInt EncodeChunkName(DThread& thread);
|
|
62 |
|
|
63 |
TInt EncodeNameCode();
|
|
64 |
TInt EncodeDataCode();
|
|
65 |
|
|
66 |
TInt iCountti;
|
|
67 |
DThread* threadsToSample[KProfilerMaxThreadAmount];
|
|
68 |
DThread* threadNamesToReport[KProfilerMaxThreadAmount];
|
|
69 |
|
|
70 |
TInt iThreadCount;
|
|
71 |
TInt iNewThreadCount;
|
|
72 |
|
|
73 |
TInt iProcessing;
|
|
74 |
TInt iPriSamplingPeriod;
|
|
75 |
|
|
76 |
TUint8 sample[257];
|
|
77 |
TPtr8 sampleDescriptor;
|
|
78 |
#ifdef __SMP__
|
|
79 |
TInt iCpuNumber;
|
|
80 |
TUint32 iStartTime;
|
|
81 |
#endif
|
|
82 |
|
|
83 |
};
|
|
84 |
|
|
85 |
template <int BufferSize>
|
|
86 |
class DProfilerPriSampler : public DProfilerGenericSampler<BufferSize>
|
|
87 |
{
|
|
88 |
public:
|
|
89 |
DProfilerPriSampler(struct TProfilerGppSamplerData*, TInt id);
|
|
90 |
~DProfilerPriSampler();
|
|
91 |
|
62
|
92 |
void Sample(TAny* aPtr);
|
20
|
93 |
TInt Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset);
|
|
94 |
TInt PostSample();
|
|
95 |
TBool PostSampleNeeded();
|
|
96 |
|
|
97 |
private:
|
|
98 |
DPriSamplerImpl priSamplerImpl;
|
|
99 |
struct TProfilerGppSamplerData* gppSamplerData;
|
|
100 |
TBool sampleNeeded;
|
|
101 |
TBool sampleInProgress;
|
|
102 |
#ifdef __SMP__
|
|
103 |
TInt iCpuNumber;
|
|
104 |
#endif
|
|
105 |
};
|
|
106 |
|
|
107 |
/*
|
|
108 |
*
|
|
109 |
* PRI sampler implementation
|
|
110 |
*
|
|
111 |
*/
|
|
112 |
//#ifndef __SMP__
|
|
113 |
template <int BufferSize>
|
|
114 |
DProfilerPriSampler<BufferSize>::DProfilerPriSampler(struct TProfilerGppSamplerData* gppSamplerDataIn, TInt id) :
|
|
115 |
DProfilerGenericSampler<BufferSize>(PROFILER_PRI_SAMPLER_ID)
|
|
116 |
{
|
|
117 |
LOGSTRING2("CProfilerPriSampler<%d>::CProfilerPriSampler",BufferSize);
|
|
118 |
this->gppSamplerData = gppSamplerDataIn;
|
|
119 |
this->sampleInProgress = false;
|
|
120 |
this->iSamplingPeriod = 3000; // set default setting
|
|
121 |
}
|
|
122 |
//#else
|
|
123 |
//template <int BufferSize>
|
|
124 |
//DProfilerPriSampler<BufferSize>::DProfilerPriSampler(struct TProfilerGppSamplerData* gppSamplerDataIn, TInt id, TInt aCpuNumber) :
|
|
125 |
// DProfilerGenericSampler<BufferSize>(PROFILER_PRI_SAMPLER_ID+(aCpuNumber*20)), iCpuNumber(aCpuNumber)
|
|
126 |
// {
|
|
127 |
// LOGSTRING2("CProfilerGppSampler<%d>::CProfilerGppSampler",BufferSize);
|
|
128 |
// }
|
|
129 |
//#endif
|
|
130 |
|
|
131 |
template <int BufferSize>
|
|
132 |
TInt DProfilerPriSampler<BufferSize>::Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset)
|
|
133 |
{
|
|
134 |
LOGSTRING2("CProfilerPriSampler<%d>::Reset - calling superclass reset",BufferSize);
|
|
135 |
DProfilerGenericSampler<BufferSize>::Reset(aStream);
|
|
136 |
LOGSTRING2("CProfilerPriSampler<%d>::Reset - called superclass reset",BufferSize);
|
|
137 |
priSamplerImpl.Reset();
|
|
138 |
|
|
139 |
#ifdef __SMP__
|
|
140 |
// this->priSamplerImpl.iCpuNumber = this->iCpuNumber;
|
|
141 |
//
|
|
142 |
// // set common start time for all CPU samplers
|
|
143 |
// this->priSamplerImpl.iStartTime = aSyncOffset;
|
|
144 |
#endif
|
|
145 |
this->priSamplerImpl.iPriSamplingPeriod = this->iSamplingPeriod;
|
|
146 |
|
|
147 |
|
|
148 |
LOGSTRING3("CProfilerPriSampler<%d>::Reset - set pri sampling period to",
|
|
149 |
BufferSize,this->priSamplerImpl.iPriSamplingPeriod);
|
|
150 |
|
|
151 |
TInt length(priSamplerImpl.CreateFirstSample());
|
|
152 |
this->iSampleBuffer->AddSample(priSamplerImpl.sample,length);
|
|
153 |
|
|
154 |
this->sampleInProgress = false;
|
|
155 |
this->sampleNeeded = false;
|
|
156 |
|
|
157 |
return KErrNone;
|
|
158 |
}
|
|
159 |
|
|
160 |
template <int BufferSize>
|
|
161 |
TInt DProfilerPriSampler<BufferSize>::PostSample()
|
|
162 |
{
|
|
163 |
if(sampleNeeded)
|
|
164 |
{
|
|
165 |
this->sampleNeeded = false;
|
|
166 |
|
62
|
167 |
LOGSTRING3("CProfilerPriSampler<%d>::PostSample - state %d",BufferSize,this->iSampleBuffer->GetBufferStatus());
|
20
|
168 |
|
|
169 |
//TInt interruptLevel = NKern::DisableInterrupts(0);
|
|
170 |
|
|
171 |
TInt length(this->priSamplerImpl.SampleImpl());
|
|
172 |
if(length != 0)
|
|
173 |
{
|
|
174 |
LOGSTRING("PRI sampler PostSample - starting to sample");
|
|
175 |
|
|
176 |
// then, encode the sample to the buffer
|
|
177 |
while(length > 0)
|
|
178 |
{
|
|
179 |
this->iSampleBuffer->AddSample(priSamplerImpl.sample,length);
|
|
180 |
length = this->priSamplerImpl.SampleImpl();
|
|
181 |
// indicate that the whole PRI sample ends by having a 0x00 in the end
|
|
182 |
if(length == 0)
|
|
183 |
{
|
|
184 |
TUint8 number(0);
|
|
185 |
LOGSTRING("PRI sampler PostSample - all samples generated!");
|
|
186 |
|
|
187 |
this->iSampleBuffer->AddSample(&number,1);
|
|
188 |
LOGSTRING("PRI sampler PostSample - end mark added");
|
|
189 |
}
|
|
190 |
}
|
|
191 |
LOGSTRING("PRI sampler PostSample - finished sampling");
|
|
192 |
}
|
|
193 |
this->sampleInProgress = false;
|
|
194 |
|
|
195 |
//NKern::RestoreInterrupts(interruptLevel);
|
|
196 |
}
|
|
197 |
|
|
198 |
// finally perform superclass postsample
|
|
199 |
TInt i(this->DProfilerGenericSampler<BufferSize>::PostSample());
|
|
200 |
return i;
|
|
201 |
}
|
|
202 |
|
|
203 |
template <int BufferSize>
|
|
204 |
TBool DProfilerPriSampler<BufferSize>::PostSampleNeeded()
|
|
205 |
{
|
62
|
206 |
LOGSTRING3("CProfilerPriSampler<%d>::PostSampleNeeded - state %d",BufferSize,this->iSampleBuffer->GetBufferStatus());
|
|
207 |
|
|
208 |
TUint32 status = this->iSampleBuffer->GetBufferStatus();
|
20
|
209 |
|
62
|
210 |
if(status == DProfilerSampleBuffer::BufferCopyAsap ||
|
|
211 |
status == DProfilerSampleBuffer::BufferFull ||
|
|
212 |
this->sampleNeeded == true)
|
20
|
213 |
{
|
|
214 |
return true;
|
|
215 |
}
|
|
216 |
|
|
217 |
return false;
|
|
218 |
}
|
|
219 |
|
|
220 |
|
|
221 |
template <int BufferSize>
|
62
|
222 |
void DProfilerPriSampler<BufferSize>::Sample(TAny* aPtr)
|
20
|
223 |
{
|
|
224 |
LOGSTRING2("CProfilerPriSampler<%d>::Sample",BufferSize);
|
|
225 |
|
|
226 |
if(priSamplerImpl.SampleNeeded() && this->sampleInProgress == false)
|
|
227 |
{
|
|
228 |
this->sampleInProgress = true;
|
|
229 |
this->sampleNeeded = true;
|
|
230 |
// start the PRI sample with the sample time
|
|
231 |
TUint8 number(4);
|
|
232 |
this->iSampleBuffer->AddSample(&number,1);
|
|
233 |
this->iSampleBuffer->AddSample((TUint8*)&(gppSamplerData->sampleNumber),4);
|
|
234 |
|
|
235 |
// leave the rest of the processing for PostSample()
|
|
236 |
}
|
|
237 |
|
|
238 |
LOGSTRING2("CProfilerPriSampler<%d>::Sample",BufferSize);
|
|
239 |
return;
|
|
240 |
}
|
|
241 |
|
|
242 |
template <int BufferSize>
|
|
243 |
DProfilerPriSampler<BufferSize>::~DProfilerPriSampler()
|
|
244 |
{
|
|
245 |
LOGSTRING2("CProfilerPriSampler<%d>::~CProfilerPriSampler",BufferSize);
|
|
246 |
}
|
|
247 |
#endif
|