|
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_ITT_SAMPLER_H |
|
20 #define PROFILER_ITT_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 /* |
|
31 * |
|
32 * ITT sampler definition |
|
33 * |
|
34 */ |
|
35 |
|
36 class IttSamplerImpl |
|
37 { |
|
38 public: |
|
39 IttSamplerImpl(); |
|
40 ~IttSamplerImpl(); |
|
41 |
|
42 TInt SampleImpl(TUint32 pc,TUint32 sampleNum); |
|
43 TBool SampleNeeded(TUint32 sampleNum); |
|
44 TInt CreateFirstSample(); |
|
45 void Reset(); |
|
46 |
|
47 TUint8* itt_sample; |
|
48 TBool iSampleProcesses; |
|
49 private: |
|
50 |
|
51 TUint8 internalData[256]; |
|
52 TPtr8* ptrToData; |
|
53 TInt currentLibCount; |
|
54 TInt currentProcCount; |
|
55 |
|
56 TBuf8<64> iVersionData; |
|
57 SDblQue* codeSegList; |
|
58 }; |
|
59 |
|
60 template <int BufferSize> |
|
61 class DProfilerIttSampler : public DProfilerGenericSampler<BufferSize> |
|
62 { |
|
63 public: |
|
64 DProfilerIttSampler(struct TProfilerGppSamplerData* gppSamplerDataIn); |
|
65 ~DProfilerIttSampler(); |
|
66 |
|
67 void Sample(); |
|
68 TInt Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset); |
|
69 TInt PostSample(); |
|
70 TBool PostSampleNeeded(); |
|
71 |
|
72 private: |
|
73 struct TProfilerGppSamplerData* gppSamplerData; |
|
74 IttSamplerImpl ittSampler; |
|
75 TBool sampleInProgress; |
|
76 TBool sampleNeeded; |
|
77 }; |
|
78 |
|
79 /* |
|
80 * |
|
81 * ITT sampler implementation |
|
82 * |
|
83 */ |
|
84 |
|
85 template <int BufferSize> |
|
86 DProfilerIttSampler<BufferSize>::DProfilerIttSampler(struct TProfilerGppSamplerData* gppSamplerDataIn) : |
|
87 DProfilerGenericSampler<BufferSize>(PROFILER_ITT_SAMPLER_ID) |
|
88 { |
|
89 this->gppSamplerData = (struct TProfilerGppSamplerData*)gppSamplerDataIn; |
|
90 this->sampleInProgress = false; |
|
91 LOGSTRING2("CProfilerIttSampler<%d>::CProfilerIttSampler",BufferSize); |
|
92 } |
|
93 |
|
94 template <int BufferSize> |
|
95 TInt DProfilerIttSampler<BufferSize>::Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset) |
|
96 { |
|
97 LOGSTRING2("CProfilerIttSampler<%d>::Reset - calling superclass reset",BufferSize); |
|
98 DProfilerGenericSampler<BufferSize>::Reset(aStream); |
|
99 LOGSTRING2("CProfilerIttSampler<%d>::Reset - called superclass reset",BufferSize); |
|
100 TInt length = this->ittSampler.CreateFirstSample(); |
|
101 this->iSampleBuffer->AddSample((TUint8*)&length,1); |
|
102 this->iSampleBuffer->AddSample(ittSampler.itt_sample,length); |
|
103 this->sampleInProgress = false; |
|
104 this->sampleNeeded = false; |
|
105 |
|
106 this->ittSampler.Reset(); |
|
107 |
|
108 return KErrNone; |
|
109 } |
|
110 |
|
111 template <int BufferSize> |
|
112 TInt DProfilerIttSampler<BufferSize>::PostSample() |
|
113 { |
|
114 if(sampleNeeded) |
|
115 { |
|
116 this->sampleNeeded = false; |
|
117 |
|
118 LOGSTRING3("CProfilerIttSampler<%d>::PostSample - state %d",BufferSize,this->sampleBuffer->GetBufferStatus()); |
|
119 |
|
120 |
|
121 TInt length = this->ittSampler.SampleImpl(this->gppSamplerData->lastPcValue, |
|
122 this->gppSamplerData->sampleNumber); |
|
123 if(length != 0) |
|
124 { |
|
125 LOGSTRING("ITT sampler PostSample - starting to sample"); |
|
126 |
|
127 while(length > 0) |
|
128 { |
|
129 this->iSampleBuffer->AddSample(ittSampler.itt_sample,length); |
|
130 length = this->ittSampler.SampleImpl( this->gppSamplerData->lastPcValue, |
|
131 this->gppSamplerData->sampleNumber ); |
|
132 if(length == 0) |
|
133 { |
|
134 LOGSTRING("MEM sampler PostSample - all samples generated!"); |
|
135 } |
|
136 } |
|
137 LOGSTRING("ITT sampler PostSample - finished sampling"); |
|
138 } |
|
139 this->sampleInProgress = false; |
|
140 } |
|
141 |
|
142 // finally perform superclass postsample |
|
143 TInt i = this->DProfilerGenericSampler<BufferSize>::PostSample(); |
|
144 return i; |
|
145 } |
|
146 |
|
147 template <int BufferSize> |
|
148 TBool DProfilerIttSampler<BufferSize>::PostSampleNeeded() |
|
149 { |
|
150 LOGSTRING3("CProfilerMemSampler<%d>::PostSampleNeeded - state %d",BufferSize,this->sampleBuffer->GetBufferStatus()); |
|
151 |
|
152 TUint32 status = this->iSampleBuffer->iBufferStatus; |
|
153 |
|
154 if(status == DProfilerSampleBuffer::BufferCopyAsap || status == DProfilerSampleBuffer::BufferFull || this->sampleNeeded == true) |
|
155 { |
|
156 return true; |
|
157 } |
|
158 |
|
159 return false; |
|
160 } |
|
161 |
|
162 template <int BufferSize> |
|
163 void DProfilerIttSampler<BufferSize>::Sample() |
|
164 { |
|
165 LOGSTRING2("CProfilerIttSampler<%d>::Sample",BufferSize); |
|
166 |
|
167 //#ifdef ITT_TEST |
|
168 LOGSTRING2("CProfilerIttSampler<%d>::Sample",BufferSize); |
|
169 |
|
170 if(ittSampler.SampleNeeded(this->gppSamplerData->sampleNumber) && this->sampleInProgress == false) |
|
171 { |
|
172 this->sampleInProgress = true; |
|
173 this->sampleNeeded = true; |
|
174 |
|
175 LOGSTRING2("CProfilerIttSampler<%d>::Sample - sample needed",BufferSize); |
|
176 } |
|
177 |
|
178 LOGSTRING2("CProfilerIttSampler<%d>::Sample",BufferSize); |
|
179 |
|
180 return; |
|
181 } |
|
182 |
|
183 template <int BufferSize> |
|
184 DProfilerIttSampler<BufferSize>::~DProfilerIttSampler() |
|
185 { |
|
186 LOGSTRING2("CProfilerIttSampler<%d>::~CProfilerIttSampler",BufferSize); |
|
187 } |
|
188 #endif |