os/kernelhwsrv/kerneltest/e32utils/profiler/profiler.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32utils\profiler\profiler.h
    15 // 
    16 // WARNING: This file contains some APIs which are internal and are subject
    17 //          to change without notice. Such APIs should therefore not be used
    18 //          outside the Kernel and Hardware Services package.
    19 //
    20 
    21 #ifndef __PROFILER__
    22 #define __PROFILER__
    23 
    24 #include <e32base.h>
    25 
    26 
    27 _LIT(KProfilerName,"Profiler");
    28 
    29 /**
    30 The Profiler class provides a functional interface to the sampling profiler. <p>
    31 The engine must already be running for this interface to work, this can be
    32 achieved by executing PROFILER.EXE. The control methods are all static, and 
    33 require no other context.
    34 
    35 @internalTechnology
    36 */
    37 class Profiler : private RSessionBase
    38 	{
    39 public:
    40 	enum TState {EStart, EStop, EClose, EUnload};
    41 public:
    42 	/** Start the sampler */
    43 	static inline TInt Start();
    44 	/** Stop the sampler */
    45 	static inline TInt Stop();
    46 	/** Release the sample trace file */
    47 	static inline TInt Close();
    48 	/** Unload the profile engine from memory */
    49 	static inline TInt Unload();
    50 //
    51 	/** Issue a control request to the engine */
    52 	static inline TInt Control(TState aRequest);
    53 private:
    54 	inline Profiler();
    55 	};
    56 
    57 inline Profiler::Profiler()
    58 	{}
    59 
    60 inline TInt Profiler::Control(TState aRequest)
    61 //
    62 // Connect to the profiler engine, and issue the control request if successful
    63 //
    64 	{
    65 	Profiler p;
    66 	TInt r = p.CreateSession(KProfilerName, TVersion(), 0);
    67 	if (r == KErrNone)
    68 		{
    69 		p.SendReceive(aRequest);
    70 		p.RSessionBase::Close();
    71 		}
    72 	return r;
    73 	}
    74 
    75 inline TInt Profiler::Start()
    76 	{return Control(EStart);}
    77 
    78 inline TInt Profiler::Stop()
    79 	{return Control(EStop);}
    80 
    81 inline TInt Profiler::Close()
    82 	{return Control(EClose);}
    83 
    84 inline TInt Profiler::Unload()
    85 	{return Control(EUnload);}
    86 
    87 
    88 
    89 /*
    90  * This is an internal interface to the profiling engine which allows
    91  * an additional control DLL to be loaded, replacing the profiler's
    92  * default console UI
    93  */
    94 
    95 /**
    96 Implementation class providing access to the profiler engine
    97 
    98 @internalTechnology
    99 */
   100 class MProfilerEngine
   101 	{
   102 public:
   103 	virtual TInt Control(Profiler::TState aCommand) =0;
   104 	virtual Profiler::TState State() const =0;
   105 	};
   106 
   107 /**
   108 The interface that the extra controller must implement to access the profiler.
   109 
   110 @internalTechnology
   111 */
   112 class MProfilerController
   113 	{
   114 public:
   115 	/** Release the controller from the profiler. This is invoked when the profiler is unloading. */
   116 	virtual void Release() =0;
   117 	/** Ask the profiler to change state */
   118 	inline TInt Control(Profiler::TState aCommand) const;
   119 	/* Query the profiler state */
   120 	inline Profiler::TState GetState() const;
   121 protected:
   122 	inline MProfilerController(MProfilerEngine& aEngine);
   123 private:
   124 	MProfilerEngine& iEngine;
   125 	};
   126 
   127 /** The signature of ordinal 1 in the controller DLL */
   128 typedef MProfilerController* (*TProfilerControllerFactoryL)(TInt aPriority, MProfilerEngine& aEngine);
   129 
   130 /** The second UID required by the controller DLL */
   131 const TUid KUidProfilerKeys={0x1000945c};
   132 
   133 
   134 inline MProfilerController::MProfilerController(MProfilerEngine& aEngine)
   135 	:iEngine(aEngine)
   136 	{}
   137 inline TInt MProfilerController::Control(Profiler::TState aCommand) const
   138 	{return iEngine.Control(aCommand);}
   139 inline Profiler::TState MProfilerController::GetState() const
   140 	{return iEngine.State();}
   141 
   142 #endif