commands/uprofiler/uprofiler.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // uprofiler.cpp
       
     2 // 
       
     3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "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 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #include <fshell/ioutils.h>
       
    14 #include <fshell/extrabtrace.h>
       
    15 
       
    16 using namespace IoUtils;
       
    17 
       
    18 class CCmdUprofiler : public CCommandBase
       
    19 	{
       
    20 public:
       
    21 	static CCommandBase* NewLC();
       
    22 	~CCmdUprofiler();
       
    23 private:
       
    24 	CCmdUprofiler();
       
    25 private: // From CCommandBase.
       
    26 	virtual const TDesC& Name() const;
       
    27 	virtual void DoRunL();
       
    28 	virtual void ArgumentsL(RCommandArgumentList& aArguments);
       
    29 	virtual void OptionsL(RCommandOptionList& aOptions);
       
    30 private:
       
    31 	enum TCommand
       
    32 		{
       
    33 		EStart = 0,
       
    34 		EStop = 1,
       
    35 		};
       
    36 	TCommand iCommand;
       
    37 	TInt iRate; // In Hz, just for fun
       
    38 	RExtraBtrace iBtrace;
       
    39 	TBool iVerbose;
       
    40 	};
       
    41 
       
    42 CCommandBase* CCmdUprofiler::NewLC()
       
    43 	{
       
    44 	CCmdUprofiler* self = new(ELeave) CCmdUprofiler();
       
    45 	CleanupStack::PushL(self);
       
    46 	self->BaseConstructL();
       
    47 	return self;
       
    48 	}
       
    49 
       
    50 CCmdUprofiler::~CCmdUprofiler()
       
    51 	{
       
    52 	iBtrace.Close();
       
    53 	}
       
    54 
       
    55 CCmdUprofiler::CCmdUprofiler()
       
    56 	: iRate(1000)
       
    57 	{
       
    58 	}
       
    59 
       
    60 const TDesC& CCmdUprofiler::Name() const
       
    61 	{
       
    62 	_LIT(KName, "uprofiler");	
       
    63 	return KName;
       
    64 	}
       
    65 
       
    66 void CCmdUprofiler::ArgumentsL(RCommandArgumentList& aArguments)
       
    67 	{
       
    68 	aArguments.AppendEnumL((TInt&)iCommand, _L("command"));
       
    69 	aArguments.AppendIntL(iRate, _L("rate"));
       
    70 	}
       
    71 
       
    72 void CCmdUprofiler::OptionsL(RCommandOptionList& aOptions)
       
    73 	{
       
    74 	aOptions.AppendBoolL(iVerbose, _L("verbose"));
       
    75 	}
       
    76 
       
    77 EXE_BOILER_PLATE(CCmdUprofiler)
       
    78 
       
    79 void CCmdUprofiler::DoRunL()
       
    80 	{
       
    81 	if (iRate <= 0 || iRate > 1000) LeaveIfErr(KErrArgument, _L("rate must be between 1 and 1000"));
       
    82 
       
    83 	TInt ms = 1000 / iRate;
       
    84 	LeaveIfErr(iBtrace.Connect(), _L("Couldn't connect to RExtraBtrace"));
       
    85 	if (iCommand == EStart)
       
    86 		{
       
    87 		LeaveIfErr(iBtrace.EnableProfiling(ms), _L("Couldn't enable profiling"));
       
    88 		}
       
    89 	else
       
    90 		{
       
    91 		LeaveIfErr(iBtrace.EnableProfiling(0), _L("Couldn't disable profiling"));
       
    92 		}
       
    93 	}