sl@0: /** sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Trace API sl@0: * sl@0: * sl@0: */ sl@0: sl@0: /** sl@0: @file sl@0: @publishedPartner sl@0: @prototype sl@0: */ sl@0: sl@0: #ifndef OPENSYSTEMTRACE_INL sl@0: #define OPENSYSTEMTRACE_INL sl@0: sl@0: /** sl@0: OST maximum data length sl@0: The length of Component, Group and Trace IDs are subtracted from it sl@0: */ sl@0: const TUint KOstMaxDataLength = 512; sl@0: sl@0: /** sl@0: BTrace maximum data length is defined in e32btrace.h sl@0: The length of Component, Group and Trace IDs are subtracted from it sl@0: */ sl@0: const TUint KBTraceMaxDataLength = KMaxBTraceDataArray - 2 * sizeof(TUint32); sl@0: sl@0: /** sl@0: * The TraceName is an amalgamation of two separate identifiers: sl@0: * Group ID and Trace ID. sl@0: * sl@0: * These defines help get back the relevant bits from the sl@0: * TraceName. sl@0: * sl@0: * Note that whilst the Group ID is defined as 16 bits we are sl@0: * only taking the first 8 bits here. sl@0: */ sl@0: #define GROUPIDMASK 0x00ff0000 sl@0: #define GROUPIDSHIFT 16 sl@0: #define TRACEIDMASK 0x0000ffff sl@0: #define TRACEIDSHIFT 0 sl@0: #define EXTRACT_GROUP_ID(aTraceName) static_cast((aTraceName & GROUPIDMASK) >> GROUPIDSHIFT) sl@0: sl@0: /** sl@0: ---------------TTraceContext----------------------- sl@0: Define the context of a trace packet by setting its attributes. sl@0: sl@0: The Component ID is defaulted according to the FW_DEFAULT_COMPONENTID definition. sl@0: The HasThreadIdentification is defaulted to the FW_DEFAULT_HAS_THREAD_IDENTIFICATION definition. sl@0: The HasProgramCounter is defaulted to the FW_DEFAULT_HAS_PC definition. sl@0: sl@0: @deprecated sl@0: sl@0: @param aGroupId @see TGroupId sl@0: sl@0: */ sl@0: TTraceContext::TTraceContext(const TGroupId aGroupId) sl@0: :iComponentId(FW_DEFAULT_COMPONENTID), iGroupId(aGroupId), iHasThreadIdentification(FW_DEFAULT_HAS_THREAD_IDENTIFICATION), iHasProgramCounter(FW_DEFAULT_HAS_PC), iReserved1(0), iReserved2(0) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Define the context of a trace packet by setting its attributes. sl@0: * sl@0: * The HasThreadIdentification is defaulted to the FW_DEFAULT_HAS_THREAD_IDENTIFICATION definition. sl@0: * The HasProgramCounter is defaulted to the FW_DEFAULT_HAS_PC definition. sl@0: * sl@0: * sl@0: * @deprecated sl@0: * sl@0: * @param aComponentId @see TComponentId sl@0: * @param aGroupId @see TGroupId sl@0: */ sl@0: TTraceContext::TTraceContext(const TComponentId aComponentId, const TGroupId aGroupId) sl@0: :iComponentId(aComponentId), iGroupId(aGroupId), iHasThreadIdentification(FW_DEFAULT_HAS_THREAD_IDENTIFICATION), iHasProgramCounter(FW_DEFAULT_HAS_PC), iReserved1(0), iReserved2(0) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Define the context of a trace packet by setting its attributes. sl@0: * sl@0: * The Component ID is defaulted according to the FW_DEFAULT_COMPONENTID definition. sl@0: * sl@0: * @deprecated sl@0: * sl@0: * @param aGroupId @see TGroupId sl@0: * @param aHasThreadIdentification Set whether to add thread identification automatically in the trace packet. sl@0: * @param aHasProgramCounter Set whether to add PC (program counter) automatically in the trace packet. sl@0: */ sl@0: TTraceContext::TTraceContext(const TGroupId aGroupId, const THasThreadIdentification aHasThreadIdentification, const THasProgramCounter aHasProgramCounter) sl@0: :iComponentId(FW_DEFAULT_COMPONENTID), iGroupId(aGroupId), iHasThreadIdentification(aHasThreadIdentification), iHasProgramCounter(aHasProgramCounter), iReserved1(0), iReserved2(0) sl@0: { sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Define the context of a trace packet by setting its attributes. sl@0: * sl@0: * @deprecated sl@0: * sl@0: * @param aComponentId @see TComponentId sl@0: * @param aGroupId @see TGroupId sl@0: * @param aHasThreadIdentification Set whether to add thread identification automatically in the trace packet. sl@0: * @param aHasProgramCounter Set whether to add PC (program counter) automatically in the trace packet. sl@0: */ sl@0: TTraceContext::TTraceContext(const TComponentId aComponentId, const TGroupId aGroupId, const THasThreadIdentification aHasThreadIdentification, const THasProgramCounter aHasProgramCounter) sl@0: :iComponentId(aComponentId), iGroupId(aGroupId), iHasThreadIdentification(aHasThreadIdentification), iHasProgramCounter(aHasProgramCounter), iReserved1(0), iReserved2(0) sl@0: { sl@0: } sl@0: sl@0: //------------------ Trace ----------------------- sl@0: /** sl@0: Outputs a trace packet containing variable length data. sl@0: sl@0: If the specified data is too big to fit into a single sl@0: trace record a multipart trace is generated. sl@0: sl@0: @deprecated sl@0: sl@0: @param aContext Attributes of the trace point. sl@0: @param aTraceId A format identifier as specified by @see TTraceId sl@0: @param aData Additional data to add to trace packet. sl@0: Must be word aligned, i.e. a multiple of 4. sl@0: sl@0: @return The trace packet was/was not logged. sl@0: sl@0: @See BTrace::TMultipart sl@0: */ sl@0: template sl@0: TBool OstTrace(const TTraceContext& aContext, TTraceId aTraceId, const T& aData) sl@0: { sl@0: return OstTrace(aContext, aTraceId, &aData, sizeof(aData)); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Send N bytes of data sl@0: sl@0: @param aGroupId The Group ID of the trace packet. @see TGroupId sl@0: @param aEOstTrace BTrace sub-category. Value between 0 and 255. The meaning of this is dependent on the Category sl@0: @param aKOstTraceComponentID The Component ID of the trace sl@0: @param aTraceName The Trace ID of the trace sl@0: @param aPtr Address of addition data to add to trace. sl@0: @param aLength Number of bytes of additional data. sl@0: @return The trace packet was/was not logged. sl@0: */ sl@0: inline TBool OstSendNBytes( TUint8 aGroupId, TUint8 aEOstTrace, TUint32 aKOstTraceComponentID, TUint32 aTraceName, const TAny* aPtr, TInt aLength ) sl@0: { sl@0: TBool retval; sl@0: sl@0: if (aLength <= (TInt)KBTraceMaxDataLength) sl@0: { sl@0: // Data length is less than BTrace max. data length, so we can directly call BTraceFilteredContextN macro. sl@0: retval = BTraceFilteredContextN( aGroupId, aEOstTrace, aKOstTraceComponentID, aTraceName, aPtr, aLength ); sl@0: } sl@0: else sl@0: { sl@0: // Data length is greater than BTrace max. data length, so we need to call BTraceContextBig macro sl@0: TUint32 data[ KOstMaxDataLength / sizeof(TUint32)+ 1 ]; sl@0: sl@0: TUint8* ptr = (TUint8*)((TUint32*)data+1); // First word holds Trace ID sl@0: sl@0: // Write Trace ID to data part because BTraceFilteredContextBig macro takes one parameter less than BTraceFilteredContextN macro sl@0: data[0] = aTraceName; sl@0: sl@0: // If there is more data than we can show sl@0: if (aLength > (TInt)KOstMaxDataLength) sl@0: { sl@0: aLength = KOstMaxDataLength; sl@0: } sl@0: sl@0: // Copy the data to the buffer sl@0: memcpy( ptr, aPtr, aLength ); sl@0: ptr += aLength; sl@0: sl@0: // Fillers are written to get 32-bit alignment sl@0: TInt lengthAligned = ( aLength + (sizeof(TUint32)-1) ) & ~(sizeof(TUint32)-1); sl@0: while ( aLength++ < lengthAligned ) sl@0: { sl@0: *ptr++ = 0; sl@0: } sl@0: sl@0: retval = BTraceFilteredContextBig( aGroupId, aEOstTrace, aKOstTraceComponentID, data, lengthAligned + sizeof(TUint32)); sl@0: } sl@0: sl@0: return retval; sl@0: } sl@0: sl@0: sl@0: #endif //OPENSYSTEMTRACE_INL