Update contrib.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include <opensystemtrace.h>
18 #include "traceutils.h"
21 //Add the Doxygen macro so that Doxygen doesn't need to know about the SYMBIAN_TRACE_EXECUTABLE_IS_INCLUDED define.
22 //This allows doxygen to pick up the comments for the enabled implementation of the trace API.
24 #define SYMBIAN_TRACE_EXECUTABLE_IS_INCLUDED
30 * This method currently incorrectly returns 0, it should be returning the UID3 of the executable.
35 EXPORT_C TComponentId TTraceContext::DefaultComponentId()
42 * Check if thread identification will be added by default.
45 EXPORT_C THasThreadIdentification TTraceContext::HasThreadIdentification() const
47 return iHasThreadIdentification;
51 * Check if PC will be added by default.
54 EXPORT_C THasProgramCounter TTraceContext::HasProgramCounter() const
56 return iHasProgramCounter;
61 * Get the current group ID in form of classification (although classification is deprecated)
63 * @deprecated Use TTraceContext::GroupId() instead.
64 * @return The current group ID of the trace point context, in form of classification.
66 EXPORT_C TClassification TTraceContext::Classification() const
68 return static_cast<TClassification>(iGroupId);
72 * Get the current group ID
75 * @return The current group ID of the trace point context.
77 EXPORT_C TGroupId TTraceContext::GroupId() const
83 * Get the current Component Id
86 * @return The currently set Component Id
88 EXPORT_C TComponentId TTraceContext::ComponentId() const
94 //--------------------- OST compiled in ------------------------
95 #ifdef SYMBIAN_TRACE_EXECUTABLE_IS_INCLUDED
99 // --------- OstPrintf ------------
102 Prints a string by outputting a trace packet with the Trace ID KFormatPrintf.
104 If the specified string is too long to fit into a single trace packet
105 a multipart trace is generated.
109 @param aContext The trace packet context. @see TTraceContext
110 @param aDes The string. This can be of variable length.
112 @return The trace packet was/was not output.
114 @See BTrace::TMultipart
116 EXPORT_C TBool OstPrint(const TTraceContext& aContext, const TDesC8& aDes)
118 if(IsTraceActive(aContext))
121 return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, aDes.Ptr(), aDes.Size());
127 #ifdef __KERNEL_MODE__
130 Prints a formatted string in kernel mode only by outputting a trace packet with the Trace ID KFormatPrintf.
132 The function uses Kern::AppendFormat() to do the formatting.
134 Although it is safe to call this function from an ISR, it polls the output
135 serial port and may take a long time to complete, invalidating any
138 If called from an ISR, it is possible for output text to be intermingled
139 with other output text if one set of output interrupts or preempts another.
141 Some of the formatting options may not work inside an ISR.
143 Be careful not to use a string that is too long to fit onto the stack.
144 If the specified string is too long to fit into a single trace packet
145 a multipart trace is generated.
149 @param aContext The trace packet context. @see TTraceContext
150 @param aFmt The format string. This must not be longer than 256 characters.
151 @param ... A variable number of arguments to be converted to text as dictated
152 by the format string.
154 @return The trace packet was/was not output.
156 @pre Calling thread can either be in a critical section or not.
157 @pre Interrupts must be enabled.
158 @pre Kernel must be unlocked
159 @pre Call in any context.
160 @pre Suitable for use in a device driver
162 @see Kern::AppendFormat()
163 @See BTrace::TMultipart
166 EXPORT_C TBool OstPrintf(const TTraceContext& aContext, const char* aFmt, ...)
168 if(IsTraceActive(aContext))
171 TBuf8<KMaxPrintfSize> buf;
174 Kern::AppendFormat(buf,aFmt,list);
175 return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, buf.Ptr(), buf.Size());
181 Prints a formatted string by outputting a trace packet with the Trace ID KFormatPrintf.
183 If the specified string is too long to fit into a single trace packet
184 a multipart trace is generated.
188 @param aContext The trace packet context. @see TTraceContext
189 @param aFmt The format string. This must not be longer than 256 characters.
190 @param ... A variable number of arguments to be converted to text as dictated
191 by the format string.
193 @return The trace packet was/was not output.
195 @See BTrace::TMultipart
197 EXPORT_C TBool OstPrintf(const TTraceContext& aContext, TRefByValue<const TDesC8> aFmt,...)
199 if(IsTraceActive(aContext))
202 TBuf8<KMaxPrintfSize> buf;
206 Kern::AppendFormat(buf,(char*)fmt.Ptr(),list);
207 return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, buf.Ptr(), buf.Size());
212 #endif // __KERNEL_MODE__
213 #ifndef __KERNEL_MODE__
216 Prints a formatted string by outputting a trace packet with the Trace ID KFormatPrintf.
219 If the specified string is too long to fit into a single trace packet
220 a multipart trace is generated.
224 @param aContext The trace packet context. @see TTraceContext
225 @param aFmt The format string. This must not be longer than 256 characters.
226 @param ... A variable number of arguments to be converted to text as dictated
227 by the format string.
229 @return The trace packet was/was not output.
231 @See BTrace::TMultipart
233 EXPORT_C TBool OstPrintf(const TTraceContext& aContext, const char* aFmt, ...)
235 if(IsTraceActive(aContext))
238 TTruncateOverflow8 overflow;
241 TPtrC8 fmt((const TText8*)aFmt);
242 TBuf8<KMaxPrintfSize> buf;
243 // coverity[uninit_use_in_call : FALSE]
244 buf.AppendFormatList(fmt,list,&overflow);
245 return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, buf.Ptr(), buf.Size());
251 Prints a formatted string by outputting a trace packet with the Trace ID KFormatPrintf.
253 If the specified string is too long to fit into a single trace packet
254 a multipart trace is generated.
258 @param aContext The trace packet context. @see TTraceContext
259 @param aFmt The format string. This must not be longer than 256 characters.
260 @param ... A variable number of arguments to be converted to text as dictated
261 by the format string.
263 @return The trace packet was/was not output.
265 @See BTrace::TMultipart
267 EXPORT_C TBool OstPrintf(const TTraceContext& aContext, TRefByValue<const TDesC8> aFmt,...)
269 if(IsTraceActive(aContext))
272 TTruncateOverflow8 overflow;
275 TBuf8<KMaxPrintfSize> buf;
276 // coverity[uninit_use_in_call : FALSE]
277 buf.AppendFormatList(aFmt,list,&overflow);
278 return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, buf.Ptr(), buf.Size());
284 Prints a formatted string by outputting a trace packet with the Trace ID
285 KFormatPrintfUnicode for unicode strings and KFormatPrintf for other strings.
287 If the specified string is too long to fit into a single trace packet
288 a multipart trace is generated.
292 @param aContext The trace packet context. @see TTraceContext
293 @param aFmt The format string. This must not be longer than 256 characters.
294 @param ... A variable number of arguments to be converted to text as dictated
295 by the format string.
297 @return The trace packet was/was not output.
299 @See BTrace::TMultipart
301 EXPORT_C TBool OstPrintf(const TTraceContext& aContext, TRefByValue<const TDesC16> aFmt,...)
303 if(IsTraceActive(aContext))
306 TTruncateOverflow16 overflow;
309 TBuf<KMaxPrintfSize> buf;
310 // coverity[uninit_use_in_call : FALSE]
311 buf.AppendFormatList(aFmt,list,&overflow);
313 TPtr8 p(buf.Collapse());
314 return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), myPc, KFormatPrintf, buf.PtrZ(), p.Size());
316 return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintfUnicode, buf.PtrZ(), buf.Size());
324 Prints a string by outputting a trace packet with the Trace ID KFormatPrintfUnicode
326 If the specified string is too long to fit into a single trace packet
327 a multipart trace is generated.
331 @param aContext The trace packet context. @see TTraceContext
332 @param aDes The string. This must not be longer than 256 characters.
334 @return The trace packet was/was not output.
336 @See BTrace::TMultipart
338 EXPORT_C TBool OstPrint(const TTraceContext& aContext, const TDesC16& aDes)
340 if(IsTraceActive(aContext))
343 return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintfUnicode, aDes.Ptr(), aDes.Size());
347 #endif // __KERNEL_MODE__
350 // --------- trace ------------
353 Outputs a trace packet containing no payload data.
357 @param aContext The trace packet context. @see TTraceContext
358 @param aTraceId The trace point identifier as specified by @see TTraceId
360 @return The trace packet was/was not output.
362 EXPORT_C TBool OstTrace(const TTraceContext& aContext, TTraceId aTraceId)
365 return OST_SECONDARY_0(aContext.GroupId(),aContext.ComponentId(),aContext.HasThreadIdentification(),aContext.HasProgramCounter(), pc, aTraceId);
369 Outputs a trace packet containing 4 bytes of data.
371 This method is likely to be deprecated soon.
373 @param aContext The trace packet context. @see TTraceContext
374 @param aTraceId The trace point identifier as specified by @see TTraceId
375 @param aData 4 bytes of data
377 @return The trace packet was/was not output.
379 EXPORT_C TBool OstTrace(const TTraceContext& aContext, TTraceId aTraceId, TUint32 aData)
382 return OST_SECONDARY_1(aContext.GroupId(),aContext.ComponentId(),aContext.HasThreadIdentification(),aContext.HasProgramCounter(),pc,aTraceId,aData);
386 Outputs a trace packet containing 8 bytes of data.
390 @param aContext The trace packet context. @see TTraceContext
391 @param aTraceId The trace point identifier as specified by @see TTraceId
392 @param aData1 4 bytes of data
393 @param aData2 4 bytes of data
395 @return The trace packet was/was not output.
397 EXPORT_C TBool OstTrace(const TTraceContext& aContext, TTraceId aTraceId, TUint32 aData1, TUint32 aData2)
403 return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, aTraceId, &packet, 8);
407 Outputs a trace packet containing variable length data.
409 If the specified data is too big to fit into a single
410 trace packet a multipart trace is generated.
414 @param aContext The trace packet context. @see TTraceContext
415 @param aTraceId The trace point identifier as specified by @see TTraceId
416 @param aData Address of additional data to add to trace packet.
417 Must be word aligned, i.e. a multiple of 4.
418 @param aSize Number of bytes of additional data.
420 @return The trace packet was/was not output.
422 @See BTrace::TMultipart
424 EXPORT_C TBool OstTrace(const TTraceContext& aContext, TTraceId aTraceId, const TAny* aData, TInt aSize)
426 if(IsTraceActive(aContext))
429 return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, aTraceId, aData, aSize);
435 Outputs a trace packet containing 4 bytes of data.
439 @param aContext The trace packet context. @see TTraceContext
440 @param aTraceId The trace point identifier as specified by @see TTraceId
441 @param aData 4 bytes of data
443 @return The trace packet was/was not output.
445 EXPORT_C TBool OstTrace(const TTraceContext& aContext, const TTraceId aTraceId, const TUint16 aData)
448 return OST_SECONDARY_1(aContext.GroupId(),aContext.ComponentId(),aContext.HasThreadIdentification(),aContext.HasProgramCounter(),pc,aTraceId,aData);
452 Outputs a trace packet containing 4 bytes of data.
456 @param aContext The trace packet context. @see TTraceContext
457 @param aTraceId The trace point identifier as specified by @see TTraceId
458 @param aData 4 bytes of data
460 @return The trace packet was/was not output.
462 EXPORT_C TBool OstTrace(const TTraceContext& aContext, const TTraceId aTraceId, const TUint8 aData)
465 return OST_SECONDARY_1(aContext.GroupId(),aContext.ComponentId(),aContext.HasThreadIdentification(),aContext.HasProgramCounter(),pc,aTraceId,aData);
468 #ifndef __KERNEL_MODE__
470 Outputs a trace packet containing variable length data.
472 If the specified data is too big to fit into a single
473 trace record a multipart trace is generated.
477 @param aContext Attributes of the trace point.
478 @param aTraceId The trace point identifier as specified by @see TTraceId
479 @param aData Additional data to add to trace packet.
480 Must be word aligned, i.e. a multiple of 4.
482 @return The trace packet was/was not logged.
484 @See BTrace::TMultipart
486 EXPORT_C TBool OstTrace(const TTraceContext& aContext, const TTraceId aTraceId, const TDesC16& aData)
488 if(IsTraceActive(aContext))
491 return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, aTraceId, aData.Ptr(), aData.Size());
495 #endif //__KERNEL_MODE__
498 Outputs a trace packet containing variable length data.
500 If the specified data is too big to fit into a single
501 trace record a multipart trace is generated.
505 @param aContext Attributes of the trace point.
506 @param aTraceId The trace point identifier as specified by @see TTraceId
507 @param aData Additional data to add to trace packet.
508 Must be word aligned, i.e. a multiple of 4.
510 @return The trace packet was/was not logged.
512 @See BTrace::TMultipart
514 EXPORT_C TBool OstTrace(const TTraceContext& aContext, const TTraceId aTraceId, const TDesC8& aData)
516 if(IsTraceActive(aContext))
519 return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, aTraceId, aData.Ptr(), aData.Size());
527 * Check whether a trace packet would be traced or not.
531 * @param aContext The context of the trace packet(s) to be checked.
532 * @return Returns whether the trace packet would be traced or not.
533 * Note: The value should never be stored since the filters can be changed without warning.
535 EXPORT_C TBool IsTraceActive(const TTraceContext& aContext)
537 return BTrace::CheckFilter2(aContext.GroupId(), aContext.ComponentId());
540 //--------------------- OST compiled out ------------------------
542 #else //SYMBIAN_TRACE_EXECUTABLE_IS_INCLUDED
545 EXPORT_C TBool OstPrintf(const TTraceContext&, const char*, ...) { return EFalse; }
546 EXPORT_C TBool OstPrint(const TTraceContext&, const TDesC8&) { return EFalse; }
547 EXPORT_C TBool OstPrintf(const TTraceContext&, TRefByValue<const TDesC8> ,...) { return EFalse; }
548 #ifndef __KERNEL_MODE__
549 EXPORT_C TBool OstPrintf(const TTraceContext&, TRefByValue<const TDesC16>,...) { return EFalse; }
550 EXPORT_C TBool OstPrint(const TTraceContext&, const TDesC16&) { return EFalse; }
551 #endif //__KERNEL_MODE__
554 EXPORT_C TBool OstTrace(const TTraceContext&, TTraceId) { return EFalse; }
555 EXPORT_C TBool OstTrace(const TTraceContext&, TTraceId, TUint32) { return EFalse; }
556 EXPORT_C TBool OstTrace(const TTraceContext&, TTraceId, TUint32, TUint32) { return EFalse; }
557 EXPORT_C TBool OstTrace(const TTraceContext&, TTraceId, const TAny*, TInt) { return EFalse; }
559 EXPORT_C TBool OstTrace(const TTraceContext&, const TTraceId, const TUint8) { return EFalse; }
560 EXPORT_C TBool OstTrace(const TTraceContext&, const TTraceId, const TUint16) { return EFalse; }
561 EXPORT_C TBool OstTrace(const TTraceContext&, const TTraceId, const TDesC8&) { return EFalse; }
562 #ifndef __KERNEL_MODE__
563 EXPORT_C TBool OstTrace(const TTraceContext&, const TTraceId, const TDesC16&) { return EFalse; }
565 EXPORT_C TBool IsTraceActive(const TTraceContext&) { return EFalse; }
568 #endif //SYMBIAN_TRACE_EXECUTABLE_IS_INCLUDED