os/kernelhwsrv/kerneltest/e32utils/profiler/sampler.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) 1999-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\sampler.h
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#ifndef __SAMPLER_H__
sl@0
    19
#define __SAMPLER_H__
sl@0
    20
sl@0
    21
#include <e32cmn.h>
sl@0
    22
#ifndef __KERNEL_MODE__
sl@0
    23
#include <e32std.h>
sl@0
    24
#endif
sl@0
    25
sl@0
    26
//Uncomment this line to generate debug logging of the profiler and sampler.
sl@0
    27
//#define DEBUG_PROFILER(f) f
sl@0
    28
#define DEBUG_PROFILER(f)
sl@0
    29
sl@0
    30
/**
sl@0
    31
 * The user device driver class for controlling the sampler.
sl@0
    32
 */
sl@0
    33
class RSampler : public RBusLogicalChannel
sl@0
    34
	{
sl@0
    35
	friend class DProfile;
sl@0
    36
private:
sl@0
    37
	enum TControl
sl@0
    38
		{
sl@0
    39
		EControlGetSegments,
sl@0
    40
		EControlStartProfile,
sl@0
    41
		EControlStopProfile,
sl@0
    42
		EControlResetProfile,
sl@0
    43
		EControlResetSegments,
sl@0
    44
		EControlDrain,
sl@0
    45
		EControlGetErrors
sl@0
    46
		};
sl@0
    47
	enum TRequest
sl@0
    48
		{
sl@0
    49
		ERequestRead
sl@0
    50
		};
sl@0
    51
	static inline TInt CancelRequest(TRequest aRequest);
sl@0
    52
public:
sl@0
    53
#ifndef __KERNEL_MODE__
sl@0
    54
	/** Open a channel to the sampling device */
sl@0
    55
	inline TInt Open();
sl@0
    56
	/** Get the current non-XIP Code Segments*/
sl@0
    57
	inline void GetSegments(TDes8& aData);
sl@0
    58
	/** Start sampling */
sl@0
    59
	inline void Start(TInt aRate);
sl@0
    60
	/** Stop sampling */
sl@0
    61
	inline void Stop();
sl@0
    62
	/** Extract the sample data */
sl@0
    63
	inline void Read(TDes8& aData,TRequestStatus& aStatus);
sl@0
    64
	/** Cancel a read request */
sl@0
    65
	inline void ReadCancel();
sl@0
    66
	/** Extract any remaining sample data */
sl@0
    67
	inline void Drain(TDes8& aData);
sl@0
    68
	/** Get error report */
sl@0
    69
	inline void GetErrors(TDes8& aData);
sl@0
    70
	/** Reset the sampler for a new run */
sl@0
    71
	inline void Reset(TBool aXIPOnly);
sl@0
    72
	/** Initialise non-XIP segments for a new run */
sl@0
    73
	inline void ResetSegments();
sl@0
    74
#endif
sl@0
    75
	};
sl@0
    76
sl@0
    77
_LIT(KSamplerName,"Sampler");
sl@0
    78
sl@0
    79
#ifndef __KERNEL_MODE__
sl@0
    80
inline TInt RSampler::CancelRequest(TRequest aRequest)
sl@0
    81
	{return 1<<aRequest;}
sl@0
    82
sl@0
    83
inline TInt RSampler::Open()
sl@0
    84
	{return DoCreate(KSamplerName,TVersion(1,0,0),KNullUnit,NULL,NULL);}
sl@0
    85
sl@0
    86
/**
sl@0
    87
 * Get the existing non-XIP Code Segments.
sl@0
    88
 *
sl@0
    89
 * @param aData	A descriptor to receive data. Returns as zero-length if all data 
sl@0
    90
 * records are already transfered.
sl@0
    91
 */
sl@0
    92
inline void RSampler::GetSegments(TDes8& aData)
sl@0
    93
	{DoControl(EControlGetSegments, &aData);}
sl@0
    94
sl@0
    95
/**
sl@0
    96
 * Start sampling at the requested rate. If currently sampling, this will just
sl@0
    97
 * change the sample rate.
sl@0
    98
 *
sl@0
    99
 * @param aRate The sample rate in samples/second
sl@0
   100
 */
sl@0
   101
inline void RSampler::Start(TInt aRate)
sl@0
   102
	{DoControl(EControlStartProfile, reinterpret_cast<TAny*>(aRate));}
sl@0
   103
sl@0
   104
/**
sl@0
   105
 * Stop sampling. If currently sampling, any outstanding read request will be completed
sl@0
   106
 * with data remaining in the buffer.
sl@0
   107
 */
sl@0
   108
inline void RSampler::Stop()
sl@0
   109
	{DoControl(EControlStopProfile);}
sl@0
   110
sl@0
   111
/**
sl@0
   112
 * Reset the sampler. All sample data is discarded and history is removed, preparing the
sl@0
   113
 * sampler for a new run. The sampler must be stopped before it can be reset.
sl@0
   114
 *
sl@0
   115
 * @param aXIPOnly True if the profiler runs in XIPOnly mode.
sl@0
   116
 */
sl@0
   117
inline void RSampler::Reset(TBool aXIPOnly)
sl@0
   118
	{DoControl(EControlResetProfile,(TAny*)aXIPOnly);}
sl@0
   119
sl@0
   120
/**
sl@0
   121
* Reset non-XIP code segments, preparing the sampler for a new run
sl@0
   122
*/
sl@0
   123
inline void RSampler::ResetSegments()
sl@0
   124
	{DoControl(EControlResetSegments);}
sl@0
   125
sl@0
   126
/**
sl@0
   127
 * Extract the sample data from the device. This will complete when the device's buffer is
sl@0
   128
 * full, when the provided descriptor is full, or when the sampler is stopped.
sl@0
   129
 *
sl@0
   130
 * @param aData		A descriptor to receive the sample data
sl@0
   131
 * @param aStatus	A request status used to signal when this request is completed
sl@0
   132
 */
sl@0
   133
inline void RSampler::Read(TDes8& aData,TRequestStatus& aStatus)
sl@0
   134
	{DoRequest(ERequestRead,aStatus,&aData);}
sl@0
   135
sl@0
   136
/**
sl@0
   137
 * Cancel the outstanding read request
sl@0
   138
 */
sl@0
   139
inline void RSampler::ReadCancel()
sl@0
   140
	{DoCancel(CancelRequest(ERequestRead));}
sl@0
   141
sl@0
   142
/**
sl@0
   143
 * Extract any remaining sample data from the device buffer. When the buffer is
sl@0
   144
 * empty, the descriptor will be empty on return.
sl@0
   145
 *
sl@0
   146
 * @param aData	A descriptor to receive the sample data
sl@0
   147
 */
sl@0
   148
inline void RSampler::Drain(TDes8& aData)
sl@0
   149
	{DoControl(EControlDrain,&aData);}
sl@0
   150
sl@0
   151
/**
sl@0
   152
 * Get error report from the sampler.
sl@0
   153
 *
sl@0
   154
 * @param aData		A descriptor to receive error report
sl@0
   155
 */
sl@0
   156
inline void RSampler::GetErrors(TDes8& aData)
sl@0
   157
	{DoControl(EControlGetErrors,&aData);}
sl@0
   158
sl@0
   159
#endif
sl@0
   160
sl@0
   161
#endif