sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32utils\profiler\profiler.h sl@0: // sl@0: // WARNING: This file contains some APIs which are internal and are subject sl@0: // to change without notice. Such APIs should therefore not be used sl@0: // outside the Kernel and Hardware Services package. sl@0: // sl@0: sl@0: #ifndef __PROFILER__ sl@0: #define __PROFILER__ sl@0: sl@0: #include sl@0: sl@0: sl@0: _LIT(KProfilerName,"Profiler"); sl@0: sl@0: /** sl@0: The Profiler class provides a functional interface to the sampling profiler.

sl@0: The engine must already be running for this interface to work, this can be sl@0: achieved by executing PROFILER.EXE. The control methods are all static, and sl@0: require no other context. sl@0: sl@0: @internalTechnology sl@0: */ sl@0: class Profiler : private RSessionBase sl@0: { sl@0: public: sl@0: enum TState {EStart, EStop, EClose, EUnload}; sl@0: public: sl@0: /** Start the sampler */ sl@0: static inline TInt Start(); sl@0: /** Stop the sampler */ sl@0: static inline TInt Stop(); sl@0: /** Release the sample trace file */ sl@0: static inline TInt Close(); sl@0: /** Unload the profile engine from memory */ sl@0: static inline TInt Unload(); sl@0: // sl@0: /** Issue a control request to the engine */ sl@0: static inline TInt Control(TState aRequest); sl@0: private: sl@0: inline Profiler(); sl@0: }; sl@0: sl@0: inline Profiler::Profiler() sl@0: {} sl@0: sl@0: inline TInt Profiler::Control(TState aRequest) sl@0: // sl@0: // Connect to the profiler engine, and issue the control request if successful sl@0: // sl@0: { sl@0: Profiler p; sl@0: TInt r = p.CreateSession(KProfilerName, TVersion(), 0); sl@0: if (r == KErrNone) sl@0: { sl@0: p.SendReceive(aRequest); sl@0: p.RSessionBase::Close(); sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: inline TInt Profiler::Start() sl@0: {return Control(EStart);} sl@0: sl@0: inline TInt Profiler::Stop() sl@0: {return Control(EStop);} sl@0: sl@0: inline TInt Profiler::Close() sl@0: {return Control(EClose);} sl@0: sl@0: inline TInt Profiler::Unload() sl@0: {return Control(EUnload);} sl@0: sl@0: sl@0: sl@0: /* sl@0: * This is an internal interface to the profiling engine which allows sl@0: * an additional control DLL to be loaded, replacing the profiler's sl@0: * default console UI sl@0: */ sl@0: sl@0: /** sl@0: Implementation class providing access to the profiler engine sl@0: sl@0: @internalTechnology sl@0: */ sl@0: class MProfilerEngine sl@0: { sl@0: public: sl@0: virtual TInt Control(Profiler::TState aCommand) =0; sl@0: virtual Profiler::TState State() const =0; sl@0: }; sl@0: sl@0: /** sl@0: The interface that the extra controller must implement to access the profiler. sl@0: sl@0: @internalTechnology sl@0: */ sl@0: class MProfilerController sl@0: { sl@0: public: sl@0: /** Release the controller from the profiler. This is invoked when the profiler is unloading. */ sl@0: virtual void Release() =0; sl@0: /** Ask the profiler to change state */ sl@0: inline TInt Control(Profiler::TState aCommand) const; sl@0: /* Query the profiler state */ sl@0: inline Profiler::TState GetState() const; sl@0: protected: sl@0: inline MProfilerController(MProfilerEngine& aEngine); sl@0: private: sl@0: MProfilerEngine& iEngine; sl@0: }; sl@0: sl@0: /** The signature of ordinal 1 in the controller DLL */ sl@0: typedef MProfilerController* (*TProfilerControllerFactoryL)(TInt aPriority, MProfilerEngine& aEngine); sl@0: sl@0: /** The second UID required by the controller DLL */ sl@0: const TUid KUidProfilerKeys={0x1000945c}; sl@0: sl@0: sl@0: inline MProfilerController::MProfilerController(MProfilerEngine& aEngine) sl@0: :iEngine(aEngine) sl@0: {} sl@0: inline TInt MProfilerController::Control(Profiler::TState aCommand) const sl@0: {return iEngine.Control(aCommand);} sl@0: inline Profiler::TState MProfilerController::GetState() const sl@0: {return iEngine.State();} sl@0: sl@0: #endif