utrace.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. *******************************************************************************
  3. *
  4. * Copyright (C) 2003-2013, International Business Machines
  5. * Corporation and others. All Rights Reserved.
  6. *
  7. *******************************************************************************
  8. * file name: utrace.h
  9. * encoding: US-ASCII
  10. * tab size: 8 (not used)
  11. * indentation:4
  12. *
  13. * created on: 2003aug06
  14. * created by: Markus W. Scherer
  15. *
  16. * Definitions for ICU tracing/logging.
  17. *
  18. */
  19. #ifndef __UTRACE_H__
  20. #define __UTRACE_H__
  21. #include <stdarg.h>
  22. #include "unicode/utypes.h"
  23. /**
  24. * \file
  25. * \brief C API: Definitions for ICU tracing/logging.
  26. *
  27. * This provides API for debugging the internals of ICU without the use of
  28. * a traditional debugger.
  29. *
  30. * By default, tracing is disabled in ICU. If you need to debug ICU with
  31. * tracing, please compile ICU with the --enable-tracing configure option.
  32. */
  33. U_CDECL_BEGIN
  34. /**
  35. * Trace severity levels. Higher levels increase the verbosity of the trace output.
  36. * @see utrace_setLevel
  37. * @stable ICU 2.8
  38. */
  39. typedef enum UTraceLevel {
  40. /** Disable all tracing @stable ICU 2.8*/
  41. UTRACE_OFF=-1,
  42. /** Trace error conditions only @stable ICU 2.8*/
  43. UTRACE_ERROR=0,
  44. /** Trace errors and warnings @stable ICU 2.8*/
  45. UTRACE_WARNING=3,
  46. /** Trace opens and closes of ICU services @stable ICU 2.8*/
  47. UTRACE_OPEN_CLOSE=5,
  48. /** Trace an intermediate number of ICU operations @stable ICU 2.8*/
  49. UTRACE_INFO=7,
  50. /** Trace the maximum number of ICU operations @stable ICU 2.8*/
  51. UTRACE_VERBOSE=9
  52. } UTraceLevel;
  53. /**
  54. * These are the ICU functions that will be traced when tracing is enabled.
  55. * @stable ICU 2.8
  56. */
  57. typedef enum UTraceFunctionNumber {
  58. UTRACE_FUNCTION_START=0,
  59. UTRACE_U_INIT=UTRACE_FUNCTION_START,
  60. UTRACE_U_CLEANUP,
  61. UTRACE_FUNCTION_LIMIT,
  62. UTRACE_CONVERSION_START=0x1000,
  63. UTRACE_UCNV_OPEN=UTRACE_CONVERSION_START,
  64. UTRACE_UCNV_OPEN_PACKAGE,
  65. UTRACE_UCNV_OPEN_ALGORITHMIC,
  66. UTRACE_UCNV_CLONE,
  67. UTRACE_UCNV_CLOSE,
  68. UTRACE_UCNV_FLUSH_CACHE,
  69. UTRACE_UCNV_LOAD,
  70. UTRACE_UCNV_UNLOAD,
  71. UTRACE_CONVERSION_LIMIT,
  72. UTRACE_COLLATION_START=0x2000,
  73. UTRACE_UCOL_OPEN=UTRACE_COLLATION_START,
  74. UTRACE_UCOL_CLOSE,
  75. UTRACE_UCOL_STRCOLL,
  76. UTRACE_UCOL_GET_SORTKEY,
  77. UTRACE_UCOL_GETLOCALE,
  78. UTRACE_UCOL_NEXTSORTKEYPART,
  79. UTRACE_UCOL_STRCOLLITER,
  80. UTRACE_UCOL_OPEN_FROM_SHORT_STRING,
  81. UTRACE_UCOL_STRCOLLUTF8, /**< @stable ICU 50 */
  82. UTRACE_COLLATION_LIMIT
  83. } UTraceFunctionNumber;
  84. /**
  85. * Setter for the trace level.
  86. * @param traceLevel A UTraceLevel value.
  87. * @stable ICU 2.8
  88. */
  89. U_STABLE void U_EXPORT2
  90. utrace_setLevel(int32_t traceLevel);
  91. /**
  92. * Getter for the trace level.
  93. * @return The UTraceLevel value being used by ICU.
  94. * @stable ICU 2.8
  95. */
  96. U_STABLE int32_t U_EXPORT2
  97. utrace_getLevel(void);
  98. /* Trace function pointers types ----------------------------- */
  99. /**
  100. * Type signature for the trace function to be called when entering a function.
  101. * @param context value supplied at the time the trace functions are set.
  102. * @param fnNumber Enum value indicating the ICU function being entered.
  103. * @stable ICU 2.8
  104. */
  105. typedef void U_CALLCONV
  106. UTraceEntry(const void *context, int32_t fnNumber);
  107. /**
  108. * Type signature for the trace function to be called when exiting from a function.
  109. * @param context value supplied at the time the trace functions are set.
  110. * @param fnNumber Enum value indicating the ICU function being exited.
  111. * @param fmt A formatting string that describes the number and types
  112. * of arguments included with the variable args. The fmt
  113. * string has the same form as the utrace_vformat format
  114. * string.
  115. * @param args A variable arguments list. Contents are described by
  116. * the fmt parameter.
  117. * @see utrace_vformat
  118. * @stable ICU 2.8
  119. */
  120. typedef void U_CALLCONV
  121. UTraceExit(const void *context, int32_t fnNumber,
  122. const char *fmt, va_list args);
  123. /**
  124. * Type signature for the trace function to be called from within an ICU function
  125. * to display data or messages.
  126. * @param context value supplied at the time the trace functions are set.
  127. * @param fnNumber Enum value indicating the ICU function being exited.
  128. * @param level The current tracing level
  129. * @param fmt A format string describing the tracing data that is supplied
  130. * as variable args
  131. * @param args The data being traced, passed as variable args.
  132. * @stable ICU 2.8
  133. */
  134. typedef void U_CALLCONV
  135. UTraceData(const void *context, int32_t fnNumber, int32_t level,
  136. const char *fmt, va_list args);
  137. /**
  138. * Set ICU Tracing functions. Installs application-provided tracing
  139. * functions into ICU. After doing this, subsequent ICU operations
  140. * will call back to the installed functions, providing a trace
  141. * of the use of ICU. Passing a NULL pointer for a tracing function
  142. * is allowed, and inhibits tracing action at points where that function
  143. * would be called.
  144. * <p>
  145. * Tracing and Threads: Tracing functions are global to a process, and
  146. * will be called in response to ICU operations performed by any
  147. * thread. If tracing of an individual thread is desired, the
  148. * tracing functions must themselves filter by checking that the
  149. * current thread is the desired thread.
  150. *
  151. * @param context an uninterpretted pointer. Whatever is passed in
  152. * here will in turn be passed to each of the tracing
  153. * functions UTraceEntry, UTraceExit and UTraceData.
  154. * ICU does not use or alter this pointer.
  155. * @param e Callback function to be called on entry to a
  156. * a traced ICU function.
  157. * @param x Callback function to be called on exit from a
  158. * traced ICU function.
  159. * @param d Callback function to be called from within a
  160. * traced ICU function, for the purpose of providing
  161. * data to the trace.
  162. *
  163. * @stable ICU 2.8
  164. */
  165. U_STABLE void U_EXPORT2
  166. utrace_setFunctions(const void *context,
  167. UTraceEntry *e, UTraceExit *x, UTraceData *d);
  168. /**
  169. * Get the currently installed ICU tracing functions. Note that a null function
  170. * pointer will be returned if no trace function has been set.
  171. *
  172. * @param context The currently installed tracing context.
  173. * @param e The currently installed UTraceEntry function.
  174. * @param x The currently installed UTraceExit function.
  175. * @param d The currently installed UTraceData function.
  176. * @stable ICU 2.8
  177. */
  178. U_STABLE void U_EXPORT2
  179. utrace_getFunctions(const void **context,
  180. UTraceEntry **e, UTraceExit **x, UTraceData **d);
  181. /*
  182. *
  183. * ICU trace format string syntax
  184. *
  185. * Format Strings are passed to UTraceData functions, and define the
  186. * number and types of the trace data being passed on each call.
  187. *
  188. * The UTraceData function, which is supplied by the application,
  189. * not by ICU, can either forward the trace data (passed via
  190. * varargs) and the format string back to ICU for formatting into
  191. * a displayable string, or it can interpret the format itself,
  192. * and do as it wishes with the trace data.
  193. *
  194. *
  195. * Goals for the format string
  196. * - basic data output
  197. * - easy to use for trace programmer
  198. * - sufficient provision for data types for trace output readability
  199. * - well-defined types and binary portable APIs
  200. *
  201. * Non-goals
  202. * - printf compatibility
  203. * - fancy formatting
  204. * - argument reordering and other internationalization features
  205. *
  206. * ICU trace format strings contain plain text with argument inserts,
  207. * much like standard printf format strings.
  208. * Each insert begins with a '%', then optionally contains a 'v',
  209. * then exactly one type character.
  210. * Two '%' in a row represent a '%' instead of an insert.
  211. * The trace format strings need not have \n at the end.
  212. *
  213. *
  214. * Types
  215. * -----
  216. *
  217. * Type characters:
  218. * - c A char character in the default codepage.
  219. * - s A NUL-terminated char * string in the default codepage.
  220. * - S A UChar * string. Requires two params, (ptr, length). Length=-1 for nul term.
  221. * - b A byte (8-bit integer).
  222. * - h A 16-bit integer. Also a 16 bit Unicode code unit.
  223. * - d A 32-bit integer. Also a 20 bit Unicode code point value.
  224. * - l A 64-bit integer.
  225. * - p A data pointer.
  226. *
  227. * Vectors
  228. * -------
  229. *
  230. * If the 'v' is not specified, then one item of the specified type
  231. * is passed in.
  232. * If the 'v' (for "vector") is specified, then a vector of items of the
  233. * specified type is passed in, via a pointer to the first item
  234. * and an int32_t value for the length of the vector.
  235. * Length==-1 means zero or NUL termination. Works for vectors of all types.
  236. *
  237. * Note: %vS is a vector of (UChar *) strings. The strings must
  238. * be nul terminated as there is no way to provide a
  239. * separate length parameter for each string. The length
  240. * parameter (required for all vectors) is the number of
  241. * strings, not the length of the strings.
  242. *
  243. * Examples
  244. * --------
  245. *
  246. * These examples show the parameters that will be passed to an application's
  247. * UTraceData() function for various formats.
  248. *
  249. * - the precise formatting is up to the application!
  250. * - the examples use type casts for arguments only to _show_ the types of
  251. * arguments without needing variable declarations in the examples;
  252. * the type casts will not be necessary in actual code
  253. *
  254. * UTraceDataFunc(context, fnNumber, level,
  255. * "There is a character %c in the string %s.", // Format String
  256. * (char)c, (const char *)s); // varargs parameters
  257. * -> There is a character 0x42 'B' in the string "Bravo".
  258. *
  259. * UTraceDataFunc(context, fnNumber, level,
  260. * "Vector of bytes %vb vector of chars %vc",
  261. * (const uint8_t *)bytes, (int32_t)bytesLength,
  262. * (const char *)chars, (int32_t)charsLength);
  263. * -> Vector of bytes
  264. * 42 63 64 3f [4]
  265. * vector of chars
  266. * "Bcd?"[4]
  267. *
  268. * UTraceDataFunc(context, fnNumber, level,
  269. * "An int32_t %d and a whole bunch of them %vd",
  270. * (int32_t)-5, (const int32_t *)ints, (int32_t)intsLength);
  271. * -> An int32_t 0xfffffffb and a whole bunch of them
  272. * fffffffb 00000005 0000010a [3]
  273. *
  274. */
  275. /**
  276. * Trace output Formatter. An application's UTraceData tracing functions may call
  277. * back to this function to format the trace output in a
  278. * human readable form. Note that a UTraceData function may choose
  279. * to not format the data; it could, for example, save it in
  280. * in the raw form it was received (more compact), leaving
  281. * formatting for a later trace analyis tool.
  282. * @param outBuf pointer to a buffer to receive the formatted output. Output
  283. * will be nul terminated if there is space in the buffer -
  284. * if the length of the requested output < the output buffer size.
  285. * @param capacity Length of the output buffer.
  286. * @param indent Number of spaces to indent the output. Intended to allow
  287. * data displayed from nested functions to be indented for readability.
  288. * @param fmt Format specification for the data to output
  289. * @param args Data to be formatted.
  290. * @return Length of formatted output, including the terminating NUL.
  291. * If buffer capacity is insufficient, the required capacity is returned.
  292. * @stable ICU 2.8
  293. */
  294. U_STABLE int32_t U_EXPORT2
  295. utrace_vformat(char *outBuf, int32_t capacity,
  296. int32_t indent, const char *fmt, va_list args);
  297. /**
  298. * Trace output Formatter. An application's UTraceData tracing functions may call
  299. * this function to format any additional trace data, beyond that
  300. * provided by default, in human readable form with the same
  301. * formatting conventions used by utrace_vformat().
  302. * @param outBuf pointer to a buffer to receive the formatted output. Output
  303. * will be nul terminated if there is space in the buffer -
  304. * if the length of the requested output < the output buffer size.
  305. * @param capacity Length of the output buffer.
  306. * @param indent Number of spaces to indent the output. Intended to allow
  307. * data displayed from nested functions to be indented for readability.
  308. * @param fmt Format specification for the data to output
  309. * @param ... Data to be formatted.
  310. * @return Length of formatted output, including the terminating NUL.
  311. * If buffer capacity is insufficient, the required capacity is returned.
  312. * @stable ICU 2.8
  313. */
  314. U_STABLE int32_t U_EXPORT2
  315. utrace_format(char *outBuf, int32_t capacity,
  316. int32_t indent, const char *fmt, ...);
  317. /* Trace function numbers --------------------------------------------------- */
  318. /**
  319. * Get the name of a function from its trace function number.
  320. *
  321. * @param fnNumber The trace number for an ICU function.
  322. * @return The name string for the function.
  323. *
  324. * @see UTraceFunctionNumber
  325. * @stable ICU 2.8
  326. */
  327. U_STABLE const char * U_EXPORT2
  328. utrace_functionName(int32_t fnNumber);
  329. U_CDECL_END
  330. #endif