os/kernelhwsrv/kerneltest/e32utils/profiler/profiler.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32utils/profiler/profiler.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,142 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32utils\profiler\profiler.h
    1.18 +// 
    1.19 +// WARNING: This file contains some APIs which are internal and are subject
    1.20 +//          to change without notice. Such APIs should therefore not be used
    1.21 +//          outside the Kernel and Hardware Services package.
    1.22 +//
    1.23 +
    1.24 +#ifndef __PROFILER__
    1.25 +#define __PROFILER__
    1.26 +
    1.27 +#include <e32base.h>
    1.28 +
    1.29 +
    1.30 +_LIT(KProfilerName,"Profiler");
    1.31 +
    1.32 +/**
    1.33 +The Profiler class provides a functional interface to the sampling profiler. <p>
    1.34 +The engine must already be running for this interface to work, this can be
    1.35 +achieved by executing PROFILER.EXE. The control methods are all static, and 
    1.36 +require no other context.
    1.37 +
    1.38 +@internalTechnology
    1.39 +*/
    1.40 +class Profiler : private RSessionBase
    1.41 +	{
    1.42 +public:
    1.43 +	enum TState {EStart, EStop, EClose, EUnload};
    1.44 +public:
    1.45 +	/** Start the sampler */
    1.46 +	static inline TInt Start();
    1.47 +	/** Stop the sampler */
    1.48 +	static inline TInt Stop();
    1.49 +	/** Release the sample trace file */
    1.50 +	static inline TInt Close();
    1.51 +	/** Unload the profile engine from memory */
    1.52 +	static inline TInt Unload();
    1.53 +//
    1.54 +	/** Issue a control request to the engine */
    1.55 +	static inline TInt Control(TState aRequest);
    1.56 +private:
    1.57 +	inline Profiler();
    1.58 +	};
    1.59 +
    1.60 +inline Profiler::Profiler()
    1.61 +	{}
    1.62 +
    1.63 +inline TInt Profiler::Control(TState aRequest)
    1.64 +//
    1.65 +// Connect to the profiler engine, and issue the control request if successful
    1.66 +//
    1.67 +	{
    1.68 +	Profiler p;
    1.69 +	TInt r = p.CreateSession(KProfilerName, TVersion(), 0);
    1.70 +	if (r == KErrNone)
    1.71 +		{
    1.72 +		p.SendReceive(aRequest);
    1.73 +		p.RSessionBase::Close();
    1.74 +		}
    1.75 +	return r;
    1.76 +	}
    1.77 +
    1.78 +inline TInt Profiler::Start()
    1.79 +	{return Control(EStart);}
    1.80 +
    1.81 +inline TInt Profiler::Stop()
    1.82 +	{return Control(EStop);}
    1.83 +
    1.84 +inline TInt Profiler::Close()
    1.85 +	{return Control(EClose);}
    1.86 +
    1.87 +inline TInt Profiler::Unload()
    1.88 +	{return Control(EUnload);}
    1.89 +
    1.90 +
    1.91 +
    1.92 +/*
    1.93 + * This is an internal interface to the profiling engine which allows
    1.94 + * an additional control DLL to be loaded, replacing the profiler's
    1.95 + * default console UI
    1.96 + */
    1.97 +
    1.98 +/**
    1.99 +Implementation class providing access to the profiler engine
   1.100 +
   1.101 +@internalTechnology
   1.102 +*/
   1.103 +class MProfilerEngine
   1.104 +	{
   1.105 +public:
   1.106 +	virtual TInt Control(Profiler::TState aCommand) =0;
   1.107 +	virtual Profiler::TState State() const =0;
   1.108 +	};
   1.109 +
   1.110 +/**
   1.111 +The interface that the extra controller must implement to access the profiler.
   1.112 +
   1.113 +@internalTechnology
   1.114 +*/
   1.115 +class MProfilerController
   1.116 +	{
   1.117 +public:
   1.118 +	/** Release the controller from the profiler. This is invoked when the profiler is unloading. */
   1.119 +	virtual void Release() =0;
   1.120 +	/** Ask the profiler to change state */
   1.121 +	inline TInt Control(Profiler::TState aCommand) const;
   1.122 +	/* Query the profiler state */
   1.123 +	inline Profiler::TState GetState() const;
   1.124 +protected:
   1.125 +	inline MProfilerController(MProfilerEngine& aEngine);
   1.126 +private:
   1.127 +	MProfilerEngine& iEngine;
   1.128 +	};
   1.129 +
   1.130 +/** The signature of ordinal 1 in the controller DLL */
   1.131 +typedef MProfilerController* (*TProfilerControllerFactoryL)(TInt aPriority, MProfilerEngine& aEngine);
   1.132 +
   1.133 +/** The second UID required by the controller DLL */
   1.134 +const TUid KUidProfilerKeys={0x1000945c};
   1.135 +
   1.136 +
   1.137 +inline MProfilerController::MProfilerController(MProfilerEngine& aEngine)
   1.138 +	:iEngine(aEngine)
   1.139 +	{}
   1.140 +inline TInt MProfilerController::Control(Profiler::TState aCommand) const
   1.141 +	{return iEngine.Control(aCommand);}
   1.142 +inline Profiler::TState MProfilerController::GetState() const
   1.143 +	{return iEngine.State();}
   1.144 +
   1.145 +#endif