os/kernelhwsrv/kernel/eka/include/d32btrace.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2005-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
//
sl@0
    15
// WARNING: This file contains some APIs which are internal and are subject
sl@0
    16
//          to change without notice. Such APIs should therefore not be used
sl@0
    17
//          outside the Kernel and Hardware Services package.
sl@0
    18
//
sl@0
    19
sl@0
    20
#ifndef D32BTRACE_H
sl@0
    21
#define D32BTRACE_H
sl@0
    22
sl@0
    23
#include <e32cmn.h>
sl@0
    24
#include <e32ver.h>
sl@0
    25
#include <e32btrace.h>
sl@0
    26
sl@0
    27
#ifndef __KERNEL_MODE__
sl@0
    28
#include <e32std.h>
sl@0
    29
#endif
sl@0
    30
sl@0
    31
sl@0
    32
class TBTraceBuffer;
sl@0
    33
sl@0
    34
/**
sl@0
    35
Interface to the fast-trace memory buffer.
sl@0
    36
sl@0
    37
@publishedPartner
sl@0
    38
@released
sl@0
    39
*/
sl@0
    40
class RBTrace : public RBusLogicalChannel
sl@0
    41
	{
sl@0
    42
public:
sl@0
    43
	/**
sl@0
    44
	Bit flags indicating the operational mode of the fast-trace buffer.
sl@0
    45
	*/
sl@0
    46
	enum TMode
sl@0
    47
		{
sl@0
    48
		/**
sl@0
    49
		Flag set to enable trace to be stored in the buffer.
sl@0
    50
		If this is not set, all trace records are discarded.
sl@0
    51
		*/
sl@0
    52
		EEnable			= 1<<0,
sl@0
    53
sl@0
    54
		/**
sl@0
    55
		This flag dictates the behaviour which occurs when the trace buffer is too full to
sl@0
    56
		accomodate a new record.
sl@0
    57
		When this flag is set, new trace records will overwrite the oldest ones.
sl@0
    58
		When this flag is not set, new trace records are discard.
sl@0
    59
		(This latter mode provides the best performance.)
sl@0
    60
		*/
sl@0
    61
		EFreeRunning	= 1<<1,
sl@0
    62
		};
sl@0
    63
sl@0
    64
#ifndef __KERNEL_MODE__
sl@0
    65
	/**
sl@0
    66
	Open channel to fast-trace driver.
sl@0
    67
	Must be called before any other methods are used.
sl@0
    68
	@return KErrNone or standard error code.
sl@0
    69
	*/
sl@0
    70
	IMPORT_C TInt Open();
sl@0
    71
sl@0
    72
	/**
sl@0
    73
	Close channel to fast-trace driver.
sl@0
    74
	*/
sl@0
    75
	IMPORT_C void Close();
sl@0
    76
sl@0
    77
	/**
sl@0
    78
	Get the current size of trace buffer.
sl@0
    79
	@return Buffer size.
sl@0
    80
	*/
sl@0
    81
	IMPORT_C TInt BufferSize();
sl@0
    82
sl@0
    83
	/**
sl@0
    84
	Change size of trace buffer.
sl@0
    85
	This causes all current data in the trace buffer to be lost.
sl@0
    86
	If this method fails then the trace buffer may no longer exist.
sl@0
    87
	@param aSize The size in bytes for the trace buffer.
sl@0
    88
	@return KErrNone or standard error code.
sl@0
    89
	*/
sl@0
    90
	IMPORT_C TInt ResizeBuffer(TInt aSize);
sl@0
    91
sl@0
    92
	/**
sl@0
    93
	Discard all trace data.
sl@0
    94
	*/
sl@0
    95
	IMPORT_C void Empty();
sl@0
    96
sl@0
    97
	/**
sl@0
    98
	The chunk in which trace data returned by GetData() resides.
sl@0
    99
	@return The chunk.
sl@0
   100
	*/
sl@0
   101
	inline RChunk DataChunk();
sl@0
   102
sl@0
   103
	/**
sl@0
   104
	The operational mode for fast-trace.
sl@0
   105
	@return The current operational mode. This is bitmask of values from TMode.
sl@0
   106
	*/
sl@0
   107
	IMPORT_C TUint Mode();
sl@0
   108
sl@0
   109
	/**
sl@0
   110
	Set the operational mode for fast-trace.
sl@0
   111
	Calling this method, invalidates the trace data returned by the last call to GetData().
sl@0
   112
	@param aMode A bitmask of values from TMode.
sl@0
   113
	*/
sl@0
   114
	IMPORT_C void SetMode(TUint aMode);
sl@0
   115
sl@0
   116
	/**
sl@0
   117
	Set the trace filter bit for the specified category.
sl@0
   118
	@param aCategory A category value from BTrace::TCategories.
sl@0
   119
	@param aValue The new filter value for the category.
sl@0
   120
				  1 means traces of this category are output, 0 means they are suppressed.
sl@0
   121
				  Any other value will be ignored, and this method will just return the current
sl@0
   122
				  value of the filter.
sl@0
   123
	@return The previous value of the filter for the category, 0 or 1.
sl@0
   124
			Or KErrNotSupported if this category is not supported by this build of the kernel.
sl@0
   125
	*/
sl@0
   126
	IMPORT_C TInt SetFilter(TUint aCategory, TInt aValue);
sl@0
   127
sl@0
   128
	/**
sl@0
   129
	Get the trace filter bit for the specified category.
sl@0
   130
	@param aCategory A category value from enum BTrace::TCategory,	
sl@0
   131
	@return The value of the filter for the category, 0 or 1,
sl@0
   132
			or KErrNotSupported if this category is not supported by this build of the kernel.
sl@0
   133
			(1 means traces of this category are output, 0 means they are suppressed.)
sl@0
   134
	*/
sl@0
   135
	inline TInt Filter(TUint aCategory);
sl@0
   136
sl@0
   137
	/**
sl@0
   138
	Set the trace secondary trace filter for the specified UID.
sl@0
   139
sl@0
   140
	This method can not be used to disable a UID key if SetFilter2(TInt aGlobalFilter)
sl@0
   141
	has been used to set the filter to pass all traces. Such attempts result in a return
sl@0
   142
	code of KErrNotSupported.
sl@0
   143
sl@0
   144
	@param aUid   The UID to filter.
sl@0
   145
	@param aValue The new filter value for the UID.
sl@0
   146
				  1 means traces with this UID are output, 0 means they are suppressed.
sl@0
   147
				  Other values must not be used.
sl@0
   148
sl@0
   149
	@return The previous value of the filter for the UID, 0 or 1, if operation is successful.
sl@0
   150
			Otherwise, a negative number representing a system wide error code.
sl@0
   151
			(E.g. KErrNoMemory.)
sl@0
   152
	*/
sl@0
   153
	IMPORT_C TInt SetFilter2(TUint32 aUid, TBool aValue);
sl@0
   154
sl@0
   155
	/**
sl@0
   156
	Set the secondary trace filter to include only the specified UIDs.
sl@0
   157
	
sl@0
   158
	@param aUids    Pointer to array of UIDs.
sl@0
   159
	@param aNumUids Number of UID values pointer to by \a aUid.
sl@0
   160
sl@0
   161
	@return KErrNone on success.
sl@0
   162
			Otherwise, a negative number representing a system wide error code.
sl@0
   163
			(E.g. KErrNoMemory.)
sl@0
   164
	*/
sl@0
   165
	IMPORT_C TInt SetFilter2(const TUint32* aUids, TInt aNumUids);
sl@0
   166
sl@0
   167
	/**
sl@0
   168
	Set the secondary trace filter to pass or reject every trace.
sl@0
   169
	
sl@0
   170
	@param aGlobalFilter If 0, the secondary filter will reject
sl@0
   171
						 all traces; if 1, all traces are passed
sl@0
   172
						 by the filter.
sl@0
   173
						 Other values have no effect.
sl@0
   174
sl@0
   175
	@return The previous value of the global filter.
sl@0
   176
	*/
sl@0
   177
	IMPORT_C TInt SetFilter2(TInt aGlobalFilter);
sl@0
   178
sl@0
   179
	/**
sl@0
   180
	Get the contents of the secondary trace filter.
sl@0
   181
	
sl@0
   182
	@param [out] aUids   Pointer to array of UIDs contained in the secondary filter.
sl@0
   183
						Ownership of this array is passed to the caller of this
sl@0
   184
						function, which is then responsible for deleting it.
sl@0
   185
						If filter is empty, \a aUid equals zero.
sl@0
   186
	@param [out] aGlobalFilter	Set to 1 if the secondary filter passes all traces.
sl@0
   187
								Set to 0 if the secondary filter rejects all traces.
sl@0
   188
								Set to -1 if the secondary filter operates by UIDs contained in traces.
sl@0
   189
sl@0
   190
	@return Number of UIDs in returned array, if operation is successful.
sl@0
   191
			Otherwise, a negative number representing a system wide error code.
sl@0
   192
	*/
sl@0
   193
	IMPORT_C TInt Filter2(TUint32*& aUids, TInt& aGlobalFilter);
sl@0
   194
sl@0
   195
	/**
sl@0
   196
	Get pointer to as much contiguous trace data as is available.
sl@0
   197
	This data resides in the shared chunk DataChunk().
sl@0
   198
	The data returned will always be a whole number of trace records, i.e. trace records
sl@0
   199
	will not be split between successive calls to this method.
sl@0
   200
	Once the data is no loger required, DataUsed() must be called.
sl@0
   201
	This method can be called repeatedly to get more trace data. E.g.
sl@0
   202
	@code
sl@0
   203
		RBTrace trace;
sl@0
   204
		TInt error = trace.Open();
sl@0
   205
		if(error!=KErrNone)
sl@0
   206
			return error;
sl@0
   207
		const TInt KTraceDataBlockSize = 65536; // size of data we ideally want to process in one go
sl@0
   208
		TUint8* data;
sl@0
   209
		TInt size;
sl@0
   210
		do
sl@0
   211
			{
sl@0
   212
			while((size=trace.GetData(data))!=0)
sl@0
   213
				{
sl@0
   214
				ProcessTheTraceData(data,size);
sl@0
   215
				trace.DataUsed();
sl@0
   216
				}
sl@0
   217
			TRequestStatus waitStatus;
sl@0
   218
			trace.RequestData(waitStatus,KTraceDataBlockSize);
sl@0
   219
			User::WaitForRequest(waitStatus);
sl@0
   220
			error = waitStatus.Int();
sl@0
   221
			}
sl@0
   222
		while(error==KErrNone);
sl@0
   223
		trace.Close();
sl@0
   224
		return error;
sl@0
   225
	@endcode
sl@0
   226
sl@0
   227
	@param aData Pointer to the first byte of trace data.
sl@0
   228
	@return The number of bytes of trace data available at aData.
sl@0
   229
	@see DataChunk();
sl@0
   230
	*/
sl@0
   231
	IMPORT_C TInt GetData(TUint8*& aData);
sl@0
   232
sl@0
   233
	/**
sl@0
   234
	Remove from the trace buffer all of the data returned by the last call to GetData().
sl@0
   235
	*/
sl@0
   236
	IMPORT_C void DataUsed();
sl@0
   237
sl@0
   238
	/**
sl@0
   239
	Request notification when trace data becomes available.
sl@0
   240
	Only one outstanding request may be present at any one time.
sl@0
   241
	@param aStatus Request status to be complete with KErrNone once data becomes available.
sl@0
   242
	@param aSize The minimum number of bytes of trace data required.
sl@0
   243
				 This is intended to improve performance by only signalling the client once
sl@0
   244
				 a suitably large amount of trace data is available. However, this request
sl@0
   245
				 may complete before this amount of trace data is available, therefore a
sl@0
   246
				 client must be able to handle this situation.
sl@0
   247
				 If aSize is zero or negative, then the request completes as soon as any trace
sl@0
   248
				 data is available.
sl@0
   249
	@panic BTRACE 0 if a previous request is still pending
sl@0
   250
	*/
sl@0
   251
	IMPORT_C void RequestData(TRequestStatus& aStatus, TInt aSize);
sl@0
   252
sl@0
   253
	/**
sl@0
   254
	Cancel any previous RequestData(), completing it with KErrCancel.
sl@0
   255
	*/
sl@0
   256
	IMPORT_C void CancelRequestData();
sl@0
   257
sl@0
   258
	/**
sl@0
   259
	@internalTechnology
sl@0
   260
	*/
sl@0
   261
	TBool SetSerialPortOutput(TBool aEnable);
sl@0
   262
sl@0
   263
	/**
sl@0
   264
	Controls whether Timestamp2 field is added to trace record headers.
sl@0
   265
	*/
sl@0
   266
	IMPORT_C TBool SetTimestamp2Enabled(TBool aEnable);
sl@0
   267
sl@0
   268
#endif
sl@0
   269
sl@0
   270
	/**
sl@0
   271
	Enumeration of panic reasons for category 'BTRACE'.
sl@0
   272
	*/
sl@0
   273
	enum TPanic
sl@0
   274
		{
sl@0
   275
		ERequestAlreadyPending, /**< A call to RequestData() was made whist a request was already pending. */
sl@0
   276
		};
sl@0
   277
private:
sl@0
   278
	TInt OpenChunk();
sl@0
   279
	void CloseChunk();
sl@0
   280
	inline static const TDesC& Name();
sl@0
   281
sl@0
   282
	enum TControl
sl@0
   283
		{
sl@0
   284
		EOpenBuffer,
sl@0
   285
		EResizeBuffer,
sl@0
   286
		ESetFilter,
sl@0
   287
		ESetFilter2,
sl@0
   288
		ESetFilter2Array,
sl@0
   289
		ESetFilter2Global,
sl@0
   290
		EGetFilter2Part1,
sl@0
   291
		EGetFilter2Part2,
sl@0
   292
		ERequestData,
sl@0
   293
		ECancelRequestData,
sl@0
   294
		ESetSerialPortOutput,
sl@0
   295
		ESetTimestamp2Enabled,
sl@0
   296
		};
sl@0
   297
#ifndef __KERNEL_MODE__
sl@0
   298
	RChunk iDataChunk;
sl@0
   299
	TBTraceBuffer* iBuffer;
sl@0
   300
	TInt iLastGetDataSize;
sl@0
   301
	TUint32 iSpare[4];
sl@0
   302
#endif
sl@0
   303
	friend class DBTraceChannel;
sl@0
   304
	friend class DBTraceFactory;
sl@0
   305
	friend class RBTraceAdapter;
sl@0
   306
	};
sl@0
   307
sl@0
   308
#ifndef __KERNEL_MODE__
sl@0
   309
sl@0
   310
inline RChunk RBTrace::DataChunk()
sl@0
   311
	{
sl@0
   312
	return iDataChunk;
sl@0
   313
	}
sl@0
   314
sl@0
   315
inline TInt RBTrace::Filter(TUint aCategory)
sl@0
   316
	{
sl@0
   317
	return SetFilter(aCategory,-1);
sl@0
   318
	}
sl@0
   319
sl@0
   320
#endif // !__KERNEL_MODE__
sl@0
   321
sl@0
   322
inline const TDesC& RBTrace::Name()
sl@0
   323
	{
sl@0
   324
	_LIT(KBTraceName,"btrace");
sl@0
   325
	return KBTraceName;
sl@0
   326
	}
sl@0
   327
sl@0
   328
sl@0
   329
/**
sl@0
   330
@internalComponent
sl@0
   331
*/
sl@0
   332
class TBTraceBuffer
sl@0
   333
	{
sl@0
   334
private:
sl@0
   335
	TUint				iStart;
sl@0
   336
	TUint				iEnd;
sl@0
   337
	volatile TUint		iHead;
sl@0
   338
	volatile TUint		iTail;
sl@0
   339
	volatile TUint		iWrap;
sl@0
   340
	volatile TUint		iGeneration;
sl@0
   341
	volatile TUint		iMode;
sl@0
   342
	TUint				iRecordOffsets;
sl@0
   343
	TUint				iCopyBuffer;
sl@0
   344
	TUint				iCopyBufferSize;
sl@0
   345
private:
sl@0
   346
	TInt	Data(TUint& aData, TUint& aTail);
sl@0
   347
	TInt	Adjust(TUint aTail, TInt aSize);
sl@0
   348
	TInt	CopyData(TUint aData, TUint aTail, TInt aSize);
sl@0
   349
	TUint	UpdateTail(TUint32 aOld, TUint32 aNew);
sl@0
   350
	TInt	GetData(TUint8*& aData);
sl@0
   351
sl@0
   352
	friend class RBTrace;
sl@0
   353
	friend class TBTraceBufferK;
sl@0
   354
	friend class RBTraceAdapter;
sl@0
   355
	};
sl@0
   356
sl@0
   357
sl@0
   358
sl@0
   359
#endif