2 *******************************************************************************
4 * Copyright (C) 2003-2006, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
10 * tab size: 8 (not used)
13 * created on: 2003aug06
14 * created by: Markus W. Scherer
16 * Definitions for ICU tracing/logging.
24 #include "unicode/utypes.h"
28 * \brief C API: Definitions for ICU tracing/logging.
34 * Trace severity levels. Higher levels increase the verbosity of the trace output.
35 * @see utrace_setLevel
38 typedef enum UTraceLevel
{
39 /** Disable all tracing @stable ICU 2.8*/
41 /** Trace error conditions only @stable ICU 2.8*/
43 /** Trace errors and warnings @stable ICU 2.8*/
45 /** Trace opens and closes of ICU services @stable ICU 2.8*/
47 /** Trace an intermediate number of ICU operations @stable ICU 2.8*/
49 /** Trace the maximum number of ICU operations @stable ICU 2.8*/
54 * These are the ICU functions that will be traced when tracing is enabled.
57 typedef enum UTraceFunctionNumber
{
58 UTRACE_FUNCTION_START
=0,
59 UTRACE_U_INIT
=UTRACE_FUNCTION_START
,
61 UTRACE_FUNCTION_LIMIT
,
63 UTRACE_CONVERSION_START
=0x1000,
64 UTRACE_UCNV_OPEN
=UTRACE_CONVERSION_START
,
65 UTRACE_UCNV_OPEN_PACKAGE
,
66 UTRACE_UCNV_OPEN_ALGORITHMIC
,
69 UTRACE_UCNV_FLUSH_CACHE
,
72 UTRACE_CONVERSION_LIMIT
,
74 UTRACE_COLLATION_START
=0x2000,
75 UTRACE_UCOL_OPEN
=UTRACE_COLLATION_START
,
78 UTRACE_UCOL_GET_SORTKEY
,
79 UTRACE_UCOL_GETLOCALE
,
80 UTRACE_UCOL_NEXTSORTKEYPART
,
81 UTRACE_UCOL_STRCOLLITER
,
82 UTRACE_UCOL_OPEN_FROM_SHORT_STRING
,
83 UTRACE_COLLATION_LIMIT
84 } UTraceFunctionNumber
;
87 * Setter for the trace level.
88 * @param traceLevel A UTraceLevel value.
91 U_STABLE
void U_EXPORT2
92 utrace_setLevel(int32_t traceLevel
);
95 * Getter for the trace level.
96 * @return The UTraceLevel value being used by ICU.
99 U_STABLE
int32_t U_EXPORT2
100 utrace_getLevel(void);
102 /* Trace function pointers types ----------------------------- */
105 * Type signature for the trace function to be called when entering a function.
106 * @param context value supplied at the time the trace functions are set.
107 * @param fnNumber Enum value indicating the ICU function being entered.
110 typedef void U_CALLCONV
111 UTraceEntry(const void *context
, int32_t fnNumber
);
114 * Type signature for the trace function to be called when exiting from a function.
115 * @param context value supplied at the time the trace functions are set.
116 * @param fnNumber Enum value indicating the ICU function being exited.
117 * @param fmt A formatting string that describes the number and types
118 * of arguments included with the variable args. The fmt
119 * string has the same form as the utrace_vformat format
121 * @param args A variable arguments list. Contents are described by
123 * @see utrace_vformat
126 typedef void U_CALLCONV
127 UTraceExit(const void *context
, int32_t fnNumber
,
128 const char *fmt
, va_list args
);
131 * Type signature for the trace function to be called from within an ICU function
132 * to display data or messages.
133 * @param context value supplied at the time the trace functions are set.
134 * @param fnNumber Enum value indicating the ICU function being exited.
135 * @param level The current tracing level
136 * @param fmt A format string describing the tracing data that is supplied
138 * @param args The data being traced, passed as variable args.
141 typedef void U_CALLCONV
142 UTraceData(const void *context
, int32_t fnNumber
, int32_t level
,
143 const char *fmt
, va_list args
);
146 * Set ICU Tracing functions. Installs application-provided tracing
147 * functions into ICU. After doing this, subsequent ICU operations
148 * will call back to the installed functions, providing a trace
149 * of the use of ICU. Passing a NULL pointer for a tracing function
150 * is allowed, and inhibits tracing action at points where that function
153 * Tracing and Threads: Tracing functions are global to a process, and
154 * will be called in response to ICU operations performed by any
155 * thread. If tracing of an individual thread is desired, the
156 * tracing functions must themselves filter by checking that the
157 * current thread is the desired thread.
159 * @param context an uninterpretted pointer. Whatever is passed in
160 * here will in turn be passed to each of the tracing
161 * functions UTraceEntry, UTraceExit and UTraceData.
162 * ICU does not use or alter this pointer.
163 * @param e Callback function to be called on entry to a
164 * a traced ICU function.
165 * @param x Callback function to be called on exit from a
166 * traced ICU function.
167 * @param d Callback function to be called from within a
168 * traced ICU function, for the purpose of providing
173 U_STABLE
void U_EXPORT2
174 utrace_setFunctions(const void *context
,
175 UTraceEntry
*e
, UTraceExit
*x
, UTraceData
*d
);
178 * Get the currently installed ICU tracing functions. Note that a null function
179 * pointer will be returned if no trace function has been set.
181 * @param context The currently installed tracing context.
182 * @param e The currently installed UTraceEntry function.
183 * @param x The currently installed UTraceExit function.
184 * @param d The currently installed UTraceData function.
187 U_STABLE
void U_EXPORT2
188 utrace_getFunctions(const void **context
,
189 UTraceEntry
**e
, UTraceExit
**x
, UTraceData
**d
);
195 * ICU trace format string syntax
197 * Format Strings are passed to UTraceData functions, and define the
198 * number and types of the trace data being passed on each call.
200 * The UTraceData function, which is supplied by the application,
201 * not by ICU, can either forward the trace data (passed via
202 * varargs) and the format string back to ICU for formatting into
203 * a displayable string, or it can interpret the format itself,
204 * and do as it wishes with the trace data.
207 * Goals for the format string
208 * - basic data output
209 * - easy to use for trace programmer
210 * - sufficient provision for data types for trace output readability
211 * - well-defined types and binary portable APIs
214 * - printf compatibility
216 * - argument reordering and other internationalization features
218 * ICU trace format strings contain plain text with argument inserts,
219 * much like standard printf format strings.
220 * Each insert begins with a '%', then optionally contains a 'v',
221 * then exactly one type character.
222 * Two '%' in a row represent a '%' instead of an insert.
223 * The trace format strings need not have \n at the end.
230 * - c A char character in the default codepage.
231 * - s A NUL-terminated char * string in the default codepage.
232 * - S A UChar * string. Requires two params, (ptr, length). Length=-1 for nul term.
233 * - b A byte (8-bit integer).
234 * - h A 16-bit integer. Also a 16 bit Unicode code unit.
235 * - d A 32-bit integer. Also a 20 bit Unicode code point value.
236 * - l A 64-bit integer.
237 * - p A data pointer.
242 * If the 'v' is not specified, then one item of the specified type
244 * If the 'v' (for "vector") is specified, then a vector of items of the
245 * specified type is passed in, via a pointer to the first item
246 * and an int32_t value for the length of the vector.
247 * Length==-1 means zero or NUL termination. Works for vectors of all types.
249 * Note: %vS is a vector of (UChar *) strings. The strings must
250 * be nul terminated as there is no way to provide a
251 * separate length parameter for each string. The length
252 * parameter (required for all vectors) is the number of
253 * strings, not the length of the strings.
258 * These examples show the parameters that will be passed to an application's
259 * UTraceData() function for various formats.
261 * - the precise formatting is up to the application!
262 * - the examples use type casts for arguments only to _show_ the types of
263 * arguments without needing variable declarations in the examples;
264 * the type casts will not be necessary in actual code
266 * UTraceDataFunc(context, fnNumber, level,
267 * "There is a character %c in the string %s.", // Format String
268 * (char)c, (const char *)s); // varargs parameters
269 * -> There is a character 0x42 'B' in the string "Bravo".
271 * UTraceDataFunc(context, fnNumber, level,
272 * "Vector of bytes %vb vector of chars %vc",
273 * (const uint8_t *)bytes, (int32_t)bytesLength,
274 * (const char *)chars, (int32_t)charsLength);
280 * UTraceDataFunc(context, fnNumber, level,
281 * "An int32_t %d and a whole bunch of them %vd",
282 * (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength);
283 * -> An int32_t 0xfffffffb and a whole bunch of them
284 * fffffffb 00000005 0000010a [3]
291 * Trace output Formatter. An application's UTraceData tracing functions may call
292 * back to this function to format the trace output in a
293 * human readable form. Note that a UTraceData function may choose
294 * to not format the data; it could, for example, save it in
295 * in the raw form it was received (more compact), leaving
296 * formatting for a later trace analyis tool.
297 * @param outBuf pointer to a buffer to receive the formatted output. Output
298 * will be nul terminated if there is space in the buffer -
299 * if the length of the requested output < the output buffer size.
300 * @param capacity Length of the output buffer.
301 * @param indent Number of spaces to indent the output. Intended to allow
302 * data displayed from nested functions to be indented for readability.
303 * @param fmt Format specification for the data to output
304 * @param args Data to be formatted.
305 * @return Length of formatted output, including the terminating NUL.
306 * If buffer capacity is insufficient, the required capacity is returned.
309 U_STABLE
int32_t U_EXPORT2
310 utrace_vformat(char *outBuf
, int32_t capacity
,
311 int32_t indent
, const char *fmt
, va_list args
);
314 * Trace output Formatter. An application's UTraceData tracing functions may call
315 * this function to format any additional trace data, beyond that
316 * provided by default, in human readable form with the same
317 * formatting conventions used by utrace_vformat().
318 * @param outBuf pointer to a buffer to receive the formatted output. Output
319 * will be nul terminated if there is space in the buffer -
320 * if the length of the requested output < the output buffer size.
321 * @param capacity Length of the output buffer.
322 * @param indent Number of spaces to indent the output. Intended to allow
323 * data displayed from nested functions to be indented for readability.
324 * @param fmt Format specification for the data to output
325 * @param ... Data to be formatted.
326 * @return Length of formatted output, including the terminating NUL.
327 * If buffer capacity is insufficient, the required capacity is returned.
330 U_STABLE
int32_t U_EXPORT2
331 utrace_format(char *outBuf
, int32_t capacity
,
332 int32_t indent
, const char *fmt
, ...);
336 /* Trace function numbers --------------------------------------------------- */
339 * Get the name of a function from its trace function number.
341 * @param fnNumber The trace number for an ICU function.
342 * @return The name string for the function.
344 * @see UTraceFunctionNumber
347 U_STABLE
const char * U_EXPORT2
348 utrace_functionName(int32_t fnNumber
);