os/kernelhwsrv/kerneltest/e32utils/profiler/sampler.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32utils/profiler/sampler.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,161 @@
     1.4 +// Copyright (c) 1999-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\sampler.h
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#ifndef __SAMPLER_H__
    1.22 +#define __SAMPLER_H__
    1.23 +
    1.24 +#include <e32cmn.h>
    1.25 +#ifndef __KERNEL_MODE__
    1.26 +#include <e32std.h>
    1.27 +#endif
    1.28 +
    1.29 +//Uncomment this line to generate debug logging of the profiler and sampler.
    1.30 +//#define DEBUG_PROFILER(f) f
    1.31 +#define DEBUG_PROFILER(f)
    1.32 +
    1.33 +/**
    1.34 + * The user device driver class for controlling the sampler.
    1.35 + */
    1.36 +class RSampler : public RBusLogicalChannel
    1.37 +	{
    1.38 +	friend class DProfile;
    1.39 +private:
    1.40 +	enum TControl
    1.41 +		{
    1.42 +		EControlGetSegments,
    1.43 +		EControlStartProfile,
    1.44 +		EControlStopProfile,
    1.45 +		EControlResetProfile,
    1.46 +		EControlResetSegments,
    1.47 +		EControlDrain,
    1.48 +		EControlGetErrors
    1.49 +		};
    1.50 +	enum TRequest
    1.51 +		{
    1.52 +		ERequestRead
    1.53 +		};
    1.54 +	static inline TInt CancelRequest(TRequest aRequest);
    1.55 +public:
    1.56 +#ifndef __KERNEL_MODE__
    1.57 +	/** Open a channel to the sampling device */
    1.58 +	inline TInt Open();
    1.59 +	/** Get the current non-XIP Code Segments*/
    1.60 +	inline void GetSegments(TDes8& aData);
    1.61 +	/** Start sampling */
    1.62 +	inline void Start(TInt aRate);
    1.63 +	/** Stop sampling */
    1.64 +	inline void Stop();
    1.65 +	/** Extract the sample data */
    1.66 +	inline void Read(TDes8& aData,TRequestStatus& aStatus);
    1.67 +	/** Cancel a read request */
    1.68 +	inline void ReadCancel();
    1.69 +	/** Extract any remaining sample data */
    1.70 +	inline void Drain(TDes8& aData);
    1.71 +	/** Get error report */
    1.72 +	inline void GetErrors(TDes8& aData);
    1.73 +	/** Reset the sampler for a new run */
    1.74 +	inline void Reset(TBool aXIPOnly);
    1.75 +	/** Initialise non-XIP segments for a new run */
    1.76 +	inline void ResetSegments();
    1.77 +#endif
    1.78 +	};
    1.79 +
    1.80 +_LIT(KSamplerName,"Sampler");
    1.81 +
    1.82 +#ifndef __KERNEL_MODE__
    1.83 +inline TInt RSampler::CancelRequest(TRequest aRequest)
    1.84 +	{return 1<<aRequest;}
    1.85 +
    1.86 +inline TInt RSampler::Open()
    1.87 +	{return DoCreate(KSamplerName,TVersion(1,0,0),KNullUnit,NULL,NULL);}
    1.88 +
    1.89 +/**
    1.90 + * Get the existing non-XIP Code Segments.
    1.91 + *
    1.92 + * @param aData	A descriptor to receive data. Returns as zero-length if all data 
    1.93 + * records are already transfered.
    1.94 + */
    1.95 +inline void RSampler::GetSegments(TDes8& aData)
    1.96 +	{DoControl(EControlGetSegments, &aData);}
    1.97 +
    1.98 +/**
    1.99 + * Start sampling at the requested rate. If currently sampling, this will just
   1.100 + * change the sample rate.
   1.101 + *
   1.102 + * @param aRate The sample rate in samples/second
   1.103 + */
   1.104 +inline void RSampler::Start(TInt aRate)
   1.105 +	{DoControl(EControlStartProfile, reinterpret_cast<TAny*>(aRate));}
   1.106 +
   1.107 +/**
   1.108 + * Stop sampling. If currently sampling, any outstanding read request will be completed
   1.109 + * with data remaining in the buffer.
   1.110 + */
   1.111 +inline void RSampler::Stop()
   1.112 +	{DoControl(EControlStopProfile);}
   1.113 +
   1.114 +/**
   1.115 + * Reset the sampler. All sample data is discarded and history is removed, preparing the
   1.116 + * sampler for a new run. The sampler must be stopped before it can be reset.
   1.117 + *
   1.118 + * @param aXIPOnly True if the profiler runs in XIPOnly mode.
   1.119 + */
   1.120 +inline void RSampler::Reset(TBool aXIPOnly)
   1.121 +	{DoControl(EControlResetProfile,(TAny*)aXIPOnly);}
   1.122 +
   1.123 +/**
   1.124 +* Reset non-XIP code segments, preparing the sampler for a new run
   1.125 +*/
   1.126 +inline void RSampler::ResetSegments()
   1.127 +	{DoControl(EControlResetSegments);}
   1.128 +
   1.129 +/**
   1.130 + * Extract the sample data from the device. This will complete when the device's buffer is
   1.131 + * full, when the provided descriptor is full, or when the sampler is stopped.
   1.132 + *
   1.133 + * @param aData		A descriptor to receive the sample data
   1.134 + * @param aStatus	A request status used to signal when this request is completed
   1.135 + */
   1.136 +inline void RSampler::Read(TDes8& aData,TRequestStatus& aStatus)
   1.137 +	{DoRequest(ERequestRead,aStatus,&aData);}
   1.138 +
   1.139 +/**
   1.140 + * Cancel the outstanding read request
   1.141 + */
   1.142 +inline void RSampler::ReadCancel()
   1.143 +	{DoCancel(CancelRequest(ERequestRead));}
   1.144 +
   1.145 +/**
   1.146 + * Extract any remaining sample data from the device buffer. When the buffer is
   1.147 + * empty, the descriptor will be empty on return.
   1.148 + *
   1.149 + * @param aData	A descriptor to receive the sample data
   1.150 + */
   1.151 +inline void RSampler::Drain(TDes8& aData)
   1.152 +	{DoControl(EControlDrain,&aData);}
   1.153 +
   1.154 +/**
   1.155 + * Get error report from the sampler.
   1.156 + *
   1.157 + * @param aData		A descriptor to receive error report
   1.158 + */
   1.159 +inline void RSampler::GetErrors(TDes8& aData)
   1.160 +	{DoControl(EControlGetErrors,&aData);}
   1.161 +
   1.162 +#endif
   1.163 +
   1.164 +#endif