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 PriSamplerImpl |
|
41 { |
|
42 public: |
|
43 enum EProcessingState |
|
44 { |
|
45 EStartingToProcess, |
|
46 EProcessingNames, |
|
47 EProcessingData, |
|
48 ENothingToProcess |
|
49 }; |
|
50 |
|
51 PriSamplerImpl(); |
|
52 ~PriSamplerImpl(); |
|
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 |
|
79 }; |
|
80 |
|
81 template <int BufferSize> |
|
82 class DProfilerPriSampler : public DProfilerGenericSampler<BufferSize> |
|
83 { |
|
84 public: |
|
85 DProfilerPriSampler(struct TProfilerGppSamplerData*, TInt id); |
|
86 ~DProfilerPriSampler(); |
|
87 |
|
88 void Sample(); |
|
89 TInt Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset); |
|
90 TInt PostSample(); |
|
91 TBool PostSampleNeeded(); |
|
92 |
|
93 private: |
|
94 PriSamplerImpl priSamplerImpl; |
|
95 struct TProfilerGppSamplerData* gppSamplerData; |
|
96 TBool sampleNeeded; |
|
97 TBool sampleInProgress; |
|
98 }; |
|
99 |
|
100 /* |
|
101 * |
|
102 * PRI sampler implementation |
|
103 * |
|
104 */ |
|
105 |
|
106 template <int BufferSize> |
|
107 DProfilerPriSampler<BufferSize>::DProfilerPriSampler(struct TProfilerGppSamplerData* gppSamplerDataIn, TInt id) : |
|
108 DProfilerGenericSampler<BufferSize>(PROFILER_PRI_SAMPLER_ID) |
|
109 { |
|
110 LOGSTRING2("CProfilerPriSampler<%d>::CProfilerPriSampler",BufferSize); |
|
111 this->gppSamplerData = gppSamplerDataIn; |
|
112 this->sampleInProgress = false; |
|
113 this->iSamplingPeriod = 3000; // set default setting |
|
114 } |
|
115 |
|
116 template <int BufferSize> |
|
117 TInt DProfilerPriSampler<BufferSize>::Reset(DProfilerSampleStream* aStream, TUint32 aSyncOffset) |
|
118 { |
|
119 LOGSTRING2("CProfilerPriSampler<%d>::Reset - calling superclass reset",BufferSize); |
|
120 DProfilerGenericSampler<BufferSize>::Reset(aStream); |
|
121 LOGSTRING2("CProfilerPriSampler<%d>::Reset - called superclass reset",BufferSize); |
|
122 priSamplerImpl.Reset(); |
|
123 |
|
124 this->priSamplerImpl.iPriSamplingPeriod = this->iSamplingPeriod; |
|
125 |
|
126 |
|
127 LOGSTRING3("CProfilerPriSampler<%d>::Reset - set pri sampling period to", |
|
128 BufferSize,this->priSamplerImpl.iPriSamplingPeriod); |
|
129 |
|
130 TInt length = priSamplerImpl.CreateFirstSample(); |
|
131 this->iSampleBuffer->AddSample(priSamplerImpl.sample,length); |
|
132 |
|
133 this->sampleInProgress = false; |
|
134 this->sampleNeeded = false; |
|
135 |
|
136 return KErrNone; |
|
137 } |
|
138 |
|
139 template <int BufferSize> |
|
140 TInt DProfilerPriSampler<BufferSize>::PostSample() |
|
141 { |
|
142 if(sampleNeeded) |
|
143 { |
|
144 this->sampleNeeded = false; |
|
145 |
|
146 LOGSTRING3("CProfilerPriSampler<%d>::PostSample - state %d",BufferSize,this->sampleBuffer->GetBufferStatus()); |
|
147 |
|
148 TInt interruptLevel = NKern::DisableInterrupts(0); |
|
149 |
|
150 TInt length = this->priSamplerImpl.SampleImpl(); |
|
151 if(length != 0) |
|
152 { |
|
153 LOGSTRING("PRI sampler PostSample - starting to sample"); |
|
154 |
|
155 // then, encode the sample to the buffer |
|
156 while(length > 0) |
|
157 { |
|
158 this->iSampleBuffer->AddSample(priSamplerImpl.sample,length); |
|
159 length = this->priSamplerImpl.SampleImpl(); |
|
160 // indicate that the whole PRI sample ends by having a 0x00 in the end |
|
161 if(length == 0) |
|
162 { |
|
163 TUint8 number = 0; |
|
164 LOGSTRING("PRI sampler PostSample - all samples generated!"); |
|
165 |
|
166 this->iSampleBuffer->AddSample(&number,1); |
|
167 LOGSTRING("PRI sampler PostSample - end mark added"); |
|
168 } |
|
169 } |
|
170 LOGSTRING("PRI sampler PostSample - finished sampling"); |
|
171 } |
|
172 this->sampleInProgress = false; |
|
173 |
|
174 NKern::RestoreInterrupts(interruptLevel); |
|
175 } |
|
176 |
|
177 // finally perform superclass postsample |
|
178 TInt i = this->DProfilerGenericSampler<BufferSize>::PostSample(); |
|
179 return i; |
|
180 } |
|
181 |
|
182 template <int BufferSize> |
|
183 TBool DProfilerPriSampler<BufferSize>::PostSampleNeeded() |
|
184 { |
|
185 LOGSTRING3("CProfilerPriSampler<%d>::PostSampleNeeded - state %d",BufferSize,this->sampleBuffer->GetBufferStatus()); |
|
186 |
|
187 TUint32 status = this->iSampleBuffer->iBufferStatus; |
|
188 |
|
189 if(status == DProfilerSampleBuffer::BufferCopyAsap || status == DProfilerSampleBuffer::BufferFull || this->sampleNeeded == true) |
|
190 { |
|
191 return true; |
|
192 } |
|
193 |
|
194 return false; |
|
195 } |
|
196 |
|
197 |
|
198 template <int BufferSize> |
|
199 void DProfilerPriSampler<BufferSize>::Sample() |
|
200 { |
|
201 LOGSTRING2("CProfilerPriSampler<%d>::Sample",BufferSize); |
|
202 |
|
203 if(priSamplerImpl.SampleNeeded() && this->sampleInProgress == false) |
|
204 { |
|
205 this->sampleInProgress = true; |
|
206 this->sampleNeeded = true; |
|
207 // start the PRI sample with the sample time |
|
208 TUint8 number = 4; |
|
209 this->iSampleBuffer->AddSample(&number,1); |
|
210 this->iSampleBuffer->AddSample((TUint8*)&(gppSamplerData->sampleNumber),4); |
|
211 |
|
212 // leave the rest of the processing for PostSample() |
|
213 } |
|
214 |
|
215 LOGSTRING2("CProfilerPriSampler<%d>::Sample",BufferSize); |
|
216 return; |
|
217 } |
|
218 |
|
219 template <int BufferSize> |
|
220 DProfilerPriSampler<BufferSize>::~DProfilerPriSampler() |
|
221 { |
|
222 LOGSTRING2("CProfilerPriSampler<%d>::~CProfilerPriSampler",BufferSize); |
|
223 } |
|
224 #endif |
|