michael@0: /* michael@0: ******************************************************************************* michael@0: * michael@0: * Copyright (C) 2003-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************* michael@0: * file name: utrace.h michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 2003aug06 michael@0: * created by: Markus W. Scherer michael@0: * michael@0: * Definitions for ICU tracing/logging. michael@0: * michael@0: */ michael@0: michael@0: #ifndef __UTRACE_H__ michael@0: #define __UTRACE_H__ michael@0: michael@0: #include michael@0: #include "unicode/utypes.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C API: Definitions for ICU tracing/logging. michael@0: * michael@0: * This provides API for debugging the internals of ICU without the use of michael@0: * a traditional debugger. michael@0: * michael@0: * By default, tracing is disabled in ICU. If you need to debug ICU with michael@0: * tracing, please compile ICU with the --enable-tracing configure option. michael@0: */ michael@0: michael@0: U_CDECL_BEGIN michael@0: michael@0: /** michael@0: * Trace severity levels. Higher levels increase the verbosity of the trace output. michael@0: * @see utrace_setLevel michael@0: * @stable ICU 2.8 michael@0: */ michael@0: typedef enum UTraceLevel { michael@0: /** Disable all tracing @stable ICU 2.8*/ michael@0: UTRACE_OFF=-1, michael@0: /** Trace error conditions only @stable ICU 2.8*/ michael@0: UTRACE_ERROR=0, michael@0: /** Trace errors and warnings @stable ICU 2.8*/ michael@0: UTRACE_WARNING=3, michael@0: /** Trace opens and closes of ICU services @stable ICU 2.8*/ michael@0: UTRACE_OPEN_CLOSE=5, michael@0: /** Trace an intermediate number of ICU operations @stable ICU 2.8*/ michael@0: UTRACE_INFO=7, michael@0: /** Trace the maximum number of ICU operations @stable ICU 2.8*/ michael@0: UTRACE_VERBOSE=9 michael@0: } UTraceLevel; michael@0: michael@0: /** michael@0: * These are the ICU functions that will be traced when tracing is enabled. michael@0: * @stable ICU 2.8 michael@0: */ michael@0: typedef enum UTraceFunctionNumber { michael@0: UTRACE_FUNCTION_START=0, michael@0: UTRACE_U_INIT=UTRACE_FUNCTION_START, michael@0: UTRACE_U_CLEANUP, michael@0: UTRACE_FUNCTION_LIMIT, michael@0: michael@0: UTRACE_CONVERSION_START=0x1000, michael@0: UTRACE_UCNV_OPEN=UTRACE_CONVERSION_START, michael@0: UTRACE_UCNV_OPEN_PACKAGE, michael@0: UTRACE_UCNV_OPEN_ALGORITHMIC, michael@0: UTRACE_UCNV_CLONE, michael@0: UTRACE_UCNV_CLOSE, michael@0: UTRACE_UCNV_FLUSH_CACHE, michael@0: UTRACE_UCNV_LOAD, michael@0: UTRACE_UCNV_UNLOAD, michael@0: UTRACE_CONVERSION_LIMIT, michael@0: michael@0: UTRACE_COLLATION_START=0x2000, michael@0: UTRACE_UCOL_OPEN=UTRACE_COLLATION_START, michael@0: UTRACE_UCOL_CLOSE, michael@0: UTRACE_UCOL_STRCOLL, michael@0: UTRACE_UCOL_GET_SORTKEY, michael@0: UTRACE_UCOL_GETLOCALE, michael@0: UTRACE_UCOL_NEXTSORTKEYPART, michael@0: UTRACE_UCOL_STRCOLLITER, michael@0: UTRACE_UCOL_OPEN_FROM_SHORT_STRING, michael@0: UTRACE_UCOL_STRCOLLUTF8, /**< @stable ICU 50 */ michael@0: UTRACE_COLLATION_LIMIT michael@0: } UTraceFunctionNumber; michael@0: michael@0: /** michael@0: * Setter for the trace level. michael@0: * @param traceLevel A UTraceLevel value. michael@0: * @stable ICU 2.8 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: utrace_setLevel(int32_t traceLevel); michael@0: michael@0: /** michael@0: * Getter for the trace level. michael@0: * @return The UTraceLevel value being used by ICU. michael@0: * @stable ICU 2.8 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: utrace_getLevel(void); michael@0: michael@0: /* Trace function pointers types ----------------------------- */ michael@0: michael@0: /** michael@0: * Type signature for the trace function to be called when entering a function. michael@0: * @param context value supplied at the time the trace functions are set. michael@0: * @param fnNumber Enum value indicating the ICU function being entered. michael@0: * @stable ICU 2.8 michael@0: */ michael@0: typedef void U_CALLCONV michael@0: UTraceEntry(const void *context, int32_t fnNumber); michael@0: michael@0: /** michael@0: * Type signature for the trace function to be called when exiting from a function. michael@0: * @param context value supplied at the time the trace functions are set. michael@0: * @param fnNumber Enum value indicating the ICU function being exited. michael@0: * @param fmt A formatting string that describes the number and types michael@0: * of arguments included with the variable args. The fmt michael@0: * string has the same form as the utrace_vformat format michael@0: * string. michael@0: * @param args A variable arguments list. Contents are described by michael@0: * the fmt parameter. michael@0: * @see utrace_vformat michael@0: * @stable ICU 2.8 michael@0: */ michael@0: typedef void U_CALLCONV michael@0: UTraceExit(const void *context, int32_t fnNumber, michael@0: const char *fmt, va_list args); michael@0: michael@0: /** michael@0: * Type signature for the trace function to be called from within an ICU function michael@0: * to display data or messages. michael@0: * @param context value supplied at the time the trace functions are set. michael@0: * @param fnNumber Enum value indicating the ICU function being exited. michael@0: * @param level The current tracing level michael@0: * @param fmt A format string describing the tracing data that is supplied michael@0: * as variable args michael@0: * @param args The data being traced, passed as variable args. michael@0: * @stable ICU 2.8 michael@0: */ michael@0: typedef void U_CALLCONV michael@0: UTraceData(const void *context, int32_t fnNumber, int32_t level, michael@0: const char *fmt, va_list args); michael@0: michael@0: /** michael@0: * Set ICU Tracing functions. Installs application-provided tracing michael@0: * functions into ICU. After doing this, subsequent ICU operations michael@0: * will call back to the installed functions, providing a trace michael@0: * of the use of ICU. Passing a NULL pointer for a tracing function michael@0: * is allowed, and inhibits tracing action at points where that function michael@0: * would be called. michael@0: *

michael@0: * Tracing and Threads: Tracing functions are global to a process, and michael@0: * will be called in response to ICU operations performed by any michael@0: * thread. If tracing of an individual thread is desired, the michael@0: * tracing functions must themselves filter by checking that the michael@0: * current thread is the desired thread. michael@0: * michael@0: * @param context an uninterpretted pointer. Whatever is passed in michael@0: * here will in turn be passed to each of the tracing michael@0: * functions UTraceEntry, UTraceExit and UTraceData. michael@0: * ICU does not use or alter this pointer. michael@0: * @param e Callback function to be called on entry to a michael@0: * a traced ICU function. michael@0: * @param x Callback function to be called on exit from a michael@0: * traced ICU function. michael@0: * @param d Callback function to be called from within a michael@0: * traced ICU function, for the purpose of providing michael@0: * data to the trace. michael@0: * michael@0: * @stable ICU 2.8 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: utrace_setFunctions(const void *context, michael@0: UTraceEntry *e, UTraceExit *x, UTraceData *d); michael@0: michael@0: /** michael@0: * Get the currently installed ICU tracing functions. Note that a null function michael@0: * pointer will be returned if no trace function has been set. michael@0: * michael@0: * @param context The currently installed tracing context. michael@0: * @param e The currently installed UTraceEntry function. michael@0: * @param x The currently installed UTraceExit function. michael@0: * @param d The currently installed UTraceData function. michael@0: * @stable ICU 2.8 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: utrace_getFunctions(const void **context, michael@0: UTraceEntry **e, UTraceExit **x, UTraceData **d); michael@0: michael@0: michael@0: michael@0: /* michael@0: * michael@0: * ICU trace format string syntax michael@0: * michael@0: * Format Strings are passed to UTraceData functions, and define the michael@0: * number and types of the trace data being passed on each call. michael@0: * michael@0: * The UTraceData function, which is supplied by the application, michael@0: * not by ICU, can either forward the trace data (passed via michael@0: * varargs) and the format string back to ICU for formatting into michael@0: * a displayable string, or it can interpret the format itself, michael@0: * and do as it wishes with the trace data. michael@0: * michael@0: * michael@0: * Goals for the format string michael@0: * - basic data output michael@0: * - easy to use for trace programmer michael@0: * - sufficient provision for data types for trace output readability michael@0: * - well-defined types and binary portable APIs michael@0: * michael@0: * Non-goals michael@0: * - printf compatibility michael@0: * - fancy formatting michael@0: * - argument reordering and other internationalization features michael@0: * michael@0: * ICU trace format strings contain plain text with argument inserts, michael@0: * much like standard printf format strings. michael@0: * Each insert begins with a '%', then optionally contains a 'v', michael@0: * then exactly one type character. michael@0: * Two '%' in a row represent a '%' instead of an insert. michael@0: * The trace format strings need not have \n at the end. michael@0: * michael@0: * michael@0: * Types michael@0: * ----- michael@0: * michael@0: * Type characters: michael@0: * - c A char character in the default codepage. michael@0: * - s A NUL-terminated char * string in the default codepage. michael@0: * - S A UChar * string. Requires two params, (ptr, length). Length=-1 for nul term. michael@0: * - b A byte (8-bit integer). michael@0: * - h A 16-bit integer. Also a 16 bit Unicode code unit. michael@0: * - d A 32-bit integer. Also a 20 bit Unicode code point value. michael@0: * - l A 64-bit integer. michael@0: * - p A data pointer. michael@0: * michael@0: * Vectors michael@0: * ------- michael@0: * michael@0: * If the 'v' is not specified, then one item of the specified type michael@0: * is passed in. michael@0: * If the 'v' (for "vector") is specified, then a vector of items of the michael@0: * specified type is passed in, via a pointer to the first item michael@0: * and an int32_t value for the length of the vector. michael@0: * Length==-1 means zero or NUL termination. Works for vectors of all types. michael@0: * michael@0: * Note: %vS is a vector of (UChar *) strings. The strings must michael@0: * be nul terminated as there is no way to provide a michael@0: * separate length parameter for each string. The length michael@0: * parameter (required for all vectors) is the number of michael@0: * strings, not the length of the strings. michael@0: * michael@0: * Examples michael@0: * -------- michael@0: * michael@0: * These examples show the parameters that will be passed to an application's michael@0: * UTraceData() function for various formats. michael@0: * michael@0: * - the precise formatting is up to the application! michael@0: * - the examples use type casts for arguments only to _show_ the types of michael@0: * arguments without needing variable declarations in the examples; michael@0: * the type casts will not be necessary in actual code michael@0: * michael@0: * UTraceDataFunc(context, fnNumber, level, michael@0: * "There is a character %c in the string %s.", // Format String michael@0: * (char)c, (const char *)s); // varargs parameters michael@0: * -> There is a character 0x42 'B' in the string "Bravo". michael@0: * michael@0: * UTraceDataFunc(context, fnNumber, level, michael@0: * "Vector of bytes %vb vector of chars %vc", michael@0: * (const uint8_t *)bytes, (int32_t)bytesLength, michael@0: * (const char *)chars, (int32_t)charsLength); michael@0: * -> Vector of bytes michael@0: * 42 63 64 3f [4] michael@0: * vector of chars michael@0: * "Bcd?"[4] michael@0: * michael@0: * UTraceDataFunc(context, fnNumber, level, michael@0: * "An int32_t %d and a whole bunch of them %vd", michael@0: * (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength); michael@0: * -> An int32_t 0xfffffffb and a whole bunch of them michael@0: * fffffffb 00000005 0000010a [3] michael@0: * michael@0: */ michael@0: michael@0: michael@0: michael@0: /** michael@0: * Trace output Formatter. An application's UTraceData tracing functions may call michael@0: * back to this function to format the trace output in a michael@0: * human readable form. Note that a UTraceData function may choose michael@0: * to not format the data; it could, for example, save it in michael@0: * in the raw form it was received (more compact), leaving michael@0: * formatting for a later trace analyis tool. michael@0: * @param outBuf pointer to a buffer to receive the formatted output. Output michael@0: * will be nul terminated if there is space in the buffer - michael@0: * if the length of the requested output < the output buffer size. michael@0: * @param capacity Length of the output buffer. michael@0: * @param indent Number of spaces to indent the output. Intended to allow michael@0: * data displayed from nested functions to be indented for readability. michael@0: * @param fmt Format specification for the data to output michael@0: * @param args Data to be formatted. michael@0: * @return Length of formatted output, including the terminating NUL. michael@0: * If buffer capacity is insufficient, the required capacity is returned. michael@0: * @stable ICU 2.8 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: utrace_vformat(char *outBuf, int32_t capacity, michael@0: int32_t indent, const char *fmt, va_list args); michael@0: michael@0: /** michael@0: * Trace output Formatter. An application's UTraceData tracing functions may call michael@0: * this function to format any additional trace data, beyond that michael@0: * provided by default, in human readable form with the same michael@0: * formatting conventions used by utrace_vformat(). michael@0: * @param outBuf pointer to a buffer to receive the formatted output. Output michael@0: * will be nul terminated if there is space in the buffer - michael@0: * if the length of the requested output < the output buffer size. michael@0: * @param capacity Length of the output buffer. michael@0: * @param indent Number of spaces to indent the output. Intended to allow michael@0: * data displayed from nested functions to be indented for readability. michael@0: * @param fmt Format specification for the data to output michael@0: * @param ... Data to be formatted. michael@0: * @return Length of formatted output, including the terminating NUL. michael@0: * If buffer capacity is insufficient, the required capacity is returned. michael@0: * @stable ICU 2.8 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: utrace_format(char *outBuf, int32_t capacity, michael@0: int32_t indent, const char *fmt, ...); michael@0: michael@0: michael@0: michael@0: /* Trace function numbers --------------------------------------------------- */ michael@0: michael@0: /** michael@0: * Get the name of a function from its trace function number. michael@0: * michael@0: * @param fnNumber The trace number for an ICU function. michael@0: * @return The name string for the function. michael@0: * michael@0: * @see UTraceFunctionNumber michael@0: * @stable ICU 2.8 michael@0: */ michael@0: U_STABLE const char * U_EXPORT2 michael@0: utrace_functionName(int32_t fnNumber); michael@0: michael@0: U_CDECL_END michael@0: michael@0: #endif