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 PROFILERGENERICCLASSESKRN_H
|
|
20 |
#define PROFILERGENERICCLASSESKRN_H
|
|
21 |
|
62
|
22 |
#include <piprofiler/ProfilerGenericClassesCommon.h>
|
|
23 |
#include <piprofiler/ProfilerTraces.h>
|
20
|
24 |
|
62
|
25 |
#include <e32cmn.h>
|
20
|
26 |
|
62
|
27 |
#define PROFILER_KERNEL_MODE
|
20
|
28 |
|
|
29 |
#ifdef PROFILER_KERNEL_MODE
|
62
|
30 |
|
|
31 |
#ifdef __SMP__
|
|
32 |
static TSpinLock BufferStateSpinLock = TSpinLock(TSpinLock::EOrderGenericIrqLow3);
|
|
33 |
static TSpinLock WriteSpinLock = TSpinLock(TSpinLock::EOrderGenericIrqLow3);
|
|
34 |
#endif
|
|
35 |
|
20
|
36 |
class DProfilerSampleBuffer;
|
|
37 |
|
|
38 |
class DProfilerSampleStream
|
|
39 |
{
|
|
40 |
public:
|
62
|
41 |
DProfilerSampleStream();
|
|
42 |
~DProfilerSampleStream();
|
20
|
43 |
|
62
|
44 |
void InsertCurrentClient(DThread* aClient);
|
|
45 |
void AddSampleBuffer(TBapBuf* aBuffer,TRequestStatus* aStatus);
|
|
46 |
void ReleaseIfPending();
|
20
|
47 |
|
62
|
48 |
void AddSamples(DProfilerSampleBuffer& aBuffer, TInt aSamplerId);
|
|
49 |
TInt EndSampling(DProfilerSampleBuffer& aBuffer,TInt aSamplerId);
|
20
|
50 |
|
62
|
51 |
void PerformCopy(TUint8 aSamplerId,TUint8* aSrc,TPtr8* dst,TInt aOffset,TInt aAmount);
|
20
|
52 |
|
|
53 |
private:
|
62
|
54 |
TBapBuf* iCurrentBuffer;
|
|
55 |
TRequestStatus* iPendingRequest;
|
|
56 |
DThread* iClient;
|
|
57 |
TInt iAddingSamples;
|
20
|
58 |
};
|
|
59 |
|
|
60 |
class DProfilerSampleBuffer : public DBase
|
|
61 |
{
|
62
|
62 |
friend class DProfilerSampleStream;
|
20
|
63 |
public:
|
|
64 |
|
62
|
65 |
enum ProfilerBufferStatus
|
|
66 |
{
|
|
67 |
BufferOk,
|
|
68 |
BufferCopyAsap,
|
|
69 |
BufferBeingCopied,
|
|
70 |
BufferFull,
|
|
71 |
BufferDataEnd
|
|
72 |
};
|
20
|
73 |
|
62
|
74 |
DProfilerSampleBuffer(TUint8* aBuffer, TUint8* aDblBuffer, TUint32 aSize);
|
|
75 |
~DProfilerSampleBuffer();
|
|
76 |
TInt AddSample(TUint8* aSample, TUint32 aLength);
|
|
77 |
TUint32 GetBufferStatus();
|
|
78 |
void ClearBuffer();
|
|
79 |
void EndSampling();
|
|
80 |
void DataCopied();
|
20
|
81 |
|
|
82 |
private:
|
62
|
83 |
TUint32 iBufferStatus;
|
|
84 |
TUint32 iBytesWritten;
|
|
85 |
TUint32 iDblBytesWritten;
|
|
86 |
TUint32 iDblBytesRead;
|
20
|
87 |
|
62
|
88 |
TUint32 iBufferDataSize;
|
|
89 |
TUint32 iBufferRealSize;
|
20
|
90 |
|
62
|
91 |
TProfilerSampleBufStruct* iDblBufStruct;
|
|
92 |
TProfilerSampleBufStruct* iBufStruct;
|
20
|
93 |
};
|
|
94 |
|
|
95 |
#endif
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
/*
|
62
|
100 |
*
|
|
101 |
* Abstract class CProfilerSamplerBase definition
|
|
102 |
*
|
20
|
103 |
*/
|
|
104 |
|
|
105 |
#ifdef PROFILER_KERNEL_MODE
|
|
106 |
class DProfilerSamplerBase : public DBase
|
|
107 |
{
|
|
108 |
public:
|
62
|
109 |
DProfilerSamplerBase();
|
|
110 |
virtual ~DProfilerSamplerBase();
|
20
|
111 |
|
62
|
112 |
virtual TInt Initialise() = 0;
|
|
113 |
virtual void Sample(TAny* aPtr) = 0;
|
|
114 |
virtual TBool PostSampleNeeded() = 0;
|
|
115 |
virtual TInt PostSample() = 0;
|
|
116 |
virtual TInt EndSampling() = 0;
|
20
|
117 |
|
62
|
118 |
virtual TInt Reset(DProfilerSampleStream* aStream = 0, TUint32 aSyncOffset = 0) = 0;
|
20
|
119 |
|
62
|
120 |
virtual void SetEnabledFlag(TBool aFlag) = 0;
|
|
121 |
virtual TBool GetEnabledFlag() = 0;
|
|
122 |
virtual void SetOutputCombination(TInt aSettings) = 0;
|
|
123 |
virtual void SetSamplingPeriod(TInt aSettings) = 0;
|
|
124 |
virtual void SetAdditionalSettings(TInt aSettings) = 0;
|
|
125 |
virtual void SetAdditionalSettings2(TInt aSettings) = 0;
|
|
126 |
virtual void SetAdditionalSettings3(TInt aSettings) = 0;
|
|
127 |
virtual void SetAdditionalSettings4(TInt aSettings) = 0;
|
20
|
128 |
|
62
|
129 |
TInt iSamplerId;
|
|
130 |
TInt iOutputCombination;
|
|
131 |
TBool iEnabled;
|
20
|
132 |
};
|
|
133 |
|
|
134 |
/*
|
62
|
135 |
*
|
|
136 |
* Template abstract class CProfilerGenericSampler definition
|
|
137 |
*
|
20
|
138 |
*/
|
|
139 |
|
|
140 |
// size parameter given defines the explicit buffer size in bytes for this sampler
|
|
141 |
template <int BufferSize>
|
|
142 |
class DProfilerGenericSampler : public DProfilerSamplerBase
|
|
143 |
{
|
|
144 |
public:
|
62
|
145 |
DProfilerGenericSampler(TInt aSamplerId);
|
|
146 |
virtual ~DProfilerGenericSampler();
|
20
|
147 |
|
62
|
148 |
TInt Initialise();
|
|
149 |
virtual void Sample(TAny* aPtr) = 0;
|
|
150 |
TBool PostSampleNeeded();
|
|
151 |
TInt PostSample();
|
|
152 |
TInt EndSampling();
|
|
153 |
virtual TInt Reset(DProfilerSampleStream* aStream = 0, TUint32 aSyncOffset = 0);
|
20
|
154 |
|
|
155 |
|
62
|
156 |
void SetEnabledFlag(TBool aFlag);
|
|
157 |
TBool GetEnabledFlag();
|
|
158 |
void SetOutputCombination(TInt aComb);
|
|
159 |
void SetSamplingPeriod(TInt aSettings);
|
|
160 |
void SetAdditionalSettings(TInt aSettings);
|
|
161 |
void SetAdditionalSettings2(TInt aSettings);
|
|
162 |
void SetAdditionalSettings3(TInt aSettings);
|
|
163 |
void SetAdditionalSettings4(TInt aSettings);
|
20
|
164 |
|
62
|
165 |
DProfilerSampleBuffer* iSampleBuffer;
|
|
166 |
DProfilerSampleStream* iStream;
|
20
|
167 |
|
62
|
168 |
// for right alignment
|
|
169 |
TUint8 iBuffer[BufferSize+4];
|
|
170 |
TUint8 iDblBuffer[BufferSize+4];
|
|
171 |
|
|
172 |
TInt iSamplingPeriod;
|
|
173 |
TInt iAdditionalSettings;
|
|
174 |
TInt iAdditionalSettings2;
|
|
175 |
TInt iAdditionalSettings3;
|
|
176 |
TInt iAdditionalSettings4;
|
20
|
177 |
};
|
|
178 |
|
|
179 |
/*
|
62
|
180 |
*
|
|
181 |
* Template abstract class CProfilerGenericSampler implementation
|
20
|
182 |
*
|
|
183 |
*/
|
|
184 |
|
|
185 |
template <int BufferSize>
|
|
186 |
DProfilerGenericSampler<BufferSize>::DProfilerGenericSampler(TInt aSamplerId)
|
|
187 |
{
|
62
|
188 |
iSamplerId = aSamplerId;
|
|
189 |
iEnabled = false;
|
|
190 |
iSampleBuffer = 0;
|
|
191 |
iAdditionalSettings = 0;
|
|
192 |
iAdditionalSettings2 = 0;
|
20
|
193 |
iAdditionalSettings3 = 0;
|
|
194 |
iAdditionalSettings4 = 0;
|
62
|
195 |
iStream = 0;
|
|
196 |
Initialise();
|
20
|
197 |
}
|
|
198 |
|
|
199 |
template <int BufferSize>
|
|
200 |
DProfilerGenericSampler<BufferSize>::~DProfilerGenericSampler()
|
|
201 |
{
|
62
|
202 |
LOGSTRING2("DProfilerGenericSampler<%d>::CProfilerGenericSampler",BufferSize);
|
|
203 |
|
|
204 |
if(iSampleBuffer != 0)
|
|
205 |
{
|
|
206 |
delete iSampleBuffer;
|
|
207 |
}
|
20
|
208 |
}
|
|
209 |
|
|
210 |
template <int BufferSize>
|
|
211 |
TInt DProfilerGenericSampler<BufferSize>::Initialise()
|
|
212 |
{
|
62
|
213 |
LOGSTRING2("DProfilerGenericSampler<%d>::Initialise - chunk option",BufferSize);
|
20
|
214 |
|
62
|
215 |
// stream is not used in chunk mode
|
|
216 |
iStream = 0;
|
20
|
217 |
|
62
|
218 |
// create the sample buffer object with the buffers
|
|
219 |
if(iSampleBuffer == 0)
|
|
220 |
{
|
|
221 |
iSampleBuffer = new DProfilerSampleBuffer(iBuffer,iDblBuffer,BufferSize);
|
20
|
222 |
}
|
62
|
223 |
else
|
|
224 |
{
|
|
225 |
LOGSTRING2("DProfilerGenericSampler<%d>::Initialise - ERROR 1",BufferSize);
|
20
|
226 |
}
|
|
227 |
|
62
|
228 |
return KErrNone;
|
20
|
229 |
}
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
template <int BufferSize>
|
|
234 |
TInt DProfilerGenericSampler<BufferSize>::Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset)
|
|
235 |
{
|
62
|
236 |
LOGSTRING4("DProfilerGenericSampler<%d>::Reset %d, sync offset %d",BufferSize,aStream,aSyncOffset);
|
|
237 |
// reset the sample buffer and resolve the chunk again
|
20
|
238 |
|
62
|
239 |
// CURRENT VERSION SUPPORTS ONLY STREAM MODE!
|
|
240 |
LOGSTRING2("DProfilerGenericSampler<%d>::Reset - stream option",BufferSize);
|
20
|
241 |
|
62
|
242 |
// initialise the sampler with the stream option
|
|
243 |
iStream = aStream;
|
20
|
244 |
|
62
|
245 |
// clear the sample buffer
|
|
246 |
if(iSampleBuffer != 0)
|
|
247 |
{
|
|
248 |
iSampleBuffer->ClearBuffer();
|
20
|
249 |
}
|
62
|
250 |
else
|
|
251 |
{
|
|
252 |
LOGSTRING2("DProfilerGenericSampler<%d>::Initialise - ERROR no buffer",BufferSize);
|
20
|
253 |
}
|
|
254 |
|
62
|
255 |
return KErrNone;
|
20
|
256 |
|
|
257 |
}
|
|
258 |
|
|
259 |
template <int BufferSize>
|
|
260 |
TBool DProfilerGenericSampler<BufferSize>::PostSampleNeeded()
|
|
261 |
{
|
62
|
262 |
LOGSTRING4("DProfilerGenericSampler<%d>::PostSampleNeeded - ID %d, state %d",BufferSize ,iSamplerId ,iSampleBuffer->GetBufferStatus());
|
20
|
263 |
|
62
|
264 |
TUint32 status(iSampleBuffer->GetBufferStatus());
|
20
|
265 |
|
62
|
266 |
if(status == DProfilerSampleBuffer::BufferCopyAsap || status == DProfilerSampleBuffer::BufferFull)
|
|
267 |
{
|
|
268 |
return true;
|
20
|
269 |
}
|
62
|
270 |
|
|
271 |
return false;
|
20
|
272 |
}
|
|
273 |
|
|
274 |
|
|
275 |
template <int BufferSize>
|
|
276 |
TInt DProfilerGenericSampler<BufferSize>::PostSample()
|
|
277 |
{
|
62
|
278 |
LOGSTRING4("DProfilerGenericSampler<%d>::PostSample - ID %d, state %d",BufferSize,iSamplerId,iSampleBuffer->GetBufferStatus());
|
20
|
279 |
|
62
|
280 |
TUint32 status(iSampleBuffer->GetBufferStatus());
|
20
|
281 |
|
62
|
282 |
if(status == DProfilerSampleBuffer::BufferCopyAsap || status == DProfilerSampleBuffer::BufferFull)
|
|
283 |
{
|
20
|
284 |
// write data to the stream
|
62
|
285 |
iStream->AddSamples(*iSampleBuffer,iSamplerId);
|
|
286 |
}
|
|
287 |
|
|
288 |
return KErrNone;
|
20
|
289 |
}
|
|
290 |
|
|
291 |
template <int BufferSize>
|
|
292 |
TInt DProfilerGenericSampler<BufferSize>::EndSampling()
|
|
293 |
{
|
62
|
294 |
LOGSTRING3("DProfilerGenericSampler<%d>::EndSampling, ID %d",BufferSize,iSamplerId);
|
20
|
295 |
|
|
296 |
// only if write to stream option is selected
|
|
297 |
if(iStream->EndSampling(*iSampleBuffer,iSamplerId) == 0)
|
|
298 |
{
|
62
|
299 |
LOGSTRING3("DProfilerGenericSampler<%d>::EndSampling, ID %d - ok",BufferSize,iSamplerId);
|
20
|
300 |
return KErrNone;
|
|
301 |
}
|
|
302 |
else
|
|
303 |
{
|
62
|
304 |
LOGSTRING3("DProfilerGenericSampler<%d>::EndSampling, ID %d - still data to copy",BufferSize,iSamplerId);
|
20
|
305 |
// there is still data to copy
|
|
306 |
return KErrNotReady;
|
|
307 |
}
|
|
308 |
}
|
|
309 |
|
|
310 |
template <int BufferSize>
|
|
311 |
void DProfilerGenericSampler<BufferSize>::SetEnabledFlag(TBool aFlag)
|
|
312 |
{
|
62
|
313 |
LOGSTRING2("CProfilerGenericSampler<%d>::SetEnabledFlag",BufferSize);
|
|
314 |
iEnabled = aFlag;
|
20
|
315 |
}
|
|
316 |
|
|
317 |
template <int BufferSize>
|
|
318 |
TBool DProfilerGenericSampler<BufferSize>::GetEnabledFlag()
|
|
319 |
{
|
62
|
320 |
LOGSTRING2("CProfilerGenericSampler<%d>::GetEnabledFlag",BufferSize);
|
|
321 |
return iEnabled;
|
20
|
322 |
}
|
|
323 |
|
|
324 |
template <int BufferSize>
|
|
325 |
void DProfilerGenericSampler<BufferSize>::SetOutputCombination(TInt aComb)
|
|
326 |
{
|
62
|
327 |
LOGSTRING2("CProfilerGenericSampler<%d>::SetOutputCombination",BufferSize);
|
|
328 |
iOutputCombination = aComb;
|
20
|
329 |
}
|
|
330 |
|
|
331 |
template <int BufferSize>
|
|
332 |
void DProfilerGenericSampler<BufferSize>::SetAdditionalSettings(TInt aSettings)
|
|
333 |
{
|
62
|
334 |
LOGSTRING3("CProfilerGenericSampler<%d>::SetAdditionalSettings to 0x%x",BufferSize,aSettings);
|
|
335 |
iAdditionalSettings = aSettings;
|
20
|
336 |
}
|
|
337 |
|
|
338 |
template <int BufferSize>
|
|
339 |
void DProfilerGenericSampler<BufferSize>::SetAdditionalSettings2(TInt aSettings)
|
|
340 |
{
|
62
|
341 |
LOGSTRING3("CProfilerGenericSampler<%d>::SetAdditionalSettings2 to 0x%x",BufferSize,aSettings);
|
|
342 |
iAdditionalSettings2 = aSettings;
|
20
|
343 |
}
|
|
344 |
|
|
345 |
template <int BufferSize>
|
|
346 |
void DProfilerGenericSampler<BufferSize>::SetAdditionalSettings3(TInt aSettings)
|
|
347 |
{
|
62
|
348 |
LOGSTRING3("CProfilerGenericSampler<%d>::SetAdditionalSettings3 to 0x%x",BufferSize,aSettings);
|
|
349 |
iAdditionalSettings3 = aSettings;
|
20
|
350 |
}
|
|
351 |
|
|
352 |
template <int BufferSize>
|
|
353 |
void DProfilerGenericSampler<BufferSize>::SetAdditionalSettings4(TInt aSettings)
|
|
354 |
{
|
62
|
355 |
LOGSTRING3("CProfilerGenericSampler<%d>::SetAdditionalSettings4 to 0x%x",BufferSize,aSettings);
|
|
356 |
iAdditionalSettings4 = aSettings;
|
20
|
357 |
}
|
|
358 |
|
|
359 |
template <int BufferSize>
|
|
360 |
void DProfilerGenericSampler<BufferSize>::SetSamplingPeriod(TInt aSettings)
|
|
361 |
{
|
62
|
362 |
LOGSTRING3("CProfilerGenericSampler<%d>::SetSamplingPeriod to 0x%x",BufferSize,aSettings);
|
|
363 |
iSamplingPeriod = aSettings;
|
20
|
364 |
}
|
|
365 |
|
|
366 |
/*
|
62
|
367 |
*
|
|
368 |
* Just a test class that is derived from CProfilerGenericSampler
|
|
369 |
*
|
20
|
370 |
*/
|
|
371 |
|
|
372 |
template <int BufferSize>
|
|
373 |
class DProfilerExampleSampler : public DProfilerGenericSampler<BufferSize>
|
|
374 |
{
|
|
375 |
public:
|
62
|
376 |
TUint32 iSampleNumber;
|
20
|
377 |
|
62
|
378 |
DProfilerExampleSampler(TInt aSamplerId);
|
|
379 |
~DProfilerExampleSampler();
|
20
|
380 |
|
62
|
381 |
void Sample();
|
|
382 |
void Sample(TInt aCount, TInt aLastPc);
|
20
|
383 |
};
|
|
384 |
|
|
385 |
|
|
386 |
/*
|
62
|
387 |
*
|
|
388 |
* Just a test class that is derived from CProfilerGenericSampler
|
|
389 |
*
|
20
|
390 |
*/
|
|
391 |
|
|
392 |
template <int BufferSize>
|
|
393 |
DProfilerExampleSampler<BufferSize>::DProfilerExampleSampler(TInt aSamplerId) :
|
62
|
394 |
DProfilerGenericSampler<BufferSize>(aSamplerId)
|
20
|
395 |
{
|
|
396 |
iSampleNumber = 0;
|
62
|
397 |
LOGSTRING2("CProfilerExampleSampler<%d>::CProfilerExampleSampler",BufferSize);
|
20
|
398 |
}
|
|
399 |
|
|
400 |
template <int BufferSize>
|
|
401 |
void DProfilerExampleSampler<BufferSize>::Sample()
|
|
402 |
{
|
62
|
403 |
LOGSTRING2("CProfilerExampleSampler<%d>::Sample",BufferSize);
|
|
404 |
TBuf8<20>* testiBuf = new TBuf8<20>;
|
20
|
405 |
|
62
|
406 |
testiBuf->AppendNum((TInt)iSampleNumber);
|
|
407 |
iSampleNumber++;
|
20
|
408 |
|
62
|
409 |
this->iSampleBuffer->AddSample((TUint8*)testiBuf->Ptr(),testiBuf->Length());
|
|
410 |
delete testiBuf;
|
|
411 |
return;
|
20
|
412 |
}
|
|
413 |
|
|
414 |
template <int BufferSize>
|
|
415 |
void DProfilerExampleSampler<BufferSize>::Sample(TInt aCount, TInt aLastPc)
|
|
416 |
{
|
62
|
417 |
return;
|
20
|
418 |
}
|
|
419 |
|
|
420 |
template <int BufferSize>
|
|
421 |
DProfilerExampleSampler<BufferSize>::~DProfilerExampleSampler()
|
|
422 |
{
|
62
|
423 |
LOGSTRING2("CProfilerExampleSampler<%d>::~CProfilerExampleSampler",BufferSize);
|
20
|
424 |
}
|
|
425 |
|
|
426 |
#include <piprofiler/ProfilerGenericClassesKrn.inl>
|
|
427 |
|
|
428 |
#endif
|
|
429 |
|
|
430 |
|
|
431 |
#endif
|