51
|
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 |
#include <e32cons.h>
|
|
20 |
#include <e32base.h>
|
|
21 |
#include <f32file.h>
|
|
22 |
#include <c32comm.h>
|
|
23 |
#include <s32file.h>
|
|
24 |
#include <pathinfo.h>
|
|
25 |
#include <s32mem.h>
|
|
26 |
#include <bautils.h>
|
|
27 |
#include <sysutil.h>
|
|
28 |
#include <piprofiler/ProfilerConfig.h>
|
|
29 |
#include "ProfilerEngine.h"
|
|
30 |
#include <piprofiler/ProfilerTraces.h>
|
|
31 |
|
|
32 |
// properties
|
|
33 |
const TUid KEngineStatusPropertyCat={0x2001E5AD};
|
|
34 |
enum TEnginePropertyKeys
|
|
35 |
{
|
|
36 |
EProfilerEngineStatus = 8,
|
|
37 |
EProfilerErrorStatus
|
|
38 |
};
|
|
39 |
|
|
40 |
static _LIT_SECURITY_POLICY_PASS( KAllowAllPolicy );
|
|
41 |
|
|
42 |
// CONSTANTS
|
|
43 |
const TInt KStreamBufferSize = 32768;
|
|
44 |
const TInt KSavedLineCount = 64;
|
|
45 |
const TInt KFileNameBufSize = 128;
|
|
46 |
// Use this UID if plugin belongs to DebOutWriterPlugin:
|
|
47 |
const TUid KDebOutWriterPluginUid = { 0x2001E5BA };
|
|
48 |
// Use this UID if plugin belongs to MmcOutWriterPlugin:
|
|
49 |
const TUid KDiskWriterPluginUid = { 0x2001E5BB };
|
|
50 |
|
|
51 |
// LITERALS
|
|
52 |
_LIT8(KGenericTraceOutput, "output_type");
|
|
53 |
_LIT8(KGenericTraceFilePrefix, "file_prefix");
|
|
54 |
_LIT8(KGenericTraceFileSaveDrive, "save_file_location");
|
|
55 |
_LIT8(KGenericTimedProfilingPeriod, "profiling_period");
|
|
56 |
_LIT8(KEquals, "=");
|
|
57 |
_LIT8(KNewLineSeparator, "\n");
|
|
58 |
_LIT8(KProfilerVersionTag, "version");
|
|
59 |
_LIT8(KEndMark, "[end]");
|
|
60 |
_LIT8(KOutputToDebugOutput, "debug_output");
|
|
61 |
|
|
62 |
/**
|
|
63 |
*
|
|
64 |
* The controller class used to provide the Profiler functions.
|
|
65 |
* This runs as a server in the engine thread
|
|
66 |
*
|
|
67 |
*/
|
|
68 |
class CPServer : public CServer2, public MProfilerController
|
|
69 |
{
|
|
70 |
public:
|
|
71 |
static MProfilerController* NewL(TInt aPriority, MProfilerEngine& aEngine);
|
|
72 |
|
|
73 |
private:
|
|
74 |
CPServer(TInt aPriority, MProfilerEngine& aEngine);
|
|
75 |
void Release();
|
|
76 |
CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const;
|
|
77 |
|
|
78 |
public:
|
|
79 |
static TInt iClientCount;
|
|
80 |
};
|
|
81 |
|
|
82 |
TInt CPServer::iClientCount = 0;
|
|
83 |
|
|
84 |
// The session class used by the server controller
|
|
85 |
class CPSession : public CSession2
|
|
86 |
{
|
|
87 |
private:
|
|
88 |
inline const CPServer& Server() const;
|
|
89 |
void ServiceL(const RMessage2& aMessage);
|
|
90 |
};
|
|
91 |
|
|
92 |
/*
|
|
93 |
*
|
|
94 |
* CProfiler class implementation
|
|
95 |
*
|
|
96 |
*/
|
|
97 |
// --------------------------------------------------------------------------------------------
|
62
|
98 |
CProfiler* CProfiler::NewLC(const TDesC& aSettingsFile, TBool aBootMode)
|
51
|
99 |
{
|
62
|
100 |
CProfiler* self = new(ELeave) CProfiler(aSettingsFile ,aBootMode);
|
51
|
101 |
CleanupStack::PushL(self);
|
|
102 |
self->ConstructL();
|
62
|
103 |
|
|
104 |
LOGTEXT(_L("CProfiler::NewLC - done"));
|
51
|
105 |
return self;
|
|
106 |
}
|
|
107 |
|
|
108 |
// --------------------------------------------------------------------------------------------
|
62
|
109 |
CProfiler::CProfiler(const TDesC& aSettingsFile, TBool aBootMode) :
|
|
110 |
iSettingsFileLocation(aSettingsFile),
|
|
111 |
iBootMode(aBootMode)
|
51
|
112 |
{
|
|
113 |
// define property for Profiler Engine status, UI may read it for control purposes
|
|
114 |
if ( RProperty::Define(KEngineStatusPropertyCat,
|
|
115 |
EProfilerEngineStatus,
|
|
116 |
RProperty::EInt,
|
|
117 |
KAllowAllPolicy,
|
|
118 |
KAllowAllPolicy,
|
|
119 |
0) != KErrAlreadyExists )
|
|
120 |
{
|
|
121 |
LOGTEXT(_L("CProfiler::CProfiler - status property already defined"));
|
|
122 |
}
|
|
123 |
|
|
124 |
if ( RProperty::Define(KEngineStatusPropertyCat,
|
|
125 |
EProfilerErrorStatus,
|
|
126 |
RProperty::EInt,
|
|
127 |
KAllowAllPolicy,
|
|
128 |
KAllowAllPolicy,
|
|
129 |
0) != KErrAlreadyExists )
|
|
130 |
{
|
|
131 |
LOGTEXT(_L("CProfiler::CProfiler - status property already defined"));
|
|
132 |
}
|
|
133 |
|
|
134 |
// attach to own property
|
|
135 |
iEngineStatus.Attach(KEngineStatusPropertyCat, EProfilerEngineStatus);
|
|
136 |
// set status idle
|
|
137 |
iEngineStatus.Set(KEngineStatusPropertyCat, EProfilerEngineStatus, RProfiler::EIdle);
|
|
138 |
|
|
139 |
// attach to own property
|
|
140 |
iUpdateStatus.Attach(KEngineStatusPropertyCat, EProfilerErrorStatus);
|
|
141 |
// set status idle
|
|
142 |
iUpdateStatus.Set(KEngineStatusPropertyCat, EProfilerErrorStatus, EFalse);
|
|
143 |
}
|
|
144 |
|
|
145 |
// --------------------------------------------------------------------------------------------
|
|
146 |
CProfiler::~CProfiler()
|
|
147 |
{
|
|
148 |
LOGTEXT(_L("CProfiler::~CProfiler - Enter"));
|
|
149 |
|
|
150 |
// delete error checker
|
|
151 |
if(iErrorChecker)
|
|
152 |
{
|
|
153 |
iErrorChecker->Cancel();
|
|
154 |
delete iErrorChecker;
|
|
155 |
iErrorChecker = NULL;
|
|
156 |
}
|
|
157 |
|
|
158 |
// delete settings array
|
|
159 |
if(iDefaultSamplerAttributesArray)
|
|
160 |
{
|
|
161 |
iDefaultSamplerAttributesArray->Reset();
|
|
162 |
delete iDefaultSamplerAttributesArray;
|
|
163 |
iDefaultSamplerAttributesArray = NULL;
|
|
164 |
}
|
|
165 |
|
|
166 |
// delete settings file raw line array
|
|
167 |
if(iSavedLineArray)
|
|
168 |
{
|
|
169 |
iSavedLineArray->Reset();
|
|
170 |
delete iSavedLineArray;
|
|
171 |
iSavedLineArray = NULL;
|
|
172 |
}
|
|
173 |
|
|
174 |
// delete sampler controller, cleans up the sampler plugin instances
|
|
175 |
if(iSamplerHandler)
|
|
176 |
{
|
|
177 |
delete iSamplerHandler;
|
|
178 |
iSamplerHandler = NULL;
|
|
179 |
}
|
|
180 |
// delete writer controller, cleans up the writer plugin instances
|
|
181 |
if(iWriterHandler)
|
|
182 |
{
|
|
183 |
delete iWriterHandler;
|
|
184 |
iWriterHandler = NULL;
|
|
185 |
}
|
|
186 |
|
|
187 |
// delete user side sampler stream
|
|
188 |
if(iUserStream)
|
|
189 |
{
|
|
190 |
delete iUserStream;
|
|
191 |
iUserStream = NULL;
|
|
192 |
}
|
|
193 |
|
|
194 |
// close engine status property
|
|
195 |
iEngineStatus.Close();
|
62
|
196 |
TInt ret = RProperty::Delete(KEngineStatusPropertyCat, EProfilerEngineStatus);
|
|
197 |
if ( ret != KErrNone)
|
51
|
198 |
{
|
62
|
199 |
LOGSTRING2("CProfiler::~CProfiler - cannot close status property %d", ret);
|
|
200 |
|
51
|
201 |
}
|
|
202 |
// close engine update property
|
|
203 |
iUpdateStatus.Close();
|
62
|
204 |
ret = RProperty::Delete(KEngineStatusPropertyCat, EProfilerErrorStatus);
|
|
205 |
if (ret != KErrNone)
|
51
|
206 |
{
|
62
|
207 |
LOGSTRING2("CProfiler::~CProfiler - cannot close update property %d",ret);
|
51
|
208 |
}
|
|
209 |
|
|
210 |
// close server process
|
|
211 |
if (iServer)
|
|
212 |
{
|
|
213 |
LOGTEXT(_L("CProfiler::~CProfiler - Releasing server"));
|
|
214 |
iServer->Release();
|
|
215 |
}
|
|
216 |
|
|
217 |
if( iTimer )
|
|
218 |
{
|
|
219 |
iTimer->Cancel();
|
|
220 |
delete iTimer;
|
|
221 |
iTimer = 0;
|
|
222 |
}
|
|
223 |
|
|
224 |
LOGTEXT(_L("CProfiler::~CProfiler - Finished"));
|
|
225 |
}
|
|
226 |
|
|
227 |
// --------------------------------------------------------------------------------------------
|
|
228 |
void CProfiler::ConstructL()
|
|
229 |
{
|
|
230 |
LOGTEXT(_L("CProfiler::ConstructL - Enter"));
|
62
|
231 |
TInt err(0);
|
51
|
232 |
TLex lex;
|
62
|
233 |
|
|
234 |
if(iBootMode)
|
|
235 |
{
|
|
236 |
LOGSTRING("boot mode enabled");
|
|
237 |
}
|
|
238 |
else
|
|
239 |
{
|
|
240 |
LOGSTRING("normal mode enabled");
|
|
241 |
}
|
51
|
242 |
|
|
243 |
if ( iSettingsFileLocation.CompareF(KNullDesC) != 0 )
|
|
244 |
{
|
|
245 |
lex=(iSettingsFileLocation);
|
|
246 |
// parse the first command line argument, the command itself
|
|
247 |
lex.Mark();
|
|
248 |
lex.SkipCharacters();
|
|
249 |
if(lex.TokenLength() != 0)
|
|
250 |
{
|
|
251 |
// there is another item in the list
|
|
252 |
TPtrC filename = lex.MarkedToken();
|
|
253 |
LOGSTRING2("filename %S", &filename);
|
62
|
254 |
|
|
255 |
}
|
|
256 |
}
|
|
257 |
else
|
|
258 |
{
|
|
259 |
LOGSTRING("CProfiler::ConstructL - Enter - settingsfilelocation null");
|
51
|
260 |
}
|
|
261 |
|
|
262 |
// create new sampler stream instance
|
|
263 |
iUserStream = CProfilerSampleStream::NewL(KStreamBufferSize);
|
|
264 |
if(!iUserStream)
|
|
265 |
{
|
|
266 |
LOGTEXT(_L("Profiler engine cannot reserve memory"));
|
|
267 |
User::Leave(KErrCancel); // operation cancelled
|
|
268 |
}
|
|
269 |
|
|
270 |
// engine status checker
|
|
271 |
iErrorChecker = CProfilerErrorChecker::NewL();
|
|
272 |
iErrorChecker->SetObserver(this);
|
|
273 |
|
62
|
274 |
// create and initiate plug-in controller instances
|
|
275 |
iSamplerHandler = CSamplerController::NewL(*iUserStream, iBootMode);
|
|
276 |
LOGSTRING("CSamplerController started from ProfilerEngine");
|
|
277 |
iWriterHandler = CWriterController::NewL(*iUserStream, iBootMode);
|
|
278 |
LOGSTRING("CWriterController started from ProfilerEngine");
|
51
|
279 |
iWriterHandler->InitialiseWriterListL();
|
62
|
280 |
LOGSTRING("WriterList initialised started from ProfilerEngine");
|
51
|
281 |
// set engine as an observer to sampler controller to get the notification of plugin load has ended
|
|
282 |
iSamplerHandler->SetObserver(this);
|
|
283 |
|
|
284 |
// default settings from sampler plugins, maximum 20 sampler plugins
|
|
285 |
iDefaultSamplerAttributesArray = new(ELeave) CArrayFixFlat<TSamplerAttributes>(20);
|
|
286 |
|
|
287 |
// set profiler status to initializing
|
|
288 |
iState = RProfiler::EInitializing;
|
|
289 |
iEngineStatus.Set(RProfiler::EInitializing);
|
|
290 |
|
|
291 |
// set default general settings, will be overdriven if changed in settings file
|
|
292 |
iGeneralAttributes.iTraceOutput.Copy(KDefaultTraceOutput);
|
|
293 |
iGeneralAttributes.iTraceFilePrefix.Copy(KDefaultTraceFilePrefix);
|
|
294 |
iGeneralAttributes.iSaveFileDrive.Copy(KDefaultTraceFileSaveDrive);
|
|
295 |
iGeneralAttributes.iTimedSamplingPeriod = KDefaultTimedSamplingPeriod;
|
|
296 |
|
|
297 |
RThread me;
|
|
298 |
|
|
299 |
me.SetPriority(EPriorityRealTime);
|
|
300 |
|
|
301 |
err = KErrGeneral;
|
|
302 |
TInt count = 0;
|
|
303 |
|
|
304 |
while(err != KErrNone && count < 30)
|
|
305 |
{
|
|
306 |
err = User::RenameThread(KProfilerName);
|
|
307 |
if(err != KErrNone)
|
|
308 |
{
|
|
309 |
LOGSTRING2("CProfiler: error renaming the thread, err %d", err);
|
|
310 |
User::Leave(err);
|
|
311 |
}
|
|
312 |
else break;
|
|
313 |
}
|
|
314 |
|
62
|
315 |
if(err != KErrNone)
|
|
316 |
{
|
|
317 |
User::Leave(err);
|
|
318 |
}
|
|
319 |
|
51
|
320 |
// set settings file loading preferences
|
|
321 |
iSettingsFileLoaded = EFalse;
|
|
322 |
|
|
323 |
// change status property to idle since initialization successfull
|
|
324 |
iState = RProfiler::EIdle;
|
|
325 |
if( iEngineStatus.Set((TInt)RProfiler::EIdle) != KErrNone )
|
|
326 |
{
|
|
327 |
LOGTEXT(_L("CProfiler::ConstructL - engine status property change failed"));
|
|
328 |
}
|
|
329 |
|
|
330 |
if( iUpdateStatus.Set(EFalse) != KErrNone )
|
|
331 |
{
|
|
332 |
LOGTEXT(_L("CProfiler::ConstructL - engine status property change failed"));
|
|
333 |
}
|
|
334 |
|
|
335 |
// create a server instance for clients to communicate with
|
|
336 |
iServer = CPServer::NewL(10,*this);
|
|
337 |
|
|
338 |
// close the handle
|
|
339 |
me.Close();
|
|
340 |
|
|
341 |
iTimer = CProfilerTimer::NewL(CActive::EPriorityStandard, *this);
|
|
342 |
|
|
343 |
LOGTEXT(_L("CProfiler::ConstructL - Exit"));
|
|
344 |
|
|
345 |
}
|
|
346 |
|
|
347 |
CProfilerSampleStream* CProfiler::GetSamplerStream()
|
|
348 |
{
|
|
349 |
return iUserStream;
|
|
350 |
}
|
|
351 |
|
|
352 |
void CProfiler::HandleSamplerControllerReadyL()
|
|
353 |
{
|
|
354 |
// load settings
|
|
355 |
// check if settings file already loaded
|
|
356 |
if(!iSettingsFileLoaded)
|
|
357 |
{
|
|
358 |
// load default settings file
|
|
359 |
LoadSettingsL();
|
|
360 |
|
|
361 |
iSettingsFileLoaded = ETrue;
|
|
362 |
}
|
62
|
363 |
LOGSTRING("CProfiler::HandleSamplerControllerReadyL rendezvous");
|
51
|
364 |
// notify engine's launcher(UI or PIProfilerLauncher) to continue launch
|
|
365 |
RProcess::Rendezvous(KErrNone);
|
|
366 |
}
|
|
367 |
|
|
368 |
void CProfiler::NotifyRequesterForSettingsUpdate()
|
|
369 |
{
|
|
370 |
// set update status P&S property true => update needed on UI side
|
|
371 |
iUpdateStatus.Set(ETrue);
|
|
372 |
}
|
|
373 |
|
|
374 |
void CProfiler::HandleProfilerErrorChangeL(TInt aError)
|
|
375 |
{
|
|
376 |
LOGSTRING2("CProfiler::HandleProfilerErrorChangeL() - error received, %d", aError);
|
|
377 |
|
|
378 |
// check if profiler running
|
|
379 |
if(iState == RProfiler::ERunning)
|
|
380 |
{
|
|
381 |
// stop profiler if error occurred during the trace
|
|
382 |
iEngineStatus.Set(aError);
|
|
383 |
|
|
384 |
// stop samplers, NOTE! Writer plugins not stopped since
|
|
385 |
iSamplerHandler->StopSamplerPlugins();
|
|
386 |
|
|
387 |
// stop debug output plugin and write the rest of the trace data to output
|
|
388 |
if(iGeneralAttributes.iTraceOutput.CompareF(KOutputToDebugOutput) == 0)
|
|
389 |
{
|
|
390 |
// write the rest of trace data only if debug output selected
|
|
391 |
iWriterHandler->StopSelectedPlugin();
|
|
392 |
}
|
|
393 |
LOGSTRING2("CProfiler::HandleProfilerErrorChangeL - sampling stopped, going to state %d", RProfiler::EIdle);
|
|
394 |
}
|
|
395 |
}
|
|
396 |
|
|
397 |
// ----------------------------------------------------------------------------
|
|
398 |
// Gets a value from settings file for certain attribute.
|
|
399 |
// ----------------------------------------------------------------------------
|
|
400 |
void CProfiler::DoGetValueFromSettingsArray(CDesC8ArrayFlat* aLineArray, const TDesC8& aAttribute, TDes8& aValue)
|
|
401 |
{
|
62
|
402 |
LOGTEXT(_L("CProfiler::DoGetValueFromSettingsArray()"));
|
51
|
403 |
_LIT8(KSettingItemSeparator, "=");
|
|
404 |
|
|
405 |
// read a line of given array
|
|
406 |
for (TInt i=0; i<aLineArray->MdcaCount(); i++)
|
|
407 |
{
|
|
408 |
// check if this line has a separator
|
|
409 |
TInt sepPos = aLineArray->MdcaPoint(i).Find(KSettingItemSeparator);
|
|
410 |
if (sepPos > 0)
|
|
411 |
{
|
|
412 |
// check that the element matches
|
|
413 |
if (aLineArray->MdcaPoint(i).Left(sepPos).CompareF(aAttribute) == 0)
|
|
414 |
{
|
|
415 |
// get the value
|
|
416 |
aValue.Copy(aLineArray->MdcaPoint(i).Right(aLineArray->MdcaPoint(i).Length()-sepPos-1));
|
|
417 |
break;
|
|
418 |
}
|
|
419 |
}
|
|
420 |
}
|
|
421 |
}
|
|
422 |
|
|
423 |
void CProfiler::DoGetValueFromSettingsArray(CDesC8ArrayFlat* aLineArray, const TDesC8& aAttribute, TInt& aValue)
|
|
424 |
{
|
62
|
425 |
LOGTEXT(_L("CProfiler::DoGetValueFromSettingsFile() TLex"));
|
51
|
426 |
_LIT8(KSettingItemSeparator, "=");
|
|
427 |
|
|
428 |
// read a line of given array
|
|
429 |
for (TInt i=0; i<aLineArray->MdcaCount(); i++)
|
|
430 |
{
|
|
431 |
// check if this line has a separator
|
|
432 |
TInt sepPos = aLineArray->MdcaPoint(i).Find(KSettingItemSeparator);
|
|
433 |
if (sepPos > 0)
|
|
434 |
{
|
|
435 |
// check that the element matches
|
|
436 |
if (aLineArray->MdcaPoint(i).Left(sepPos).CompareF(aAttribute) == 0)
|
|
437 |
{
|
|
438 |
// get the value
|
|
439 |
TLex8 parser(aLineArray->MdcaPoint(i).Right(aLineArray->MdcaPoint(i).Length()-sepPos-1));
|
|
440 |
parser.Val(aValue);
|
|
441 |
break;
|
|
442 |
}
|
|
443 |
}
|
|
444 |
}
|
|
445 |
}
|
|
446 |
|
|
447 |
// --------------------------------------------------------------------------------------------
|
|
448 |
TInt CProfiler::GetSamplerAttributesL(const RMessage2& aMessage)
|
|
449 |
{
|
|
450 |
TInt err(KErrNone);
|
|
451 |
TInt pos(0);
|
|
452 |
|
|
453 |
// get sampler count
|
|
454 |
TInt count(iDefaultSamplerAttributesArray->Count());
|
|
455 |
|
|
456 |
// write each of the default sampler plugin setting attributes over client-server session
|
|
457 |
for (TInt i(0); i<count; ++i)
|
|
458 |
{
|
|
459 |
TSamplerAttributes attr = iDefaultSamplerAttributesArray->At(i);
|
|
460 |
TPckgC<TSamplerAttributes> attrPckg(attr);
|
|
461 |
|
|
462 |
// write a TSamplerAttributes container at a time
|
|
463 |
aMessage.WriteL(0, attrPckg, pos);
|
|
464 |
pos += attrPckg.Length();
|
|
465 |
}
|
|
466 |
|
|
467 |
aMessage.Complete(err);
|
|
468 |
return err;
|
|
469 |
}
|
|
470 |
|
|
471 |
// --------------------------------------------------------------------------------------------
|
|
472 |
TInt CProfiler::SetSamplerAttributesL(const RMessage2& aMessage)
|
|
473 |
{
|
|
474 |
TSamplerAttributes attr;
|
|
475 |
TPckg<TSamplerAttributes> inAttr(attr);
|
|
476 |
|
|
477 |
TInt err = aMessage.Read(0, inAttr, 0);
|
|
478 |
|
|
479 |
// apply the changes directly to a plugin
|
|
480 |
iSamplerHandler->SetSamplerSettingsL(attr.iUid, attr);
|
|
481 |
|
|
482 |
aMessage.Complete(err);
|
|
483 |
return err;
|
|
484 |
}
|
|
485 |
|
|
486 |
// --------------------------------------------------------------------------------------------
|
|
487 |
TInt CProfiler::GetGeneralAttributesL(const RMessage2& aMessage)
|
|
488 |
{
|
|
489 |
TPckgBuf<TGeneralAttributes> generalSettings( iGeneralAttributes );
|
|
490 |
|
|
491 |
// write general attributes over client-server session
|
|
492 |
TInt err = aMessage.Write(0, generalSettings);
|
|
493 |
|
|
494 |
aMessage.Complete(err);
|
|
495 |
return err;
|
|
496 |
}
|
|
497 |
|
|
498 |
// --------------------------------------------------------------------------------------------
|
|
499 |
TInt CProfiler::SetGeneralAttributesL(const RMessage2& aMessage)
|
|
500 |
{
|
|
501 |
// read the general settings from message
|
|
502 |
TGeneralAttributes attr;
|
|
503 |
TPckg<TGeneralAttributes> inPckg(attr);
|
|
504 |
TInt err = aMessage.Read(0, inPckg, 0);
|
|
505 |
|
|
506 |
// copy to the general attributes
|
|
507 |
iGeneralAttributes.iSaveFileDrive.Copy(attr.iSaveFileDrive);
|
|
508 |
iGeneralAttributes.iTraceFilePrefix.Copy(attr.iTraceFilePrefix);
|
|
509 |
iGeneralAttributes.iTraceOutput.Copy(attr.iTraceOutput);
|
|
510 |
iGeneralAttributes.iTimedSamplingPeriod = attr.iTimedSamplingPeriod;
|
|
511 |
|
|
512 |
aMessage.Complete(err);
|
|
513 |
return err;
|
|
514 |
}
|
|
515 |
|
|
516 |
TInt CProfiler::GetSamplerAttributeCountL(const RMessage2& aMessage)
|
|
517 |
{
|
|
518 |
// get the plugin array count and wrap it to TPckgBuf<>
|
|
519 |
TPckgBuf<TInt> attributeCount(iDefaultSamplerAttributesArray->Count());
|
|
520 |
|
|
521 |
// write general attributes over client-server session
|
|
522 |
TInt err = aMessage.Write(0, attributeCount);
|
|
523 |
|
|
524 |
aMessage.Complete(err);
|
|
525 |
return err;
|
|
526 |
}
|
|
527 |
|
|
528 |
TInt CProfiler::RefreshStatus(const RMessage2& aMessage)
|
|
529 |
{
|
|
530 |
TInt err(KErrNone);
|
|
531 |
|
|
532 |
// update profiler status for requester
|
|
533 |
iEngineStatus.Set(iState);
|
|
534 |
|
|
535 |
aMessage.Complete(err);
|
|
536 |
return err;
|
|
537 |
}
|
|
538 |
|
|
539 |
// --------------------------------------------------------------------------------------------
|
|
540 |
TInt CProfiler::LoadSettingsL(/*const TDesC& configFile*/)
|
|
541 |
{
|
|
542 |
RFs fileServer;
|
|
543 |
RFile file;
|
|
544 |
TInt err(KErrNone);
|
|
545 |
|
|
546 |
// connect to file server
|
|
547 |
err = fileServer.Connect();
|
|
548 |
|
|
549 |
// check if file server can be connected
|
|
550 |
if (err != KErrNone)
|
|
551 |
{
|
|
552 |
// file server couldn't be connected
|
|
553 |
return KErrGeneral;
|
|
554 |
}
|
|
555 |
|
|
556 |
// check if settings file location length reasonable
|
|
557 |
if ( iSettingsFileLocation.CompareF(KNullDesC) == 0 )
|
|
558 |
{
|
|
559 |
// open the file with the default path and name
|
|
560 |
TBuf<256> pathAndName;
|
|
561 |
pathAndName.Append(PathInfo::PhoneMemoryRootPath());
|
|
562 |
pathAndName.Append(KProfilerSettingsFileName);
|
|
563 |
iSettingsFileLocation.Copy(pathAndName);
|
|
564 |
LOGTEXT(_L("CProfiler::LoadSettings - Opening settings file with name (with the default path)"));
|
|
565 |
LOGTEXT(pathAndName);
|
|
566 |
}
|
|
567 |
|
|
568 |
// open the file with the given path and name
|
|
569 |
err = file.Open(fileServer,iSettingsFileLocation,EFileRead);
|
|
570 |
|
|
571 |
|
|
572 |
// check if RFile::Open() returned error
|
|
573 |
if (err != KErrNone)
|
|
574 |
{
|
|
575 |
// file couldn't be opened
|
|
576 |
LOGTEXT(_L("CProfiler::LoadSettings - Failed to open settings, using default"));
|
|
577 |
|
|
578 |
// check if settings already loaded
|
|
579 |
if(iDefaultSamplerAttributesArray->Count() > 0)
|
|
580 |
{
|
|
581 |
// reset default settings array
|
|
582 |
iDefaultSamplerAttributesArray->Reset();
|
|
583 |
}
|
|
584 |
|
|
585 |
// load default settings, instead of settings file ones
|
|
586 |
iSamplerHandler->GetSamplerAttributesL(iDefaultSamplerAttributesArray);
|
|
587 |
|
|
588 |
fileServer.Close();
|
|
589 |
return KErrNone;
|
|
590 |
}
|
|
591 |
|
|
592 |
// initialize iSavedLineArray, initial settings file lines 64
|
|
593 |
if(iSavedLineArray)
|
|
594 |
{
|
|
595 |
iSavedLineArray->Reset();
|
|
596 |
}
|
|
597 |
else
|
|
598 |
{
|
|
599 |
iSavedLineArray = new (ELeave) CDesC8ArrayFlat(KSavedLineCount);
|
|
600 |
}
|
|
601 |
|
|
602 |
iSavedLinesCount = KSavedLineCount;
|
|
603 |
|
|
604 |
// get size of the file
|
|
605 |
TInt fileSize(0);
|
|
606 |
err = file.Size(fileSize);
|
|
607 |
// check if an error occurred reading the file size
|
|
608 |
if(err != KErrNone)
|
|
609 |
{
|
|
610 |
return KErrGeneral; // could not find the size
|
|
611 |
}
|
|
612 |
|
|
613 |
// sanity check for the file size
|
|
614 |
if (fileSize < 3 || fileSize > 20000)
|
|
615 |
{
|
|
616 |
fileSize = KSettingsFileSize;
|
|
617 |
return KErrNotSupported;
|
|
618 |
}
|
|
619 |
|
|
620 |
// read the contents of the file to buffer.
|
|
621 |
iSettingsBuffer.Zero();
|
|
622 |
file.Read(iSettingsBuffer, fileSize);
|
|
623 |
file.Close();
|
|
624 |
fileServer.Close();
|
|
625 |
LOGSTRING2("CProfiler::LoadSettings: read %d bytes",iSettingsBuffer.Length());
|
|
626 |
|
|
627 |
// append end mark "[end]"
|
|
628 |
iSettingsBuffer.Append(KEndMark);
|
|
629 |
// force an ending newline
|
|
630 |
iSettingsBuffer.Append('\n');
|
|
631 |
|
|
632 |
// next fill the saved settings array (CDesC8ArrayFlat) for further comparison with changes and default values
|
|
633 |
TBuf8<384> tmpBuf;
|
|
634 |
TInt lineCount(0);
|
|
635 |
TBool commentFound(EFalse);
|
|
636 |
for (TInt i(0); i<iSettingsBuffer.Length(); i++) // loop all chars
|
|
637 |
{
|
|
638 |
// if new line char found, create a new text line
|
|
639 |
if (iSettingsBuffer[i]=='\r' || iSettingsBuffer[i]=='\n')
|
|
640 |
{
|
|
641 |
// check if collected string has reasonable length
|
|
642 |
if (tmpBuf.Length() > 0)
|
|
643 |
{
|
|
644 |
// remove extra spaces
|
|
645 |
tmpBuf.TrimAll();
|
|
646 |
// check if the size of the array too small
|
|
647 |
if(lineCount >= iSavedLinesCount)
|
|
648 |
{
|
|
649 |
iSavedLineArray->ExpandL(20); // expand by 20 lines
|
|
650 |
iSavedLinesCount += 20;
|
|
651 |
}
|
|
652 |
iSavedLineArray->AppendL(tmpBuf);
|
|
653 |
tmpBuf.Copy(KNullDesC8);
|
|
654 |
lineCount++;
|
|
655 |
}
|
|
656 |
commentFound = EFalse;
|
|
657 |
}
|
|
658 |
// check if comment mark ';' is found on the line, skip the rest of the line
|
|
659 |
else if(iSettingsBuffer[i]==';')
|
|
660 |
{
|
|
661 |
commentFound = ETrue;
|
|
662 |
}
|
|
663 |
// otherwise append a char to the temp line buffer if it is a wanted ASCII char
|
|
664 |
else if (iSettingsBuffer[i]>=32 && iSettingsBuffer[i]<=127 && !commentFound)
|
|
665 |
{
|
|
666 |
tmpBuf.Append(iSettingsBuffer[i]);
|
|
667 |
}
|
|
668 |
}
|
|
669 |
|
|
670 |
// empty tmpBuf
|
|
671 |
tmpBuf.Copy(KNullDesC8);
|
|
672 |
// check settings file version
|
|
673 |
DoGetValueFromSettingsArray(iSavedLineArray, KProfilerVersionTag, tmpBuf);
|
|
674 |
|
|
675 |
TBuf8<32> version;
|
|
676 |
version.Copy(PROFILER_VERSION_SHORT);
|
|
677 |
|
|
678 |
// check if settings file version is
|
|
679 |
if(tmpBuf.CompareF(version) >= 0)
|
|
680 |
{
|
|
681 |
// update general attributes
|
|
682 |
UpdateSavedGeneralAttributes(iSavedLineArray);
|
|
683 |
|
|
684 |
// update settings to sampler plugins and save the attributes to default array
|
|
685 |
iSamplerHandler->UpdateSavedSamplerAttributesL(iSavedLineArray, iDefaultSamplerAttributesArray);
|
|
686 |
}
|
|
687 |
else
|
|
688 |
{
|
|
689 |
// check if settings already loaded
|
|
690 |
if(iDefaultSamplerAttributesArray)
|
|
691 |
{
|
|
692 |
// reset default settings array
|
|
693 |
iDefaultSamplerAttributesArray->Reset();
|
|
694 |
|
|
695 |
// get the default settings if settings file version too old
|
|
696 |
iSamplerHandler->GetSamplerAttributesL(iDefaultSamplerAttributesArray);
|
|
697 |
}
|
|
698 |
}
|
|
699 |
|
|
700 |
return err;
|
|
701 |
}
|
|
702 |
|
|
703 |
// --------------------------------------------------------------------------------------------
|
|
704 |
void CProfiler::UpdateSavedGeneralAttributes(CDesC8ArrayFlat* aSavedAttributes)
|
|
705 |
{
|
|
706 |
// get saved general settings
|
62
|
707 |
LOGSTRING("CProfiler::UpdateSavedGeneralAttributes");
|
51
|
708 |
DoGetValueFromSettingsArray(aSavedAttributes, KGenericTraceOutput, iGeneralAttributes.iTraceOutput);
|
|
709 |
DoGetValueFromSettingsArray(aSavedAttributes, KGenericTraceFilePrefix, iGeneralAttributes.iTraceFilePrefix);
|
|
710 |
DoGetValueFromSettingsArray(aSavedAttributes, KGenericTraceFileSaveDrive, iGeneralAttributes.iSaveFileDrive);
|
|
711 |
DoGetValueFromSettingsArray(aSavedAttributes, KGenericTimedProfilingPeriod, iGeneralAttributes.iTimedSamplingPeriod);
|
|
712 |
}
|
|
713 |
|
|
714 |
TBool CProfiler::CheckLocationSanity(RFs& fs, const TDesC8& aLocation)
|
|
715 |
{
|
|
716 |
TBool ret(EFalse);
|
|
717 |
TBool noDiskSpace(EFalse);
|
|
718 |
TBuf<32> drive;
|
|
719 |
|
|
720 |
CnvUtfConverter::ConvertToUnicodeFromUtf8(drive, aLocation);
|
|
721 |
TDriveUnit driveUnit = TDriveUnit(drive);
|
|
722 |
|
|
723 |
// check that the root folder is correct
|
|
724 |
if (drive.Length() > 2 && BaflUtils::CheckFolder(fs, drive.Left(3)) == KErrNone)
|
|
725 |
{
|
|
726 |
// test available disk space
|
|
727 |
TRAP_IGNORE((noDiskSpace = SysUtil::DiskSpaceBelowCriticalLevelL(&fs, 0, driveUnit)));
|
|
728 |
if(!noDiskSpace)
|
|
729 |
ret = ETrue;
|
|
730 |
}
|
|
731 |
|
|
732 |
return ret;
|
|
733 |
}
|
|
734 |
|
|
735 |
TInt CProfiler::HandleGeneralSettingsChange()
|
|
736 |
{
|
|
737 |
// local literals
|
|
738 |
_LIT8(KBackSlash, "\\");
|
|
739 |
_LIT8(KTraceFileExtension, ".dat");
|
|
740 |
|
|
741 |
TBuf8<KFileNameBufSize> fileNameBuf;
|
|
742 |
TBuf8<10> number;
|
|
743 |
TInt result(0);
|
|
744 |
TInt index(1);
|
|
745 |
TInt hashLocation(0);
|
|
746 |
TParse parse;
|
|
747 |
|
|
748 |
// check if plugin writer changed
|
|
749 |
if(iGeneralAttributes.iTraceOutput.CompareF(KOutputToDebugOutput) == 0)
|
|
750 |
{
|
|
751 |
iWriterHandler->SetPluginActive( KDebOutWriterPluginUid, EWriterPluginEnabled );
|
|
752 |
}
|
|
753 |
else
|
|
754 |
{
|
|
755 |
RFs fileServer;
|
|
756 |
RFile file;
|
|
757 |
|
|
758 |
// connect to the file server
|
|
759 |
result = fileServer.Connect();
|
|
760 |
if(result == KErrNone)
|
|
761 |
{
|
|
762 |
// disk writer plugin will be activated
|
|
763 |
iWriterHandler->SetPluginActive( KDiskWriterPluginUid, EWriterPluginEnabled );
|
|
764 |
|
|
765 |
// fix the trace data file location as well
|
|
766 |
iTotalPrefix.Zero();
|
|
767 |
iTotalPrefix.Append(iGeneralAttributes.iSaveFileDrive);
|
|
768 |
|
|
769 |
// check that trace file location sane
|
|
770 |
if(!CProfiler::CheckLocationSanity(fileServer, iTotalPrefix))
|
|
771 |
{
|
|
772 |
fileServer.Close();
|
|
773 |
return KErrPathNotFound;
|
|
774 |
}
|
|
775 |
|
|
776 |
// remove extra spaces
|
|
777 |
iTotalPrefix.TrimAll();
|
|
778 |
|
|
779 |
// check the directory contains a trailing backlash
|
|
780 |
if(iTotalPrefix.Right(1) != _L8("\\") &&
|
|
781 |
iTotalPrefix.Right(1) != _L8("/"))
|
|
782 |
{
|
|
783 |
// append backslash to end
|
|
784 |
iTotalPrefix.Append(KBackSlash);
|
|
785 |
}
|
|
786 |
|
|
787 |
// append trace file name prefix e.g. PIProfiler_#
|
|
788 |
iTotalPrefix.Append(iGeneralAttributes.iTraceFilePrefix);
|
|
789 |
|
|
790 |
// locate '#' mark for finding the next free trace file name, e.g. E:\data\PIProfiler_4.dat
|
|
791 |
hashLocation = iTotalPrefix.Locate('#');
|
|
792 |
if( hashLocation == KErrNotFound )
|
|
793 |
{
|
|
794 |
// append simply at the end of the trace file prefix, no need to inform user
|
|
795 |
iTotalPrefix.Append('#');
|
|
796 |
// get new hash mark location
|
|
797 |
hashLocation = iTotalPrefix.Locate('#');
|
|
798 |
}
|
|
799 |
|
|
800 |
// add the file extension
|
|
801 |
iTotalPrefix.Append(KTraceFileExtension);
|
|
802 |
|
|
803 |
// search for files with different indices
|
|
804 |
// until a free filename is found
|
|
805 |
while(result != KErrNotFound)
|
|
806 |
{
|
|
807 |
fileNameBuf.Zero();
|
|
808 |
// start with the original prefix
|
|
809 |
fileNameBuf.Append(iTotalPrefix);
|
|
810 |
// convert the number to a descriptor
|
|
811 |
number.Num(index);
|
|
812 |
// replace the hashmark with the real number
|
|
813 |
fileNameBuf.Replace(hashLocation,1,number);
|
|
814 |
|
|
815 |
// make a copy to the iFileNameStream descriptor
|
|
816 |
iFileNameStream.Zero();
|
|
817 |
CnvUtfConverter::ConvertToUnicodeFromUtf8(iFileNameStream, fileNameBuf);
|
|
818 |
|
|
819 |
LOGSTRING2("CProfiler::HandleGeneralSettingsChange() - trying to open files %S ",&iFileNameStream);
|
|
820 |
|
|
821 |
if((result = parse.Set(iFileNameStream, NULL, NULL)) != KErrNone)
|
|
822 |
{
|
|
823 |
// break loop if fails, problems in file name => change to log into debug output
|
|
824 |
break;
|
|
825 |
}
|
|
826 |
|
|
827 |
// create directory for trace files if not exists
|
|
828 |
result = fileServer.MkDirAll(parse.FullName());
|
|
829 |
|
|
830 |
// check that file server responded with KErrNone or KErrAlreadyExists
|
|
831 |
if( result != KErrNone && result != KErrAlreadyExists)
|
|
832 |
{
|
|
833 |
// if some other result, e.g. memory full => break
|
|
834 |
break;
|
|
835 |
}
|
|
836 |
|
|
837 |
// attempt opening the file
|
|
838 |
result = file.Open(fileServer,parse.FullName(),EFileShareReadersOnly);
|
|
839 |
if(result != KErrNotFound)
|
|
840 |
{
|
|
841 |
if( result != KErrNotReady &&
|
|
842 |
result != KErrServerBusy )
|
|
843 |
{
|
|
844 |
// close the file if it could be opened
|
|
845 |
LOGSTRING2("Found STREAM file with index %d",index);
|
|
846 |
index++;
|
|
847 |
}
|
|
848 |
else
|
|
849 |
{
|
|
850 |
// in boot measurements the file system might not be ready yet.
|
|
851 |
LOGSTRING2("Problem in opening STREAM file %d",index);
|
|
852 |
}
|
|
853 |
file.Close();
|
|
854 |
}
|
|
855 |
} // while
|
|
856 |
}
|
|
857 |
else
|
|
858 |
{
|
|
859 |
// return error code
|
|
860 |
return result;
|
|
861 |
}
|
|
862 |
|
|
863 |
TUint32 id(iWriterHandler->GetActiveWriter()->GetWriterType());
|
|
864 |
|
|
865 |
// check if a file name is one that does not exist and selected plugin is disk writer
|
|
866 |
if(result == KErrNotFound && id == KDiskWriterPluginUid.iUid)
|
|
867 |
{
|
|
868 |
// write right trace data file name to disk writer plugin
|
|
869 |
iWriterHandler->SetPluginSettings( KDiskWriterPluginUid, iFileNameStream );
|
|
870 |
}
|
|
871 |
else
|
|
872 |
{
|
|
873 |
// return error if could not create trace log file
|
|
874 |
return result;
|
|
875 |
}
|
|
876 |
// close file server
|
|
877 |
fileServer.Close();
|
|
878 |
} // if output == KOutputToDebugOutput
|
|
879 |
return KErrNone;
|
|
880 |
}
|
|
881 |
|
|
882 |
// --------------------------------------------------------------------------------------------
|
|
883 |
void CProfiler::HandleTimerExpiresL(TInt aError)
|
|
884 |
{
|
|
885 |
LOGSTRING2("CProfiler::HandleTimerExpiresL - Error: %d", aError);
|
|
886 |
this->ControlL(RProfiler::EStopSampling);
|
|
887 |
if( CPServer::iClientCount <= 0 )
|
|
888 |
{
|
|
889 |
LOGSTRING("CProfiler::HandleTimerExpiresL - No clients attached, shutting down server...");
|
|
890 |
this->ControlL(RProfiler::EExitProfiler);
|
|
891 |
}
|
|
892 |
}
|
|
893 |
|
|
894 |
// --------------------------------------------------------------------------------------------
|
|
895 |
void CProfiler::SaveSettingsL()
|
|
896 |
{
|
|
897 |
LOGTEXT(_L("CProfiler::SaveSettings()"));
|
|
898 |
|
|
899 |
// local literal
|
|
900 |
_LIT(KGeneralHeader, "[general]");
|
|
901 |
_LIT(KVersionHeader, "version");
|
|
902 |
_LIT8(KPIProfilerSettingsHeader, "; PI Profiler Settings File");
|
|
903 |
_LIT8(KGeneralSettingsHeader, "; general settings");
|
|
904 |
_LIT8(KOutputFileDescription,"; \"output_type=file_system\" writes *.dat file to external memory");
|
|
905 |
_LIT8(KOutputDebugDescription,"; \"output_type=debug_output\" writes *.dat file to debug port");
|
|
906 |
_LIT8(KOutputFilePrefixDescription,"; if writing to file, prefix of the *.dat file\r\n; first '#' in the prefix is replaced with an integer");
|
|
907 |
_LIT8(KOutputSaveDriveDescription,"; if writing to file, the location to store the *.dat file");
|
|
908 |
_LIT8(KTimedProfilingPeriod,"; period (in seconds) used when using timed profiling");
|
|
909 |
|
|
910 |
RFs fs;
|
|
911 |
RFile settingsFile;
|
|
912 |
TInt err(KErrNone);
|
|
913 |
TBuf8<384> line;
|
|
914 |
|
|
915 |
// connect to file server
|
|
916 |
err = fs.Connect();
|
|
917 |
if( err != KErrNone )
|
62
|
918 |
{
|
51
|
919 |
// failed to write settings to settings file
|
62
|
920 |
RDebug::Printf("FS connect failed");
|
51
|
921 |
return;
|
62
|
922 |
}
|
51
|
923 |
|
|
924 |
// create and set the private path
|
|
925 |
fs.CreatePrivatePath(EDriveC);
|
|
926 |
fs.SetSessionToPrivate(EDriveC);
|
|
927 |
|
|
928 |
// create the new settings file
|
|
929 |
err = settingsFile.Replace(fs, iSettingsFileLocation, EFileWrite);
|
|
930 |
if(err != KErrNone)
|
62
|
931 |
{
|
|
932 |
RDebug::Printf("Settingsfile replace failed");
|
|
933 |
fs.Close();
|
|
934 |
return;
|
|
935 |
}
|
51
|
936 |
|
|
937 |
// write the header
|
|
938 |
line.Copy(KPIProfilerSettingsHeader);
|
|
939 |
line.Append(KNewLineSeparator);
|
|
940 |
line.Append(KNewLineSeparator);
|
|
941 |
settingsFile.Write(line);
|
|
942 |
|
|
943 |
// write the header
|
|
944 |
line.Copy(KGeneralSettingsHeader);
|
|
945 |
line.Append(KNewLineSeparator);
|
|
946 |
settingsFile.Write(line);
|
|
947 |
|
|
948 |
// write all generic settings
|
|
949 |
line.Copy(KGeneralHeader);
|
|
950 |
line.Append(KNewLineSeparator);
|
|
951 |
settingsFile.Write(line);
|
|
952 |
|
|
953 |
// write version info
|
|
954 |
line.Copy(KVersionHeader);
|
|
955 |
line.Append(KEquals);
|
|
956 |
line.Append(PROFILER_VERSION_SHORT);
|
|
957 |
line.Append(KNewLineSeparator);
|
|
958 |
settingsFile.Write(line);
|
|
959 |
|
|
960 |
// output explanation
|
|
961 |
line.Copy(KOutputFileDescription);
|
|
962 |
line.Append(KNewLineSeparator);
|
|
963 |
line.Append(KOutputDebugDescription);
|
|
964 |
line.Append(KNewLineSeparator);
|
|
965 |
settingsFile.Write(line);
|
|
966 |
|
|
967 |
// write trace output
|
|
968 |
line.Copy(KGenericTraceOutput);
|
|
969 |
line.Append(KEquals);
|
|
970 |
line.Append(iGeneralAttributes.iTraceOutput);
|
|
971 |
line.Append(KNewLineSeparator);
|
|
972 |
settingsFile.Write(line);
|
|
973 |
|
|
974 |
// file prefix explanation
|
|
975 |
line.Copy(KOutputFilePrefixDescription);
|
|
976 |
line.Append(KNewLineSeparator);
|
|
977 |
settingsFile.Write(line);
|
|
978 |
|
|
979 |
// write trace file prefix
|
|
980 |
line.Copy(KGenericTraceFilePrefix);
|
|
981 |
line.Append(KEquals);
|
|
982 |
line.Append(iGeneralAttributes.iTraceFilePrefix);
|
|
983 |
line.Append(KNewLineSeparator);
|
|
984 |
settingsFile.Write(line);
|
|
985 |
|
|
986 |
// file prefix explanation
|
|
987 |
line.Copy(KOutputSaveDriveDescription);
|
|
988 |
line.Append(KNewLineSeparator);
|
|
989 |
settingsFile.Write(line);
|
|
990 |
|
|
991 |
// write trace file location
|
|
992 |
line.Copy(KGenericTraceFileSaveDrive);
|
|
993 |
line.Append(KEquals);
|
|
994 |
line.Append(iGeneralAttributes.iSaveFileDrive);
|
|
995 |
line.Append(KNewLineSeparator);
|
|
996 |
settingsFile.Write(line);
|
|
997 |
|
|
998 |
// timed profiling period explanation
|
|
999 |
line.Copy(KTimedProfilingPeriod);
|
|
1000 |
line.Append(KNewLineSeparator);
|
|
1001 |
settingsFile.Write(line);
|
|
1002 |
|
|
1003 |
// Write timed profiling period value
|
|
1004 |
line.Copy(KGenericTimedProfilingPeriod);
|
|
1005 |
line.Append(KEquals);
|
|
1006 |
TBuf<16> tmpNum;
|
|
1007 |
tmpNum.AppendNum(iGeneralAttributes.iTimedSamplingPeriod);
|
|
1008 |
line.Append(tmpNum);
|
|
1009 |
line.Append(KNewLineSeparator);
|
|
1010 |
settingsFile.Write(line);
|
|
1011 |
|
|
1012 |
// reset the default attributes array
|
|
1013 |
iDefaultSamplerAttributesArray->Reset();
|
|
1014 |
|
|
1015 |
// update the latest changes from plugins
|
|
1016 |
iSamplerHandler->GetSamplerAttributesL(iDefaultSamplerAttributesArray);
|
|
1017 |
|
|
1018 |
// call CSamplerController to write all sampler settings
|
|
1019 |
iSamplerHandler->ComposeAttributesToSettingsFileFormat(settingsFile, iDefaultSamplerAttributesArray);
|
|
1020 |
|
62
|
1021 |
settingsFile.Close();
|
51
|
1022 |
// close file
|
|
1023 |
fs.Close();
|
|
1024 |
}
|
|
1025 |
|
|
1026 |
TInt CProfiler::CheckOldProfilerRunning()
|
|
1027 |
{
|
|
1028 |
TFindProcess procName;
|
|
1029 |
procName.Find(_L("BappeaProf.exe*"));
|
|
1030 |
TFullName aResult;
|
|
1031 |
TInt err(KErrNone);
|
|
1032 |
RProcess proc;
|
|
1033 |
|
|
1034 |
// now check if old Profiler is still running on
|
|
1035 |
err = procName.Next(aResult);
|
|
1036 |
// check if old profiler process found
|
|
1037 |
if(err == KErrNone)
|
|
1038 |
{
|
|
1039 |
// other process found, i.e. right process to communicate with, in case started from eshell
|
|
1040 |
err = proc.Open(procName);
|
|
1041 |
if(err == KErrNone)
|
|
1042 |
{
|
|
1043 |
if(proc.ExitCategory().Length() > 0)
|
|
1044 |
{
|
|
1045 |
proc.Close();
|
|
1046 |
// process already exited => create a new one
|
|
1047 |
return KErrNotFound;
|
|
1048 |
}
|
|
1049 |
proc.Close();
|
|
1050 |
}
|
|
1051 |
// return error for error handling
|
|
1052 |
return KErrAlreadyExists;
|
|
1053 |
}
|
|
1054 |
return err;
|
|
1055 |
}
|
|
1056 |
|
|
1057 |
// --------------------------------------------------------------------------------------------
|
|
1058 |
void CProfiler::HandleError(TInt aErr)
|
|
1059 |
{
|
|
1060 |
// write error to status property to inform requester
|
|
1061 |
TInt err(iEngineStatus.Set(KEngineStatusPropertyCat, EProfilerEngineStatus, aErr));
|
|
1062 |
if(err != KErrNone)
|
|
1063 |
RDebug::Print(_L("CProfiler::HandleError() - error setting status: %d"), err);
|
|
1064 |
}
|
|
1065 |
|
|
1066 |
// --------------------------------------------------------------------------------------------
|
|
1067 |
TInt CProfiler::ControlDataL(TInt aCommand,TAny* value1,TAny* /*value2*/)
|
|
1068 |
{
|
|
1069 |
LOGSTRING3("CProfiler::ControlData %d, 0x%x",aCommand,value1);
|
|
1070 |
|
|
1071 |
_LIT(KDebugOutput, "debug_output");
|
|
1072 |
_LIT(KFileOutput, "file_system");
|
|
1073 |
_LIT8(KOutputToDebugOutput, "debug_output");
|
|
1074 |
|
|
1075 |
TDes* desc;
|
|
1076 |
TPtrC ptrDesc;
|
|
1077 |
|
|
1078 |
switch(aCommand)
|
|
1079 |
{
|
|
1080 |
// new controls
|
|
1081 |
case RProfiler::EGetFileName:
|
|
1082 |
{
|
|
1083 |
LOGTEXT(_L("Profiler::EGetFileName - start"));
|
|
1084 |
LOGSTRING2("Profiler::EGetFileName - total file name is: %S",(TDes*)value1);
|
|
1085 |
desc = (TDes*)value1;
|
|
1086 |
desc->Zero();
|
|
1087 |
desc->Append(iFileNameStream);
|
|
1088 |
LOGSTRING2("Profiler::EGetFileName - now total file name is: %S",(TDes*)value1);
|
|
1089 |
return KErrNone;
|
|
1090 |
}
|
|
1091 |
case RProfiler::EGetActiveWriter:
|
|
1092 |
{
|
|
1093 |
LOGTEXT(_L("Profiler::EGetActiveWriter - start"));
|
|
1094 |
desc = (TDes*)value1;
|
|
1095 |
desc->Zero();
|
|
1096 |
if(iGeneralAttributes.iTraceOutput.CompareF(KOutputToDebugOutput) == 0)
|
|
1097 |
{
|
|
1098 |
desc->Append(KDebugOutput);
|
|
1099 |
}
|
|
1100 |
else
|
|
1101 |
{
|
|
1102 |
desc->Append(KFileOutput);
|
|
1103 |
}
|
|
1104 |
return KErrNone;
|
|
1105 |
}
|
|
1106 |
}
|
|
1107 |
|
|
1108 |
return KErrNone;
|
|
1109 |
}
|
|
1110 |
|
|
1111 |
// --------------------------------------------------------------------------------------------
|
|
1112 |
TInt CProfiler::ControlL(TInt aCommand)
|
|
1113 |
{
|
|
1114 |
LOGSTRING2("CProfiler::Control - Controlling ProfilerEngine %d",aCommand);
|
|
1115 |
TInt err(KErrNone);
|
|
1116 |
|
|
1117 |
switch (aCommand)
|
|
1118 |
{
|
|
1119 |
case RProfiler::EStartSampling:
|
|
1120 |
case RProfiler::EStartTimedSampling:
|
|
1121 |
{
|
|
1122 |
// check first if old Profiler already running
|
|
1123 |
err = CheckOldProfilerRunning();
|
|
1124 |
if(err == KErrAlreadyExists)
|
|
1125 |
{
|
|
1126 |
// if exists do not start a profiling process since corrupts the collected trace data
|
|
1127 |
HandleError(err);
|
|
1128 |
err = KErrNone;
|
|
1129 |
return err;
|
|
1130 |
}
|
|
1131 |
|
|
1132 |
// save settings before launching the profiler
|
|
1133 |
// reason: the profiling may have set to the background => need for get right settings
|
|
1134 |
SaveSettingsL();
|
|
1135 |
|
|
1136 |
// set the general settings to writer plugins to reflect the latest changes
|
|
1137 |
err = HandleGeneralSettingsChange();
|
|
1138 |
if(err == KErrNone)
|
|
1139 |
{
|
|
1140 |
// reset the buffers before new profiling
|
|
1141 |
iUserStream->ResetBuffers();
|
|
1142 |
|
|
1143 |
// give the CProfilerSampleStream a handle to current writer
|
|
1144 |
iUserStream->SetWriter(*iWriterHandler->GetActiveWriter());
|
|
1145 |
|
|
1146 |
// set initially debug output writer active
|
|
1147 |
err = iWriterHandler->StartSelectedPlugin();
|
|
1148 |
|
|
1149 |
// check that writer plugin started
|
|
1150 |
if(err != KErrNone)
|
|
1151 |
{
|
|
1152 |
// if not started handle error
|
|
1153 |
HandleError(err);
|
|
1154 |
}
|
|
1155 |
else
|
|
1156 |
{
|
|
1157 |
// start activated sampler plug-in, NOTE: plugins check if errors occur in startup for some reason
|
|
1158 |
iSamplerHandler->StartSamplerPluginsL();
|
|
1159 |
|
|
1160 |
// set engine state P&S property to running, e.g. for PIProfiler UI to read
|
|
1161 |
iState = RProfiler::ERunning;
|
|
1162 |
|
|
1163 |
// set the engine into running mode
|
|
1164 |
iEngineStatus.Set(iState);
|
|
1165 |
}
|
|
1166 |
}
|
|
1167 |
else
|
|
1168 |
{
|
|
1169 |
// handle error and notify requester
|
|
1170 |
HandleError(err);
|
|
1171 |
}
|
|
1172 |
|
|
1173 |
if( aCommand == RProfiler::EStartTimedSampling )
|
|
1174 |
{
|
|
1175 |
iTimer->After(iGeneralAttributes.iTimedSamplingPeriod);
|
|
1176 |
LOGTEXT(_L("CProfiler::Control - Finished processing EStartTimedSampling!"));
|
|
1177 |
}
|
|
1178 |
else
|
|
1179 |
{
|
|
1180 |
LOGTEXT(_L("CProfiler::Control - Finished processing EStartSampling!"));
|
|
1181 |
}
|
|
1182 |
|
|
1183 |
return err;
|
|
1184 |
}
|
|
1185 |
case RProfiler::EStopSampling:
|
|
1186 |
LOGTEXT(_L("CProfiler::Control - Starting to stop sampling..."));
|
|
1187 |
// stop sampler plugins
|
|
1188 |
if(iState == RProfiler::ERunning)
|
|
1189 |
{
|
|
1190 |
iState = RProfiler::EStopping;
|
|
1191 |
iEngineStatus.Set(RProfiler::EStopping);
|
|
1192 |
|
|
1193 |
iSamplerHandler->StopSamplerPlugins();
|
|
1194 |
|
|
1195 |
// finalize the filled buffer writing
|
|
1196 |
iUserStream->Finalise();
|
|
1197 |
|
|
1198 |
// stop output plugin and write the rest of the trace data to output
|
|
1199 |
LOGTEXT(_L("CProfiler::Control - stopping writer"));
|
|
1200 |
iWriterHandler->StopSelectedPlugin();
|
|
1201 |
|
|
1202 |
// set engine state P&S property idle
|
|
1203 |
iState = RProfiler::EIdle;
|
|
1204 |
iEngineStatus.Set(RProfiler::EIdle);
|
|
1205 |
|
|
1206 |
LOGSTRING2("CProfiler::Control - sampling stopped, going to state %d", RProfiler::EIdle);
|
|
1207 |
}
|
|
1208 |
return KErrNone;
|
|
1209 |
|
|
1210 |
case RProfiler::EExitProfiler:
|
|
1211 |
{
|
|
1212 |
// save settings into settings file when exiting
|
|
1213 |
SaveSettingsL();
|
|
1214 |
|
|
1215 |
if(iUserStream)
|
|
1216 |
{
|
|
1217 |
delete iUserStream;
|
|
1218 |
iUserStream = NULL;
|
|
1219 |
}
|
|
1220 |
|
|
1221 |
// set engine state P&S property idle
|
|
1222 |
iState = RProfiler::EIdle;
|
|
1223 |
iEngineStatus.Set(RProfiler::EIdle);
|
|
1224 |
|
|
1225 |
LOGTEXT(_L("Stopping Activer Scheduler"));
|
|
1226 |
CActiveScheduler::Stop();
|
|
1227 |
LOGTEXT(_L("Stopped Activer Scheduler"));
|
|
1228 |
|
|
1229 |
return KErrNone;
|
|
1230 |
}
|
|
1231 |
|
|
1232 |
case RProfiler::EAttachClient:
|
|
1233 |
{
|
|
1234 |
// Increase client reference count
|
|
1235 |
++CPServer::iClientCount;
|
|
1236 |
LOGSTRING2("Increased client reference count to: %d", CPServer::iClientCount);
|
|
1237 |
return KErrNone;
|
|
1238 |
}
|
|
1239 |
case RProfiler::ERemoveClient:
|
|
1240 |
{
|
|
1241 |
// Decrease client reference count
|
|
1242 |
--CPServer::iClientCount;
|
|
1243 |
LOGSTRING2("Decreasing client reference count to: %d", CPServer::iClientCount);
|
|
1244 |
return KErrNone;
|
|
1245 |
}
|
|
1246 |
}
|
|
1247 |
|
|
1248 |
LOGTEXT(_L("CProfiler::Control - returning"));
|
|
1249 |
|
|
1250 |
return err;
|
|
1251 |
}
|
|
1252 |
|
|
1253 |
// --------------------------------------------------------------------------------------------
|
|
1254 |
void CProfiler::Finalise()
|
|
1255 |
{
|
|
1256 |
LOGTEXT(_L("CProfiler::Finalise - Finished processing EStopSampling!"));
|
|
1257 |
}
|
|
1258 |
|
|
1259 |
// --------------------------------------------------------------------------------------------
|
|
1260 |
RProfiler::TSamplerState CProfiler::State() const
|
|
1261 |
{
|
|
1262 |
return iState;
|
|
1263 |
}
|
|
1264 |
|
|
1265 |
/*
|
|
1266 |
*
|
|
1267 |
* Class CPServer definition
|
|
1268 |
*
|
|
1269 |
*/
|
|
1270 |
// --------------------------------------------------------------------------------------------
|
|
1271 |
inline const CPServer& CPSession::Server() const
|
|
1272 |
{
|
|
1273 |
return *static_cast<const CPServer*>(CSession2::Server());
|
|
1274 |
}
|
|
1275 |
|
|
1276 |
// --------------------------------------------------------------------------------------------
|
|
1277 |
void CPSession::ServiceL(const RMessage2& aMessage)
|
|
1278 |
{
|
|
1279 |
LOGTEXT(_L("CPSession::ServiceL - Starting to process message"));
|
|
1280 |
TInt err(KErrNone);
|
|
1281 |
|
|
1282 |
if(aMessage.Function() == RProfiler::EGetGeneralAttributes)
|
|
1283 |
{
|
|
1284 |
Server().GetGeneralAttributesL(aMessage);
|
|
1285 |
}
|
|
1286 |
else if(aMessage.Function() == RProfiler::ESetGeneralAttributes)
|
|
1287 |
{
|
|
1288 |
Server().SetGeneralAttributesL(aMessage);
|
|
1289 |
}
|
|
1290 |
else if(aMessage.Function() == RProfiler::EGetSamplerAttributes)
|
|
1291 |
{
|
|
1292 |
Server().GetSamplerAttributesL(aMessage);
|
|
1293 |
}
|
|
1294 |
else if(aMessage.Function() == RProfiler::EGetSamplerAttributeCount)
|
|
1295 |
{
|
|
1296 |
Server().GetSamplerAttributeCountL(aMessage);
|
|
1297 |
}
|
|
1298 |
else if(aMessage.Function() == RProfiler::ESetSamplerAttributes)
|
|
1299 |
{
|
|
1300 |
Server().SetSamplerAttributesL(aMessage);
|
|
1301 |
}
|
|
1302 |
else if(aMessage.Function() == RProfiler::ERefreshProfilerStatus)
|
|
1303 |
{
|
|
1304 |
Server().RefreshStatus(aMessage);
|
|
1305 |
}
|
|
1306 |
else if(aMessage.Ptr0() == 0 && aMessage.Ptr1() == 0 && aMessage.Ptr2() == 0)
|
|
1307 |
{
|
|
1308 |
LOGTEXT(_L("Ptr0 && Ptr1 == 0 && Ptr2 == 0"));
|
|
1309 |
aMessage.Complete(Server().ControlL(RProfiler::TCommand(aMessage.Function())));
|
|
1310 |
LOGTEXT(_L("CPSession::ServiceL - Message completed"));
|
|
1311 |
}
|
|
1312 |
else if(aMessage.Ptr0() != 0 && aMessage.Ptr1() != 0 && aMessage.Ptr2() != 0)
|
|
1313 |
{
|
|
1314 |
LOGTEXT(_L("Error with message, all pointers contain data!"));
|
|
1315 |
}
|
|
1316 |
|
|
1317 |
else if (aMessage.Ptr0() != 0)
|
|
1318 |
{
|
|
1319 |
if(aMessage.Ptr1() == 0)
|
|
1320 |
{
|
|
1321 |
LOGTEXT(_L("ServiceL: Ptr0 != 0 && Ptr1 == 0"));
|
|
1322 |
// provided value is a descriptor
|
|
1323 |
TBuf<64>* dst = new TBuf<64>;
|
|
1324 |
aMessage.ReadL(0,*dst,0);
|
|
1325 |
|
|
1326 |
err = Server().ControlDataL(aMessage.Function(),(TAny*)dst);
|
|
1327 |
delete dst;
|
|
1328 |
aMessage.Complete(err);
|
|
1329 |
LOGTEXT(_L("CPSession::ServiceL - Message completed"));
|
|
1330 |
}
|
|
1331 |
else
|
|
1332 |
{
|
|
1333 |
LOGTEXT(_L("ServiceL: Ptr0 != 0 && Ptr1 != 0"));
|
|
1334 |
// provided value is a descriptor
|
|
1335 |
TBuf<64>* dst = new TBuf<64>;
|
|
1336 |
aMessage.ReadL(0,*dst,0);
|
|
1337 |
|
|
1338 |
TUint32 num1 = (TUint32)aMessage.Ptr1();
|
|
1339 |
|
|
1340 |
err = Server().ControlDataL(aMessage.Function(),(TAny*)dst, (TAny*)num1);
|
|
1341 |
delete dst;
|
|
1342 |
aMessage.Complete(err);
|
|
1343 |
LOGTEXT(_L("CPSession::ServiceL - Message completed"));
|
|
1344 |
}
|
|
1345 |
}
|
|
1346 |
else if (aMessage.Ptr1() != 0)
|
|
1347 |
{
|
|
1348 |
LOGTEXT(_L("ServiceL: Ptr1 != 0"));
|
|
1349 |
// provided value is a TUint32
|
|
1350 |
if( ((TUint32)aMessage.Ptr3()) == 0xffffffff)
|
|
1351 |
{
|
|
1352 |
TUint32 num = (TUint32)aMessage.Ptr1();
|
|
1353 |
err = Server().ControlDataL(aMessage.Function(),(TAny*)num);
|
|
1354 |
aMessage.Complete(err);
|
|
1355 |
LOGTEXT(_L("CPSession::ServiceL - Message completed"));
|
|
1356 |
}
|
|
1357 |
else
|
|
1358 |
{
|
|
1359 |
LOGTEXT(_L("ServiceL: Ptr3 != 0xffffffff"));
|
|
1360 |
TUint32 num1 = (TUint32)aMessage.Ptr1();
|
|
1361 |
TUint32 num2 = (TUint32)aMessage.Ptr3();
|
|
1362 |
err = Server().ControlDataL(aMessage.Function(),(TAny*)num1,(TAny*)num2);
|
|
1363 |
aMessage.Complete(err);
|
|
1364 |
LOGTEXT(_L("CPSession::ServiceL - Message completed"));
|
|
1365 |
}
|
|
1366 |
}
|
|
1367 |
else if (aMessage.Ptr2() != 0)
|
|
1368 |
{
|
|
1369 |
// command requests for data, provided
|
|
1370 |
// value should be a descriptor
|
|
1371 |
if( ((TUint32)aMessage.Ptr3()) == 0xffffffff)
|
|
1372 |
{
|
|
1373 |
LOGTEXT(_L("ServiceL: Ptr2 != 0 && Ptr3 == 0xffffffff"));
|
|
1374 |
|
|
1375 |
TBuf<256>* src = new TBuf<256>;
|
|
1376 |
src->Zero();
|
|
1377 |
err = Server().ControlDataL(aMessage.Function(),(TAny*)src);
|
|
1378 |
|
|
1379 |
LOGSTRING2("Got sampler data %S",src);
|
|
1380 |
|
|
1381 |
aMessage.WriteL(2, *src, 0);
|
|
1382 |
|
|
1383 |
delete src;
|
|
1384 |
aMessage.Complete(err);
|
|
1385 |
LOGTEXT(_L("CPSession::ServiceL - Message completed"));
|
|
1386 |
}
|
|
1387 |
else
|
|
1388 |
{
|
|
1389 |
LOGTEXT(_L("ServiceL: Ptr2 != 0 && Ptr3 != 0xffffffff"));
|
|
1390 |
|
|
1391 |
TUint32 num1 = (TUint32)aMessage.Ptr2(); // containing id
|
|
1392 |
TBuf<256>* buffer = new TBuf<256>; // Text data, e.g. plug-in name or description
|
|
1393 |
|
|
1394 |
LOGSTRING3("Getting data for sampler: 0x%X, buffer max len %d",num1, aMessage.GetDesMaxLength(3));
|
|
1395 |
|
|
1396 |
err = Server().ControlDataL(aMessage.Function(), (TAny*)num1, (TAny*)buffer);
|
|
1397 |
|
|
1398 |
LOGSTRING2("Got sampler data %S",&buffer);
|
|
1399 |
|
|
1400 |
// write back to same parameter
|
|
1401 |
aMessage.WriteL(3, *buffer, 0);
|
|
1402 |
|
|
1403 |
delete buffer;
|
|
1404 |
aMessage.Complete(err);
|
|
1405 |
LOGTEXT(_L("CPSession::ServiceL - Message completed"));
|
|
1406 |
}
|
|
1407 |
}
|
|
1408 |
LOGTEXT(_L("CPSession::ServiceL - Message processed"));
|
|
1409 |
}
|
|
1410 |
|
|
1411 |
// --------------------------------------------------------------------------------------------
|
|
1412 |
MProfilerController* CPServer::NewL(TInt aPriority, MProfilerEngine& aEngine)
|
|
1413 |
{
|
|
1414 |
LOGTEXT(_L("CPServer::NewL - Enter"));
|
|
1415 |
CPServer* self = new(ELeave) CPServer(aPriority, aEngine);
|
|
1416 |
CleanupStack::PushL(self);
|
|
1417 |
self->StartL(KProfilerName);
|
|
1418 |
CleanupStack::Pop();
|
62
|
1419 |
LOGTEXT(_L("CPServer::NewL - Exit "));
|
51
|
1420 |
return self;
|
|
1421 |
}
|
|
1422 |
|
|
1423 |
// --------------------------------------------------------------------------------------------
|
|
1424 |
CPServer::CPServer(TInt aPriority, MProfilerEngine& aEngine)
|
|
1425 |
: CServer2(aPriority), MProfilerController(aEngine)
|
|
1426 |
{
|
|
1427 |
|
|
1428 |
}
|
|
1429 |
|
|
1430 |
// --------------------------------------------------------------------------------------------
|
|
1431 |
void CPServer::Release()
|
|
1432 |
{
|
|
1433 |
delete this;
|
|
1434 |
}
|
|
1435 |
|
|
1436 |
// --------------------------------------------------------------------------------------------
|
|
1437 |
CSession2* CPServer::NewSessionL(const TVersion&,const RMessage2&) const
|
|
1438 |
{
|
|
1439 |
return new(ELeave) CPSession();
|
|
1440 |
}
|
|
1441 |
|
|
1442 |
/*
|
|
1443 |
*
|
|
1444 |
* Static methods for controlling the profiler
|
|
1445 |
* through command line
|
|
1446 |
*
|
|
1447 |
*/
|
|
1448 |
// --------------------------------------------------------------------------------------------
|
62
|
1449 |
static void RunEngineServerL(const TDesC& aSettingsFile, TBool aBoot)
|
51
|
1450 |
{
|
62
|
1451 |
LOGSTRING("Profiler: RunEngineServerL() - Install active scheduler");
|
51
|
1452 |
CActiveScheduler* pS = new CActiveScheduler;
|
|
1453 |
CActiveScheduler::Install(pS);
|
62
|
1454 |
CProfiler* p = CProfiler::NewLC(aSettingsFile, aBoot);
|
|
1455 |
|
|
1456 |
LOGSTRING("Profiler: RunEngineServerL() - Starting active scheduler");
|
51
|
1457 |
CActiveScheduler::Start();
|
|
1458 |
p->Finalise();
|
62
|
1459 |
LOGSTRING("Profiler: RunEngineServerL() - profiler finalised");
|
51
|
1460 |
CleanupStack::PopAndDestroy(p);
|
|
1461 |
delete pS;
|
62
|
1462 |
LOGSTRING("Profiler: RunEngineServerL() - done");
|
51
|
1463 |
}
|
|
1464 |
|
|
1465 |
// --------------------------------------------------------------------------------------------
|
|
1466 |
static TInt TestSettingsFile(const TDesC& configFile)
|
|
1467 |
{
|
|
1468 |
RFs fs;
|
|
1469 |
LOGSTRING2("TestSettingsFile: entry %S", &configFile);
|
|
1470 |
// check if file server can be connected
|
|
1471 |
if (fs.Connect() != KErrNone)
|
|
1472 |
{
|
|
1473 |
LOGTEXT(_L("TestSettingsFile: could not connect file server"));
|
|
1474 |
// file server couldn't be connected, return false
|
|
1475 |
return KErrNotFound;
|
|
1476 |
}
|
|
1477 |
|
|
1478 |
// check if config file name length is > 0
|
|
1479 |
if (configFile.Length() > 0)
|
|
1480 |
{
|
|
1481 |
LOGTEXT(_L("TestSettingsFile: checking location sanity"));
|
|
1482 |
// check sanity of settings file location
|
|
1483 |
if(BaflUtils::CheckFolder(fs, configFile) != KErrNone)
|
|
1484 |
{
|
|
1485 |
LOGTEXT(_L("TestSettingsFile: location sanity check failed"));
|
|
1486 |
fs.Close();
|
|
1487 |
return KErrGeneral;
|
|
1488 |
}
|
|
1489 |
}
|
|
1490 |
else
|
|
1491 |
{
|
|
1492 |
// configFile length 0, return false
|
|
1493 |
LOGTEXT(_L("TestSettingsFile: config file string null length"));
|
|
1494 |
fs.Close();
|
|
1495 |
return KErrNotFound;
|
|
1496 |
}
|
|
1497 |
// return true if tests passed
|
|
1498 |
LOGTEXT(_L("TestSettingsFile: exiting..."));
|
|
1499 |
fs.Close();
|
|
1500 |
return KErrNone;
|
|
1501 |
}
|
|
1502 |
|
|
1503 |
// --------------------------------------------------------------------------------------------
|
|
1504 |
GLDEF_C TInt E32Main()
|
|
1505 |
{
|
62
|
1506 |
LOGSTRING("Profiler: E32Main()");
|
51
|
1507 |
// parse command line arguments
|
|
1508 |
TBuf<256> c;
|
|
1509 |
TInt err(KErrNone);
|
62
|
1510 |
_LIT(KBootMeasurement,"*boot");
|
51
|
1511 |
|
62
|
1512 |
TBool myBoot(EFalse);
|
51
|
1513 |
// copy the full command line with arguments into a buffer
|
|
1514 |
User::CommandLine(c);
|
|
1515 |
|
62
|
1516 |
// parse command line for boot mode. filename boot
|
|
1517 |
|
|
1518 |
|
|
1519 |
if (c.Match(KBootMeasurement) != KErrNotFound)
|
|
1520 |
{
|
|
1521 |
LOGTEXT(_L("ParseCommandAndExecute Found keyword boot"));
|
|
1522 |
myBoot = ETrue;
|
|
1523 |
}
|
|
1524 |
|
|
1525 |
TBuf<256> temp;
|
|
1526 |
temp.Append(c);
|
|
1527 |
TLex lex(temp);
|
|
1528 |
lex.Mark();
|
|
1529 |
lex.SkipCharacters();
|
|
1530 |
|
|
1531 |
TPtrC token;
|
51
|
1532 |
TBuf<256> fileName;
|
62
|
1533 |
|
|
1534 |
if(lex.TokenLength() != 0)
|
51
|
1535 |
{
|
62
|
1536 |
TPtrC token = lex.MarkedToken();
|
|
1537 |
LOGSTRING2("E32 Main Token 1 %S",&token);
|
|
1538 |
fileName.Append(token); // only one settings param should be
|
|
1539 |
LOGSTRING3("Filename is #%S#, response %d 1", &fileName, err);
|
|
1540 |
err = TestSettingsFile(fileName);
|
|
1541 |
if(err != KErrNone)
|
|
1542 |
{
|
|
1543 |
LOGSTRING3("Filename is #%S#, response %d 2", &fileName, err);
|
|
1544 |
// settings file does not exist, copy null desc to file name
|
|
1545 |
fileName.Copy(KNullDesC);
|
|
1546 |
}
|
|
1547 |
}
|
|
1548 |
else
|
|
1549 |
{
|
|
1550 |
LOGTEXT(_L("E32 Main Problem 1 in parsing command line"));
|
51
|
1551 |
}
|
|
1552 |
|
|
1553 |
// if no command line arguments found just start the profiler process
|
|
1554 |
__UHEAP_MARK;
|
|
1555 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
|
1556 |
TInt ret(KErrNoMemory);
|
62
|
1557 |
err = KErrNoMemory;
|
51
|
1558 |
if( cleanup )
|
|
1559 |
{
|
62
|
1560 |
TRAPD(err ,RunEngineServerL(fileName, myBoot));
|
|
1561 |
LOGSTRING3("Profiler: E32Main() - ret %d err %d", ret,err);
|
|
1562 |
if(err != KErrNone)
|
|
1563 |
{
|
|
1564 |
RDebug::Print(_L("if Profiler: E32Main() - ret %d err %d"), ret,err);
|
|
1565 |
ret = err;
|
|
1566 |
delete cleanup;
|
|
1567 |
}
|
|
1568 |
else
|
|
1569 |
{
|
|
1570 |
LOGSTRING3("else Profiler: E32Main() - ret %d err %d", ret,err);
|
|
1571 |
ret = err;
|
|
1572 |
delete cleanup;
|
|
1573 |
}
|
51
|
1574 |
}
|
|
1575 |
__UHEAP_MARKEND;
|
|
1576 |
|
|
1577 |
return ret;
|
|
1578 |
}
|
|
1579 |
|
|
1580 |
|