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 |
#ifndef PROFILER_ITT_SAMPLER_H
|
|
19 |
#define PROFILER_ITT_SAMPLER_H
|
|
20 |
|
|
21 |
#include "GeneralsConfig.h"
|
|
22 |
|
|
23 |
#include <kern_priv.h>
|
|
24 |
|
|
25 |
#include <piprofiler/ProfilerGenericClassesKrn.h>
|
|
26 |
#include <piprofiler/ProfilerTraces.h>
|
|
27 |
#include "GppSamplerImpl.h"
|
|
28 |
#include "IttEventHandler.h"
|
|
29 |
|
|
30 |
// CONSTANTS
|
|
31 |
const TInt KITTSampleBufferSize = 256;
|
|
32 |
|
|
33 |
// flags
|
|
34 |
#define ITT_EVENT_HANDLER // enable event based ITT sampling
|
|
35 |
|
|
36 |
/*
|
|
37 |
*
|
|
38 |
* ITT sampler definition
|
|
39 |
*
|
|
40 |
*/
|
|
41 |
class DIttEventHandler;
|
|
42 |
|
|
43 |
/*
|
|
44 |
* User side ITT sampler
|
|
45 |
*/
|
|
46 |
class IttSamplerImpl
|
|
47 |
{
|
|
48 |
public:
|
|
49 |
IttSamplerImpl();
|
|
50 |
~IttSamplerImpl();
|
|
51 |
|
|
52 |
TInt SampleImpl(TUint32 pc,TUint32 sampleNum);
|
|
53 |
TBool SampleNeeded(TUint32 sampleNum);
|
|
54 |
TInt CreateFirstSample();
|
|
55 |
void Reset();
|
|
56 |
TInt ProcessEvent();
|
|
57 |
|
62
|
58 |
TInt HandleLibs(TUint32 sampleNum);
|
|
59 |
TInt HandleSegs(TUint32 sampleNum);
|
|
60 |
|
20
|
61 |
TUint8* itt_sample;
|
|
62 |
TInt iIttSamplingPeriod;
|
|
63 |
TInt iIttSamplingPeriodDiv2;
|
|
64 |
TBool iTimeToSample;
|
|
65 |
#ifdef ITT_EVENT_HANDLER
|
|
66 |
TBool iEventReceived;
|
62
|
67 |
TBool iInitialLibsTaken;
|
|
68 |
TBool iInitialSegsTaken;
|
20
|
69 |
#endif
|
|
70 |
|
|
71 |
private:
|
62
|
72 |
enum {
|
|
73 |
KIttHandlingLibs=0,
|
|
74 |
KIttHandlingCodeSegs
|
|
75 |
};
|
20
|
76 |
#ifdef ITT_EVENT_HANDLER
|
|
77 |
TInt iCount;
|
|
78 |
#endif
|
62
|
79 |
TInt iCurrentLibCount;
|
|
80 |
TInt iLibsCount;
|
|
81 |
TInt iCodeSegsCount;
|
20
|
82 |
TInt currentProcCount;
|
|
83 |
|
|
84 |
TUint8 sample[KITTSampleBufferSize ];
|
|
85 |
TPtr8 sampleDescriptor;
|
|
86 |
|
|
87 |
TBuf8<64> iVersionData;
|
|
88 |
SDblQue* codeSegList;
|
62
|
89 |
TUint8 iInitState;
|
|
90 |
SDblQueLink* iLatestCodeseg;
|
20
|
91 |
};
|
|
92 |
|
|
93 |
/*
|
|
94 |
* ITT sampler kernel part
|
|
95 |
*
|
|
96 |
*/
|
|
97 |
template <int BufferSize>
|
|
98 |
class DProfilerIttSampler : public DProfilerGenericSampler<BufferSize>
|
|
99 |
{
|
|
100 |
public:
|
|
101 |
DProfilerIttSampler(struct TProfilerGppSamplerData* gppSamplerDataIn);
|
|
102 |
~DProfilerIttSampler();
|
|
103 |
|
62
|
104 |
void Sample(TAny* aPtr);
|
20
|
105 |
TInt Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset);
|
|
106 |
TInt PostSample();
|
|
107 |
TBool PostSampleNeeded();
|
|
108 |
|
|
109 |
private:
|
62
|
110 |
|
20
|
111 |
#ifdef ITT_EVENT_HANDLER
|
|
112 |
DIttEventHandler* iEventHandler;
|
|
113 |
#endif
|
|
114 |
IttSamplerImpl ittSamplerImpl;
|
|
115 |
struct TProfilerGppSamplerData* gppSamplerData;
|
|
116 |
TBool sampleInProgress;
|
|
117 |
TBool sampleNeeded;
|
62
|
118 |
TUint32 iSyncOffset;
|
20
|
119 |
};
|
|
120 |
|
|
121 |
/*
|
|
122 |
* ITT sampler implementation
|
|
123 |
*
|
|
124 |
*/
|
|
125 |
template <int BufferSize>
|
|
126 |
DProfilerIttSampler<BufferSize>::DProfilerIttSampler(struct TProfilerGppSamplerData* gppSamplerDataIn) :
|
|
127 |
DProfilerGenericSampler<BufferSize>(PROFILER_ITT_SAMPLER_ID)
|
62
|
128 |
{
|
20
|
129 |
this->gppSamplerData = (struct TProfilerGppSamplerData*)gppSamplerDataIn;
|
|
130 |
this->sampleInProgress = false;
|
62
|
131 |
iSyncOffset = 0;
|
|
132 |
LOGSTRING2("DProfilerIttSampler<%d>::DProfilerIttSampler",BufferSize);
|
|
133 |
}
|
20
|
134 |
|
|
135 |
/*
|
|
136 |
* DProfilerIttSampler::Reset()
|
|
137 |
*
|
|
138 |
* @param DProfilerSampleStream* sample stream
|
|
139 |
* @param TUint32 Offset
|
|
140 |
*/
|
|
141 |
template <int BufferSize>
|
|
142 |
TInt DProfilerIttSampler<BufferSize>::Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset)
|
62
|
143 |
{
|
|
144 |
iSyncOffset = aSyncOffset;
|
20
|
145 |
// check if reset called in stop (by driver)
|
62
|
146 |
if(iSyncOffset != KStateSamplingEnding)
|
20
|
147 |
{
|
62
|
148 |
DProfilerGenericSampler<BufferSize>::Reset(aStream);
|
20
|
149 |
#ifdef ITT_EVENT_HANDLER
|
|
150 |
// Itt event handler
|
|
151 |
if(iEventHandler)
|
|
152 |
{
|
|
153 |
// stop previous sampling if still running
|
|
154 |
Kern::Printf("Stopping DIttEventHandler");
|
|
155 |
iEventHandler->Stop();
|
|
156 |
}
|
|
157 |
|
|
158 |
iEventHandler = new DIttEventHandler(this->iSampleBuffer, this->gppSamplerData);
|
|
159 |
if(iEventHandler)
|
|
160 |
{
|
|
161 |
TInt err(iEventHandler->Create());
|
|
162 |
if(err != KErrNone)
|
|
163 |
{
|
|
164 |
Kern::Printf("Error in creation of DIttEventHandler, error %d", err);
|
|
165 |
return err;
|
|
166 |
}
|
|
167 |
}
|
|
168 |
else
|
|
169 |
{
|
|
170 |
Kern::Printf("Could not initiate DIttEventHandler");
|
|
171 |
return KErrGeneral;
|
|
172 |
}
|
|
173 |
|
|
174 |
// set first sample at the 10 ms, should be enough
|
62
|
175 |
this->ittSamplerImpl.iIttSamplingPeriod = 8;
|
20
|
176 |
#else
|
|
177 |
this->ittSamplerImpl.iIttSamplingPeriod = this->iSamplingPeriod;
|
|
178 |
#endif
|
|
179 |
this->ittSamplerImpl.iIttSamplingPeriodDiv2 = (TInt)(this->ittSamplerImpl.iIttSamplingPeriod / 2);
|
62
|
180 |
LOGSTRING3("DProfilerIttSampler<%d>::Reset - set ITT sampling period to %d",
|
20
|
181 |
BufferSize,this->ittSamplerImpl.iIttSamplingPeriod);
|
|
182 |
}
|
|
183 |
else
|
|
184 |
{
|
|
185 |
LOGSTRING2("DProfilerIttSampler<%d>::Reset - reset in stop", BufferSize);
|
|
186 |
#ifdef ITT_EVENT_HANDLER
|
|
187 |
// destroy memory event handler
|
|
188 |
if(iEventHandler)
|
|
189 |
{
|
|
190 |
// stop previous sampling if still running
|
|
191 |
iEventHandler->Stop();
|
|
192 |
}
|
|
193 |
#endif
|
|
194 |
return KErrNone; // return if reset called in stop
|
|
195 |
}
|
|
196 |
|
|
197 |
TInt length(ittSamplerImpl.CreateFirstSample());
|
|
198 |
this->iSampleBuffer->AddSample((TUint8*)&length,1);
|
|
199 |
this->iSampleBuffer->AddSample(ittSamplerImpl.itt_sample, length);
|
|
200 |
this->sampleInProgress = false;
|
|
201 |
this->sampleNeeded = false;
|
|
202 |
//LOGSTRING("DProfilerIttSampler::Reset - exit");
|
|
203 |
this->ittSamplerImpl.Reset();
|
|
204 |
return KErrNone;
|
|
205 |
|
62
|
206 |
}
|
20
|
207 |
|
|
208 |
/*
|
|
209 |
* DProfilerIttSampler::PostSample
|
|
210 |
*
|
|
211 |
* Function for finishing sample
|
|
212 |
*/
|
|
213 |
template <int BufferSize>
|
|
214 |
TInt DProfilerIttSampler<BufferSize>::PostSample()
|
62
|
215 |
{
|
20
|
216 |
#ifdef ITT_EVENT_HANDLER
|
62
|
217 |
if(!ittSamplerImpl.iInitialSegsTaken || !ittSamplerImpl.iInitialLibsTaken) // if we haven't read the initial state
|
|
218 |
{
|
20
|
219 |
#endif
|
|
220 |
if(sampleNeeded)
|
62
|
221 |
{
|
20
|
222 |
this->sampleNeeded = false;
|
62
|
223 |
LOGSTRING3("DProfilerIttSampler<%d>::PostSample - state %d",BufferSize,this->iSampleBuffer->GetBufferStatus());
|
20
|
224 |
|
|
225 |
TInt length = this->ittSamplerImpl.SampleImpl(this->gppSamplerData->lastPcValue,
|
|
226 |
this->gppSamplerData->sampleNumber);
|
|
227 |
if(length != 0)
|
62
|
228 |
{
|
20
|
229 |
LOGSTRING("ITT sampler PostSample - starting to sample");
|
|
230 |
while(length > 0)
|
62
|
231 |
{
|
20
|
232 |
this->iSampleBuffer->AddSample(ittSamplerImpl.itt_sample,length);
|
|
233 |
length = this->ittSamplerImpl.SampleImpl( this->gppSamplerData->lastPcValue,
|
|
234 |
this->gppSamplerData->sampleNumber );
|
|
235 |
if(length == 0)
|
62
|
236 |
{
|
|
237 |
LOGSTRING("ITT sampler PostSample - done for this round!");
|
|
238 |
}
|
20
|
239 |
}
|
62
|
240 |
LOGSTRING("ITT sampler PostSample - finished sampling");
|
20
|
241 |
}
|
62
|
242 |
this->sampleInProgress = false;
|
20
|
243 |
}
|
|
244 |
#ifdef ITT_EVENT_HANDLER
|
62
|
245 |
}
|
|
246 |
#endif
|
20
|
247 |
|
|
248 |
LOGSTRING2("ITT sampler PostSample - finished sampling, time: %d", gppSamplerData->sampleNumber);
|
|
249 |
|
|
250 |
// finally perform superclass postsample
|
|
251 |
TInt i(this->DProfilerGenericSampler<BufferSize>::PostSample());
|
62
|
252 |
#ifdef ITT_EVENT_HANDLER
|
|
253 |
// notify event handler
|
|
254 |
if(iEventHandler)
|
|
255 |
{
|
|
256 |
iEventHandler->SampleHandled();
|
|
257 |
}
|
|
258 |
#endif
|
20
|
259 |
return i;
|
62
|
260 |
}
|
20
|
261 |
|
|
262 |
/*
|
|
263 |
* DProfilerIttSampler::PostSampleNeeded()
|
|
264 |
*
|
|
265 |
* Function for deciding if sample handling is needed
|
|
266 |
*/
|
|
267 |
template <int BufferSize>
|
|
268 |
TBool DProfilerIttSampler<BufferSize>::PostSampleNeeded()
|
62
|
269 |
{
|
|
270 |
LOGSTRING3("DProfilerIttSampler<%d>::PostSampleNeeded - buffer status %d",BufferSize,this->iSampleBuffer->GetBufferStatus());
|
20
|
271 |
|
62
|
272 |
TUint32 status(this->iSampleBuffer->GetBufferStatus());
|
|
273 |
#ifdef ITT_EVENT_HANDLER
|
|
274 |
if(iEventHandler)
|
|
275 |
{
|
|
276 |
if(iEventHandler->Tracking())
|
|
277 |
{
|
|
278 |
this->sampleNeeded = iEventHandler->SampleNeeded();
|
|
279 |
}
|
|
280 |
}
|
|
281 |
#endif
|
|
282 |
if(status == DProfilerSampleBuffer::BufferCopyAsap ||
|
|
283 |
status == DProfilerSampleBuffer::BufferFull ||
|
|
284 |
this->sampleNeeded == true)
|
|
285 |
{
|
|
286 |
LOGSTRING2("DProfilerIttSampler<%d>::PostSampleNeeded - buffer needs emptying or sample is needed",BufferSize);
|
20
|
287 |
return true;
|
62
|
288 |
}
|
20
|
289 |
return false;
|
62
|
290 |
}
|
20
|
291 |
|
|
292 |
/*
|
|
293 |
* DProfilerIttSampler::Sample
|
|
294 |
*
|
|
295 |
* Function for initiating sampling
|
|
296 |
*/
|
|
297 |
template <int BufferSize>
|
62
|
298 |
void DProfilerIttSampler<BufferSize>::Sample(TAny* aPtr)
|
|
299 |
{
|
|
300 |
LOGSTRING2("DProfilerIttSampler<%d>::Sample - entry",BufferSize);
|
|
301 |
if(iEventHandler)
|
|
302 |
{
|
|
303 |
if(!iEventHandler->Tracking())
|
|
304 |
{
|
|
305 |
if(ittSamplerImpl.SampleNeeded(this->gppSamplerData->sampleNumber) && this->sampleInProgress == false)
|
|
306 |
{
|
|
307 |
this->sampleInProgress = true;
|
|
308 |
this->sampleNeeded = true;
|
|
309 |
|
|
310 |
LOGSTRING2("DProfilerIttSampler<%d>::Sample - sample needed 1",BufferSize);
|
|
311 |
}
|
|
312 |
|
|
313 |
if(ittSamplerImpl.iInitialSegsTaken && ittSamplerImpl.iInitialLibsTaken)
|
|
314 |
{
|
|
315 |
iEventHandler->Start();
|
|
316 |
}
|
|
317 |
}
|
|
318 |
}
|
|
319 |
else
|
|
320 |
{
|
|
321 |
if(ittSamplerImpl.SampleNeeded(this->gppSamplerData->sampleNumber) && this->sampleInProgress == false)
|
|
322 |
{
|
|
323 |
this->sampleInProgress = true;
|
|
324 |
this->sampleNeeded = true;
|
|
325 |
|
|
326 |
LOGSTRING2("DProfilerIttSampler<%d>::Sample - sample needed 2",BufferSize);
|
|
327 |
}
|
|
328 |
}
|
20
|
329 |
|
62
|
330 |
LOGSTRING2("DProfilerIttSampler<%d>::Sample - exit",BufferSize);
|
20
|
331 |
return;
|
62
|
332 |
}
|
20
|
333 |
|
|
334 |
/*
|
|
335 |
* Destructor
|
|
336 |
*/
|
|
337 |
template <int BufferSize>
|
|
338 |
DProfilerIttSampler<BufferSize>::~DProfilerIttSampler()
|
62
|
339 |
{
|
|
340 |
LOGSTRING2("DProfilerIttSampler<%d>::~DProfilerIttSampler",BufferSize);
|
20
|
341 |
#ifdef ITT_EVENT_HANDLER
|
|
342 |
if(iEventHandler)
|
|
343 |
{
|
|
344 |
// stop previous sampling if still running
|
|
345 |
iEventHandler->Stop();
|
|
346 |
iEventHandler->Close();
|
|
347 |
iEventHandler = NULL;
|
|
348 |
}
|
|
349 |
#endif
|
62
|
350 |
}
|
20
|
351 |
#endif
|
|
352 |
// end of file
|