ICU-2403 Make tracing a configure option

X-SVN-Rev: 14120
This commit is contained in:
George Rhoten 2003-12-13 00:18:41 +00:00
parent d685699946
commit 5b04614ac5
5 changed files with 109 additions and 66 deletions

View File

@ -112,6 +112,11 @@
#define U_HAVE_PLACEMENT_NEW @U_HAVE_PLACEMENT_NEW@
#endif
/* Determine whether to enable tracing. */
#ifndef U_ENABLE_TRACING
#define U_ENABLE_TRACING @U_ENABLE_TRACING@
#endif
/* Define the library suffix in a C syntax. */
#define U_HAVE_LIB_SUFFIX @U_HAVE_LIB_SUFFIX@
#define U_LIB_SUFFIX_C_NAME @ICULIBSUFFIXCNAME@

View File

@ -68,6 +68,11 @@
#define U_OVERRIDE_CXX_ALLOCATION 1
#endif
/* Determine whether to enable tracing. */
#ifndef U_ENABLE_TRACING
#define U_ENABLE_TRACING 1
#endif
/*===========================================================================*/
/* Generic data types */
/*===========================================================================*/

View File

@ -87,6 +87,11 @@
#define U_HAVE_PLACEMENT_NEW 1
#endif
/* Determine whether to enable tracing. */
#ifndef U_ENABLE_TRACING
#define U_ENABLE_TRACING 1
#endif
/*===========================================================================*/
/* Generic data types */
/*===========================================================================*/

View File

@ -40,13 +40,11 @@
#ifndef __UTRACIMP_H__
#define __UTRACIMP_H__
#include <stdarg.h>
#include "unicode/utrace.h"
#include "unicode/utypes.h"
#include <stdarg.h>
U_CDECL_BEGIN
/**
* \var utrace_level
* Trace level variable. Negative for "off".
@ -63,6 +61,68 @@ U_CFUNC U_IMPORT int32_t
utrace_level;
/**
* Traced Function Exit return types.
* Flags indicating the number and types of varargs included in a call
* to a UTraceExit function.
* Bits 0-3: The function return type. First variable param.
* Bit 4: Flag for presence of U_ErrorCode status param.
* @internal
*/
typedef enum UTraceExitVal {
/** The traced function returns no value @internal */
UTRACE_EXITV_NONE = 0,
/** The traced function returns an int32_t, or compatible, type. @internal */
UTRACE_EXITV_I32 = 1,
/** The traced function returns a pointer @internal */
UTRACE_EXITV_PTR = 2,
/** The traced function returns a UBool @internal */
UTRACE_EXITV_BOOL = 3,
/** Mask to extract the return type values from a UTraceExitVal @internal */
UTRACE_EXITV_MASK = 0xf,
/** Bit indicating that the traced function includes a UErrorCode parameter @internal */
UTRACE_EXITV_STATUS = 0x10
} UTraceExitVal;
/**
* Trace function for the entry point of a function.
* Do not use directly, use UTRACE_ENTRY instead.
* @param fnNumber The UTraceFunctionNumber for the current function.
* @internal
*/
U_CAPI void U_EXPORT2
utrace_entry(int32_t fnNumber);
/**
* Trace function for each exit point of a function.
* Do not use directly, use UTRACE_EXIT* instead.
* @param fnNumber The UTraceFunctionNumber for the current function.
* @param returnType The type of the value returned by the function.
* @param errorCode The UErrorCode value at function exit. See UTRACE_EXIT.
* @internal
*/
U_CAPI void U_EXPORT2
utrace_exit(int32_t fnNumber, int32_t returnType, ...);
/**
* Trace function used inside functions that have a UTRACE_ENTRY() statement.
* Do not use directly, use UTRACE_DATAX() macros instead.
*
* @param utraceFnNumber The number of the current function, from the local
* variable of the same name.
* @param level The trace level for this message.
* @param fmt The trace format string.
*
* @internal
*/
U_CAPI void U_EXPORT2
utrace_data(int32_t utraceFnNumber, int32_t level, const char *fmt, ...);
U_CDECL_END
#if U_ENABLE_TRACING
/**
* Boolean expression to see if ICU tracing is turned on
* to at least the specified level.
@ -121,32 +181,6 @@ utrace_level;
utraceFnNumber |= UTRACE_TRACED_ENTRY; \
}
/**
* Traced Function Exit return types.
* Flags indicating the number and types of varargs included in a call
* to a UTraceExit function.
* Bits 0-3: The function return type. First variable param.
* Bit 4: Flag for presence of U_ErrorCode status param.
* @internal
*/
typedef enum UTraceExitVal {
/** The traced function returns no value @internal */
UTRACE_EXITV_NONE = 0,
/** The traced function returns an int32_t, or compatible, type. @internal */
UTRACE_EXITV_I32 = 1,
/** The traced function returns a pointer @internal */
UTRACE_EXITV_PTR = 2,
/** The traced function returns a UBool @internal */
UTRACE_EXITV_BOOL = 3,
/** Mask to extract the return type values from a UTraceExitVal @internal */
UTRACE_EXITV_MASK = 0xf,
/** Bit indicating that the traced function includes a UErrorCode parameter @internal */
UTRACE_EXITV_STATUS = 0x10
} UTraceExitVal;
/**
* Trace statement for each exit point of a function that has a UTRACE_ENTRY()
* statement.
@ -192,41 +226,6 @@ typedef enum UTraceExitVal {
utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (UTRACE_EXITV_PTR | UTRACE_EXITV_STATUS), ptr, status); \
}}
/**
* Trace function for the entry point of a function.
* Do not use directly, use UTRACE_ENTRY instead.
* @param fnNumber The UTraceFunctionNumber for the current function.
* @internal
*/
U_CAPI void U_EXPORT2
utrace_entry(int32_t fnNumber);
/**
* Trace function for each exit point of a function.
* Do not use directly, use UTRACE_EXIT* instead.
* @param fnNumber The UTraceFunctionNumber for the current function.
* @param returnType The type of the value returned by the function.
* @param errorCode The UErrorCode value at function exit. See UTRACE_EXIT.
* @internal
*/
U_CAPI void U_EXPORT2
utrace_exit(int32_t fnNumber, int32_t returnType, ...);
/**
* Trace function used inside functions that have a UTRACE_ENTRY() statement.
* Do not use directly, use UTRACE_DATAX() macros instead.
*
* @param utraceFnNumber The number of the current function, from the local
* variable of the same name.
* @param level The trace level for this message.
* @param fmt The trace format string.
*
* @internal
*/
U_CAPI void U_EXPORT2
utrace_data(int32_t utraceFnNumber, int32_t level, const char *fmt, ...);
/**
* Trace statement used inside functions that have a UTRACE_ENTRY() statement.
* Takes no data arguments.
@ -357,6 +356,31 @@ utrace_data(int32_t utraceFnNumber, int32_t level, const char *fmt, ...);
utrace_data(utraceFnNumber, (level), (fmt), (a), (b), (c), (d), (e), (f), (g), (h), (i)); \
}
U_CDECL_END
#else
/*
* When tracing is disabled, the following macros become empty
*/
#define UTRACE_LEVEL(level) 0
#define UTRACE_ENTRY(fnNumber)
#define UTRACE_ENTRY_OC(fnNumber)
#define UTRACE_EXIT()
#define UTRACE_EXIT_VALUE(val)
#define UTRACE_EXIT_STATUS(status)
#define UTRACE_EXIT_VALUE_STATUS(val, status)
#define UTRACE_EXIT_PTR_STATUS(ptr, status)
#define UTRACE_DATA0(level, fmt)
#define UTRACE_DATA1(level, fmt, a)
#define UTRACE_DATA2(level, fmt, a, b)
#define UTRACE_DATA3(level, fmt, a, b, c)
#define UTRACE_DATA4(level, fmt, a, b, c, d)
#define UTRACE_DATA5(level, fmt, a, b, c, d, e)
#define UTRACE_DATA6(level, fmt, a, b, c, d, e, f)
#define UTRACE_DATA7(level, fmt, a, b, c, d, e, f, g)
#define UTRACE_DATA8(level, fmt, a, b, c, d, e, f, g, h)
#define UTRACE_DATA9(level, fmt, a, b, c, d, e, f, g, h, i)
#endif
#endif

View File

@ -11,7 +11,6 @@
#include "unicode/utypes.h"
#include "unicode/utrace.h"
#include "utracimp.h"
#include "unicode/uclean.h"
#include "unicode/uchar.h"
#include "unicode/ures.h"
@ -19,6 +18,7 @@
#include "cintltst.h"
#include <stdlib.h>
#include <string.h>
#include "utracimp.h"
static void TestTraceAPI(void);
@ -188,9 +188,13 @@ static void TestTraceAPI() {
cnv = ucnv_open(NULL, &status);
TEST_ASSERT(U_SUCCESS(status));
ucnv_close(cnv);
#if U_ENABLE_TRACING
TEST_ASSERT(gTraceEntryCount > 0);
TEST_ASSERT(gTraceExitCount > 0);
TEST_ASSERT(gTraceDataCount > 0);
#else
log_info("Tracing has been disabled. Testing of this feature has been skipped.\n");
#endif
}