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