|
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 __PROFILERENGINE__ |
|
20 #define __PROFILERENGINE__ |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <e32svr.h> |
|
24 #include <e32property.h> |
|
25 |
|
26 #include <piprofiler/SamplerPluginInterface.h> |
|
27 #include <piprofiler/WriterPluginInterface.h> |
|
28 #include <piprofiler/ProfilerSession.h> |
|
29 #include <piprofiler/ProfilerAttributes.h> // internal settings format presentations |
|
30 |
|
31 #include "SamplerController.h" |
|
32 #include "WriterController.h" |
|
33 #include "ProfilerErrorChecker.h" |
|
34 #include "ProfilerTimer.h" |
|
35 |
|
36 // CONSTANTS |
|
37 const TInt KProfilerPrefixMaxLength = 32; |
|
38 const TInt KSettingsFileSize = 4096; |
|
39 |
|
40 /* |
|
41 * This is an internal interface to the profiling engine which allows |
|
42 * an additional control DLL to be loaded, replacing the profiler's |
|
43 * default console UI |
|
44 */ |
|
45 |
|
46 /** |
|
47 * Implementation class providing access to the profiler engine |
|
48 */ |
|
49 |
|
50 class MProfilerEngine |
|
51 { |
|
52 public: |
|
53 virtual TInt ControlL(TInt aCommand) =0; |
|
54 virtual TInt ControlDataL(TInt aCommand, TAny* data1 = 0, TAny* data2 = 0) = 0; |
|
55 |
|
56 virtual TInt GetSamplerAttributesL(const RMessage2& aMessage) = 0; |
|
57 virtual TInt GetSamplerAttributeCountL(const RMessage2& aMessage) = 0; |
|
58 virtual TInt SetSamplerAttributesL(const RMessage2& aMessage) = 0; |
|
59 virtual TInt GetGeneralAttributesL(const RMessage2& aMessage) = 0; |
|
60 virtual TInt SetGeneralAttributesL(const RMessage2& aMessage) = 0; |
|
61 virtual TInt RefreshStatus(const RMessage2& aMessage) = 0; |
|
62 virtual RProfiler::TSamplerState State() const =0; |
|
63 }; |
|
64 |
|
65 /** |
|
66 * The interface that the extra controller must implement to access |
|
67 * the profiler. |
|
68 */ |
|
69 class MProfilerController |
|
70 { |
|
71 public: |
|
72 /** Release the controller from the profiler. This is invoked when the profiler is unloading. */ |
|
73 virtual void Release() = 0; |
|
74 /** Ask the profiler to change state */ |
|
75 inline TInt ControlL(TInt aCommand) const; |
|
76 /** Ask the profiler to change state */ |
|
77 inline TInt ControlDataL(TInt aCommand, TAny* data1 = 0, TAny* data2 = 0) const; |
|
78 |
|
79 inline TInt GetSamplerAttributesL(const RMessage2& aMessage) const; |
|
80 inline TInt SetSamplerAttributesL(const RMessage2& aMessage) const; |
|
81 inline TInt GetGeneralAttributesL(const RMessage2& aMessage) const; |
|
82 inline TInt SetGeneralAttributesL(const RMessage2& aMessage) const; |
|
83 inline TInt GetSamplerAttributeCountL(const RMessage2& aMessage) const; |
|
84 inline TInt RefreshStatus(const RMessage2& aMessage) const; |
|
85 /* Query the profiler state */ |
|
86 inline RProfiler::TSamplerState GeTComand() const; |
|
87 protected: |
|
88 inline MProfilerController(MProfilerEngine& aEngine); |
|
89 private: |
|
90 MProfilerEngine& iEngine; |
|
91 }; |
|
92 |
|
93 /** The signature of ordinal 1 in the controller DLL */ |
|
94 typedef MProfilerController* (*TProfilerControllerFactoryL)(TInt aPriority, MProfilerEngine& aEngine); |
|
95 /** The second UID required by the controller DLL */ |
|
96 const TUid KUidProfilerKeys={0x1000945c}; |
|
97 |
|
98 inline MProfilerController::MProfilerController(MProfilerEngine& aEngine) |
|
99 :iEngine(aEngine) |
|
100 { |
|
101 |
|
102 } |
|
103 |
|
104 inline TInt MProfilerController::ControlL(TInt aCommand) const |
|
105 { |
|
106 return iEngine.ControlL(aCommand); |
|
107 } |
|
108 |
|
109 inline TInt MProfilerController::ControlDataL(TInt aCommand,TAny* data1, TAny* data2) const |
|
110 { |
|
111 return iEngine.ControlDataL(aCommand,data1,data2); |
|
112 } |
|
113 |
|
114 inline TInt MProfilerController::GetSamplerAttributesL(const RMessage2& aMessage) const |
|
115 { |
|
116 return iEngine.GetSamplerAttributesL(aMessage); |
|
117 } |
|
118 |
|
119 inline TInt MProfilerController::SetSamplerAttributesL(const RMessage2& aMessage) const |
|
120 { |
|
121 return iEngine.SetSamplerAttributesL(aMessage); |
|
122 } |
|
123 |
|
124 inline TInt MProfilerController::GetGeneralAttributesL(const RMessage2& aMessage) const |
|
125 { |
|
126 return iEngine.GetGeneralAttributesL(aMessage); |
|
127 } |
|
128 |
|
129 inline TInt MProfilerController::GetSamplerAttributeCountL(const RMessage2& aMessage) const |
|
130 { |
|
131 return iEngine.GetSamplerAttributeCountL(aMessage); |
|
132 } |
|
133 |
|
134 inline TInt MProfilerController::SetGeneralAttributesL(const RMessage2& aMessage) const |
|
135 { |
|
136 return iEngine.SetGeneralAttributesL(aMessage); |
|
137 } |
|
138 |
|
139 inline TInt MProfilerController::RefreshStatus(const RMessage2& aMessage) const |
|
140 { |
|
141 return iEngine.RefreshStatus(aMessage); |
|
142 } |
|
143 |
|
144 inline RProfiler::TSamplerState MProfilerController::GeTComand() const |
|
145 { |
|
146 return iEngine.State(); |
|
147 } |
|
148 |
|
149 class CSamplerController; |
|
150 class CWriterController; |
|
151 class MSamplerControllerObserver; |
|
152 class MProfilerErrorObserver; |
|
153 |
|
154 class CProfiler : public CBase, private MProfilerEngine, |
|
155 MSamplerControllerObserver, |
|
156 MProfilerErrorObserver, |
|
157 MProfilerTimerObserver |
|
158 { |
|
159 public: |
|
160 |
|
161 static CProfiler* NewLC(const TDesC& aSettingsFile); |
|
162 |
|
163 /** |
|
164 * Method for control commands, i.e. start, stop and exit |
|
165 * |
|
166 * @param aCommand command to be parsed and executed |
|
167 * @return TInt KErrNone if succeed, else error code |
|
168 */ |
|
169 TInt ControlL(TInt aCommand); |
|
170 |
|
171 /** |
|
172 * Method for control data, e.g. settings |
|
173 * |
|
174 * @param aCommand command to be parsed and executed |
|
175 * @param value1 can contain any value, integer or string, depends on use case |
|
176 * @param value2 can contain any value, integer or string, depends on use case |
|
177 * @return TInt KErrNone if succeed, else error code |
|
178 */ |
|
179 TInt ControlDataL(TInt aCommand, TAny* value1 = 0, TAny* value2 = 0); |
|
180 |
|
181 // setting attributes manipulation |
|
182 TInt GetGeneralAttributesL(const RMessage2& aMessage); |
|
183 TInt GetSamplerAttributesL(const RMessage2& aMessage); |
|
184 TInt SetGeneralAttributesL(const RMessage2& aMessage); |
|
185 TInt SetSamplerAttributesL(const RMessage2& aMessage); |
|
186 TInt GetSamplerAttributeCountL(const RMessage2& aMessage); |
|
187 TInt RefreshStatus(const RMessage2& /*aMessage*/); |
|
188 |
|
189 // from CProfilerErrorChecker |
|
190 void HandleSamplerControllerReadyL(); |
|
191 void NotifyRequesterForSettingsUpdate(); |
|
192 void HandleProfilerErrorChangeL( TInt aError ); |
|
193 |
|
194 // from MProfilerTimerObserver |
|
195 void HandleTimerExpiresL(TInt aError); |
|
196 |
|
197 void Finalise(); |
|
198 CProfilerSampleStream* GetSamplerStream(); |
|
199 void HandleError(TInt aErr); |
|
200 static TBool CheckLocationSanity(RFs& fs, const TDesC8& aLocation); |
|
201 private: |
|
202 CProfiler(const TDesC& aSettingsFile); |
|
203 ~CProfiler(); |
|
204 void ConstructL(); |
|
205 TInt LoadSettingsL(/*const TDesC& configFile*/); |
|
206 void DoGetValueFromSettingsArray(CDesC8ArrayFlat* aLineArray, const TDesC8& aAttribute, TDes8& aValue); |
|
207 void DoGetValueFromSettingsArray(CDesC8ArrayFlat* aLineArray, const TDesC8& aAttribute, TInt& aValue); |
|
208 void UpdateSavedGeneralAttributes(CDesC8ArrayFlat* aSavedAttributes); |
|
209 template<class T> CBufFlat* ExternalizeLC(const T& aElements); |
|
210 |
|
211 RProfiler::TSamplerState State() const; |
|
212 |
|
213 void DrainSampleStream(); |
|
214 void InstallStreamForActiveTraces(CSamplerPluginInterface& aSampler, CWriterPluginInterface& aWriter, TDesC& totalPrefix); |
|
215 void SaveSettingsL(); |
|
216 |
|
217 TInt HandleGeneralSettingsChange(); |
|
218 TInt CheckOldProfilerRunning(); |
|
219 public: |
|
220 // trace file settings |
|
221 TBuf8<KProfilerPrefixMaxLength> iFilePrefix; |
|
222 TBuf8<KProfilerPrefixMaxLength> iDriveLetter; |
|
223 TBuf8<KProfilerPrefixMaxLength*2> iTotalPrefix; |
|
224 |
|
225 TBuf<256> iSettingsFileLocation; |
|
226 |
|
227 MProfilerController* iServer; |
|
228 RProfiler::TSamplerState iState; |
|
229 |
|
230 CProfilerSampleStream* iUserStream; |
|
231 |
|
232 // plug-in controllers |
|
233 CWriterController* iWriterHandler; |
|
234 CSamplerController* iSamplerHandler; |
|
235 |
|
236 // setting attribute containers |
|
237 TGeneralAttributes iGeneralAttributes; |
|
238 CArrayFixFlat<TSamplerAttributes>* iDefaultSamplerAttributesArray; |
|
239 |
|
240 // temporary settings file array container |
|
241 CDesC8ArrayFlat* iSavedLineArray; |
|
242 TInt iSavedLinesCount; |
|
243 // saved settings, add extra 1 byte space to end buffer with a '\n' |
|
244 TBuf8<KSettingsFileSize + 1> iSettingsBuffer; |
|
245 |
|
246 // P&S status properties |
|
247 RProperty iEngineStatus; |
|
248 RProperty iUpdateStatus; |
|
249 TBuf<128> iFileNameStream; |
|
250 private: |
|
251 TBool iSettingsFileLoaded; |
|
252 CProfilerErrorChecker* iErrorChecker; |
|
253 CProfilerTimer* iTimer; |
|
254 }; |
|
255 |
|
256 #include <piprofiler/ProfilerGenericClassesUsr.h> |
|
257 #endif // __PROFILERENGINE__ |
|
258 |