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