ICU-2403 add tracing to converter open/close/load/unload

X-SVN-Rev: 13822
This commit is contained in:
Markus Scherer 2003-11-21 23:24:11 +00:00
parent f409a92b99
commit 19c5a7a2e7
4 changed files with 97 additions and 117 deletions

View File

@ -28,71 +28,13 @@
#include "cmemory.h"
#include "cstring.h"
#include "uassert.h"
#include "utracimp.h"
#include "ustr_imp.h"
#include "ucnv_imp.h"
#include "ucnv_io.h"
#include "ucnv_cnv.h"
#include "ucnv_bld.h"
#if 0
/* debugging for converters */
# include <stdio.h>
void UCNV_DEBUG_LOG(const char *what, const char *who, const void *p, int l)
{
static FILE *f = NULL;
if(f==NULL)
{
/* stderr, or open another file */
f = stderr;
/* f = fopen("c:\\UCNV_DEBUG_LOG.txt", "w"); */
}
if (!what) {
what = "(null)";
}
if (!who) {
who = "(null)";
}
if (!p) {
p = "(null)";
}
fprintf(f, "%p\t:%d\t%-20s\t%-10s\n",
p, l, who, what);
fflush(f);
}
/* dump the contents of a converter */
static void UCNV_DEBUG_CNV(const UConverter *c, int line)
{
UErrorCode err = U_ZERO_ERROR;
fprintf(stderr, "%p\t:%d\t", c, line);
if(c!=NULL) {
const char *name = ucnv_getName(c, &err);
if (!name) {
name = "(null)";
}
fprintf(stderr, "%s\t", name);
fprintf(stderr, "shr=%p, ref=%x\n",
c->sharedData,
c->sharedData->referenceCounter);
} else {
fprintf(stderr, "DEMISED\n");
}
}
# define UCNV_DEBUG 1
# define UCNV_DEBUG_LOG(x,y,z) UCNV_DEBUG_LOG(x,y,z,__LINE__)
# define UCNV_DEBUG_CNV(c) UCNV_DEBUG_CNV(c, __LINE__)
#else
# define UCNV_DEBUG_LOG(x,y,z)
# define UCNV_DEBUG_CNV(c)
#endif
/* size of intermediate and preflighting buffers in ucnv_convert() */
#define CHUNK_SIZE 1024
@ -129,13 +71,10 @@ ucnv_open (const char *name,
UConverter *r;
if (err == NULL || U_FAILURE (*err)) {
UCNV_DEBUG_LOG("open", name, NULL);
return NULL;
}
r = ucnv_createConverter(NULL, name, err);
UCNV_DEBUG_LOG("open", name, r);
UCNV_DEBUG_CNV(r);
return r;
}
@ -216,18 +155,21 @@ ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, U
NULL
};
UTRACE_ENTRY_OC(UTRACE_UCNV_CLONE);
if (status == NULL || U_FAILURE(*status)){
UTRACE_EXIT_STATUS(*status);
return 0;
}
if (!pBufferSize || !cnv){
*status = U_ILLEGAL_ARGUMENT_ERROR;
*status = U_ILLEGAL_ARGUMENT_ERROR;
UTRACE_EXIT_STATUS(*status);
return 0;
}
UCNV_DEBUG_LOG("cloning FROM", ucnv_getName(cnv,status), cnv);
UCNV_DEBUG_LOG("cloning WITH", "memory", stackBuffer);
UCNV_DEBUG_CNV(cnv);
UTRACE_DATA3(UTRACE_OPEN_CLOSE, "clone converter %s at %p into stackBuffer %p",
ucnv_getName(cnv, status), cnv, stackBuffer);
/* Pointers on 64-bit platforms need to be aligned
* on a 64-bit boundry in memory.
@ -253,6 +195,7 @@ ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, U
if (*pBufferSize <= 0){ /* 'preflighting' request - set needed size into *pBufferSize */
*pBufferSize = bufferSizeNeeded;
UTRACE_EXIT_VALUE(bufferSizeNeeded);
return 0;
}
@ -265,6 +208,7 @@ ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, U
if(localConverter == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
UTRACE_EXIT_STATUS(*status);
return NULL;
}
@ -292,6 +236,7 @@ ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, U
if(localConverter==NULL || U_FAILURE(*status)) {
uprv_free(allocatedConverter);
UTRACE_EXIT_STATUS(*status);
return NULL;
}
@ -308,17 +253,6 @@ ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, U
if(localConverter == (UConverter*)stackBuffer) {
/* we're using user provided data - set to not destroy */
localConverter->isCopyLocal = TRUE;
#ifdef UCNV_DEBUG
fprintf(stderr, "%p\t:%d\t\t==stackbuffer %p, isCopyLocal TRUE\n",
localConverter, __LINE__, stackBuffer);
#endif
} else {
#ifdef UCNV_DEBUG
fprintf(stderr, "%p\t:%d\t\t!=stackbuffer %p, isCopyLocal left at %s\n",
localConverter, __LINE__, stackBuffer,
localConverter->isCopyLocal?"TRUE":"FALSE");
#endif
}
localConverter->isExtraLocal = localConverter->isCopyLocal;
@ -330,11 +264,7 @@ ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, U
cbErr = U_ZERO_ERROR;
cnv->fromUCharErrorBehaviour(cnv->fromUContext, &fromUArgs, NULL, 0, 0, UCNV_CLONE, &cbErr);
UCNV_DEBUG_LOG("cloning TO", ucnv_getName(localConverter,status), localConverter);
UCNV_DEBUG_CNV(localConverter);
UCNV_DEBUG_CNV(cnv);
UTRACE_EXIT_PTR_STATUS(localConverter, *status);
return localConverter;
}
@ -369,13 +299,16 @@ ucnv_close (UConverter * converter)
};
UErrorCode errorCode = U_ZERO_ERROR;
UTRACE_ENTRY_OC(UTRACE_UCNV_CLOSE);
if (converter == NULL)
{
UTRACE_EXIT();
return;
}
UCNV_DEBUG_LOG("close", ucnv_getName(converter, &errorCode), converter);
UCNV_DEBUG_CNV(converter);
UTRACE_DATA3(UTRACE_OPEN_CLOSE, "close converter %s at %p, isCopyLocal=%b",
ucnv_getName(converter, &errorCode), converter, converter->isCopyLocal);
toUArgs.converter = fromUArgs.converter = converter;
@ -383,25 +316,10 @@ ucnv_close (UConverter * converter)
errorCode = U_ZERO_ERROR;
converter->fromUCharErrorBehaviour(converter->fromUContext, &fromUArgs, NULL, 0, 0, UCNV_CLOSE, &errorCode);
UCNV_DEBUG_CNV(converter);
if (converter->sharedData->impl->close != NULL) {
converter->sharedData->impl->close(converter);
}
#ifdef UCNV_DEBUG
{
char c[4];
c[0]='0'+converter->sharedData->referenceCounter;
c[1]=0;
UCNV_DEBUG_LOG("close--", c, converter);
if((converter->sharedData->referenceCounter == 0)&&(converter->sharedData->sharedDataCached == FALSE)) {
UCNV_DEBUG_CNV(converter);
UCNV_DEBUG_LOG("close:delDead", "??", converter);
}
}
#endif
/*
Checking whether it's an algorithic converter is okay
in multithreaded applications because the value never changes.
@ -412,10 +330,10 @@ ucnv_close (UConverter * converter)
}
if(!converter->isCopyLocal){
UCNV_DEBUG_LOG("close:free", "", converter);
uprv_free (converter);
}
return;
UTRACE_EXIT();
}
/*returns a single Name from the list, will return NULL if out of bounds

View File

@ -24,6 +24,7 @@
#include "unicode/ucnv.h"
#include "unicode/ucnv_err.h"
#include "unicode/uloc.h"
#include "utracimp.h"
#include "ucnv_io.h"
#include "ucnv_bld.h"
#include "ucnvmbcs.h"
@ -273,13 +274,19 @@ static UConverterSharedData *createConverterFromFile(UConverterLoadArgs *pArgs,
UDataMemory *data;
UConverterSharedData *sharedData;
UTRACE_ENTRY_OC(UTRACE_UCNV_LOAD);
if (err == NULL || U_FAILURE (*err)) {
UTRACE_EXIT_STATUS(*err);
return NULL;
}
UTRACE_DATA2(UTRACE_OPEN_CLOSE, "load converter %s from package %s", pArgs->name, pArgs->pkg);
data = udata_openChoice(pArgs->pkg, DATA_TYPE, pArgs->name, isCnvAcceptable, NULL, err);
if(U_FAILURE(*err))
{
UTRACE_EXIT_STATUS(*err);
return NULL;
}
@ -287,6 +294,7 @@ static UConverterSharedData *createConverterFromFile(UConverterLoadArgs *pArgs,
if(U_FAILURE(*err))
{
udata_close(data);
UTRACE_EXIT_STATUS(*err);
return NULL;
}
@ -297,6 +305,7 @@ static UConverterSharedData *createConverterFromFile(UConverterLoadArgs *pArgs,
* in the first place, or just set the pkg field to "".
*/
UTRACE_EXIT_PTR_STATUS(sharedData, *err);
return sharedData;
}
@ -439,8 +448,13 @@ ucnv_getSharedConverterData(const char *name)
static UBool
ucnv_deleteSharedConverterData(UConverterSharedData * deadSharedData)
{
if (deadSharedData->referenceCounter > 0)
UTRACE_ENTRY_OC(UTRACE_UCNV_UNLOAD);
UTRACE_DATA2(UTRACE_OPEN_CLOSE, "unload converter %s shared data %p", deadSharedData->staticData->name, deadSharedData);
if (deadSharedData->referenceCounter > 0) {
UTRACE_EXIT_VALUE((int32_t)FALSE);
return FALSE;
}
if (deadSharedData->impl->unload != NULL) {
deadSharedData->impl->unload(deadSharedData);
@ -472,7 +486,8 @@ ucnv_deleteSharedConverterData(UConverterSharedData * deadSharedData)
#endif
uprv_free(deadSharedData);
UTRACE_EXIT_VALUE((int32_t)TRUE);
return TRUE;
}
@ -656,8 +671,14 @@ ucnv_createConverter(UConverter *myUConverter, const char *converterName, UError
UConverterSharedData *mySharedConverterData = NULL;
UErrorCode internalErrorCode = U_ZERO_ERROR;
uint32_t options = 0;
if (U_FAILURE (*err))
return NULL;
UTRACE_ENTRY_OC(UTRACE_UCNV_OPEN);
if (U_FAILURE (*err)) {
goto exitError;
}
UTRACE_DATA1(UTRACE_OPEN_CLOSE, "open converter %s", converterName);
locale[0] = 0;
@ -666,7 +687,7 @@ ucnv_createConverter(UConverter *myUConverter, const char *converterName, UError
realName = ucnv_io_getDefaultConverterName();
if (realName == NULL) {
*err = U_MISSING_RESOURCE_ERROR;
return NULL;
goto exitError;
}
/* the default converter name is already canonical */
} else {
@ -674,7 +695,7 @@ ucnv_createConverter(UConverter *myUConverter, const char *converterName, UError
parseConverterOptions(converterName, cnvName, locale, &options, err);
if (U_FAILURE(*err)) {
/* Very bad name used. */
return NULL;
goto exitError;
}
/* get the canonical converter name */
@ -716,7 +737,7 @@ ucnv_createConverter(UConverter *myUConverter, const char *converterName, UError
umtx_unlock(&cnvCacheMutex);
if (U_FAILURE (*err) || (mySharedConverterData == NULL))
{
return NULL;
goto exitError;
}
}
@ -734,10 +755,15 @@ ucnv_createConverter(UConverter *myUConverter, const char *converterName, UError
--mySharedConverterData->referenceCounter;
umtx_unlock(&cnvCacheMutex);
}
return NULL;
goto exitError;
}
UTRACE_EXIT_PTR_STATUS(myUConverter, *err);
return myUConverter;
exitError:
UTRACE_EXIT_STATUS(*err);
return NULL;
}
UConverter *
@ -745,11 +771,16 @@ ucnv_createAlgorithmicConverter(UConverter *myUConverter,
UConverterType type,
const char *locale, uint32_t options,
UErrorCode *err) {
UConverter *cnv;
const UConverterSharedData *sharedData;
UBool isAlgorithmicConverter;
UTRACE_ENTRY_OC(UTRACE_UCNV_OPEN_ALGORITHMIC);
UTRACE_DATA1(UTRACE_OPEN_CLOSE, "open algorithmic converter type %d", (int32_t)type);
if(type<0 || UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES<=type) {
*err = U_ILLEGAL_ARGUMENT_ERROR;
UTRACE_EXIT_STATUS(U_ILLEGAL_ARGUMENT_ERROR);
return NULL;
}
@ -760,11 +791,15 @@ ucnv_createAlgorithmicConverter(UConverter *myUConverter,
if (isAlgorithmicConverter) {
/* not a valid type, or not an algorithmic converter */
*err = U_ILLEGAL_ARGUMENT_ERROR;
UTRACE_EXIT_STATUS(U_ILLEGAL_ARGUMENT_ERROR);
return NULL;
}
return ucnv_createConverterFromSharedData(myUConverter, (UConverterSharedData *)sharedData, "",
cnv = ucnv_createConverterFromSharedData(myUConverter, (UConverterSharedData *)sharedData, "",
locale != NULL ? locale : "", options, err);
UTRACE_EXIT_PTR_STATUS(cnv, *err);
return cnv;
}
UConverter*
@ -776,10 +811,15 @@ ucnv_createConverterFromPackage(const char *packageName, const char *converterNa
UConverterLoadArgs args={ 0 };
UTRACE_ENTRY_OC(UTRACE_UCNV_OPEN_PACKAGE);
if(U_FAILURE(*err)) {
UTRACE_EXIT_STATUS(*err);
return NULL;
}
UTRACE_DATA2(UTRACE_OPEN_CLOSE, "open converter %s from package %s", converterName, packageName);
args.size=sizeof(UConverterLoadArgs);
args.nestedLoads=1;
args.pkg=packageName;
@ -788,6 +828,7 @@ ucnv_createConverterFromPackage(const char *packageName, const char *converterNa
parseConverterOptions(converterName, cnvName, locale, &args.options, err);
if (U_FAILURE(*err)) {
/* Very bad name used. */
UTRACE_EXIT_STATUS(*err);
return NULL;
}
args.name=cnvName;
@ -796,6 +837,7 @@ ucnv_createConverterFromPackage(const char *packageName, const char *converterNa
mySharedConverterData = createConverterFromFile(&args, err);
if (U_FAILURE(*err)) {
UTRACE_EXIT_STATUS(*err);
return NULL;
}
@ -804,9 +846,11 @@ ucnv_createConverterFromPackage(const char *packageName, const char *converterNa
if (U_FAILURE(*err)) {
ucnv_close(myUConverter);
UTRACE_EXIT_STATUS(*err);
return NULL;
}
UTRACE_EXIT_PTR_STATUS(myUConverter, *err);
return myUConverter;
}
@ -870,14 +914,18 @@ ucnv_flushCache ()
UErrorCode status = U_ILLEGAL_ARGUMENT_ERROR;
int32_t i, remaining;
UTRACE_ENTRY_OC(UTRACE_UCNV_FLUSH_CACHE);
/* Close the default converter without creating a new one so that everything will be flushed. */
ucnv_close(u_getDefaultConverter(&status));
/*if shared data hasn't even been lazy evaluated yet
* return 0
*/
if (SHARED_DATA_HASHTABLE == NULL)
if (SHARED_DATA_HASHTABLE == NULL) {
UTRACE_EXIT_VALUE((int32_t)0);
return 0;
}
/*creates an enumeration to iterate through every element in the
* table
@ -923,6 +971,7 @@ ucnv_flushCache ()
ucnv_io_flushAvailableConverterCache();
UTRACE_EXIT_VALUE(tableDeletedNum);
return tableDeletedNum;
}

View File

@ -323,8 +323,13 @@ typedef enum UTraceFunctionNumber {
UTRACE_CONVERSION_START=0x1000,
UTRACE_UCNV_OPEN=UTRACE_CONVERSION_START,
UTRACE_UCNV_OPEN_PACKAGE,
UTRACE_UCNV_OPEN_ALGORITHMIC,
UTRACE_UCNV_CLONE,
UTRACE_UCNV_CLOSE,
UTRACE_UCNV_FLUSH_CACHE,
UTRACE_UCNV_LOAD,
UTRACE_UCNV_UNLOAD,
UTRACE_CONVERSION_LIMIT,
UTRACE_COLLATION_START=0x2000,

View File

@ -438,17 +438,25 @@ utrace_cleanup() {
static const char * const
trFnName[] = {"u_init",
"u_cleanup",
0};
trFnName[] = {
"u_init",
"u_cleanup",
NULL
};
static const char * const
trConvNames[] = {
"ucnv_open",
"ucnv_openPackage",
"ucnv_openAlgorithmic",
"ucnv_clone",
"ucnv_close",
"ucnv_flushCache",
0};
"ucnv_load",
"ucnv_unload",
NULL
};
static const char * const
@ -460,8 +468,8 @@ trCollNames[] = {
"ucol_getLocale",
"ucol_nextSortKeyPart",
"ucol_strcollIter",
0};
NULL
};
U_CAPI const char * U_EXPORT2