New LOG lib

Change-Id: I977e7e10fa58c0a64ca0c3c7b5cb2272446e3efe
main
satok 2012-01-13 18:01:22 +09:00
parent b960477952
commit 9fb6f47a6a
10 changed files with 74 additions and 70 deletions

View File

@ -51,7 +51,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
PROF_START(66); PROF_START(66);
const char *sourceDirChars = env->GetStringUTFChars(sourceDir, 0); const char *sourceDirChars = env->GetStringUTFChars(sourceDir, 0);
if (sourceDirChars == 0) { if (sourceDirChars == 0) {
LOGE("DICT: Can't get sourceDir string"); AKLOGE("DICT: Can't get sourceDir string");
return 0; return 0;
} }
int fd = 0; int fd = 0;
@ -61,7 +61,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
/* mmap version */ /* mmap version */
fd = open(sourceDirChars, O_RDONLY); fd = open(sourceDirChars, O_RDONLY);
if (fd < 0) { if (fd < 0) {
LOGE("DICT: Can't open sourceDir. sourceDirChars=%s errno=%d", sourceDirChars, errno); AKLOGE("DICT: Can't open sourceDir. sourceDirChars=%s errno=%d", sourceDirChars, errno);
return 0; return 0;
} }
int pagesize = getpagesize(); int pagesize = getpagesize();
@ -70,7 +70,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
int adjDictSize = dictSize + adjust; int adjDictSize = dictSize + adjust;
dictBuf = mmap(0, sizeof(char) * adjDictSize, PROT_READ, MAP_PRIVATE, fd, adjDictOffset); dictBuf = mmap(0, sizeof(char) * adjDictSize, PROT_READ, MAP_PRIVATE, fd, adjDictOffset);
if (dictBuf == MAP_FAILED) { if (dictBuf == MAP_FAILED) {
LOGE("DICT: Can't mmap dictionary. errno=%d", errno); AKLOGE("DICT: Can't mmap dictionary. errno=%d", errno);
return 0; return 0;
} }
dictBuf = (void *)((char *)dictBuf + adjust); dictBuf = (void *)((char *)dictBuf + adjust);
@ -79,39 +79,39 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
FILE *file = 0; FILE *file = 0;
file = fopen(sourceDirChars, "rb"); file = fopen(sourceDirChars, "rb");
if (file == 0) { if (file == 0) {
LOGE("DICT: Can't fopen sourceDir. sourceDirChars=%s errno=%d", sourceDirChars, errno); AKLOGE("DICT: Can't fopen sourceDir. sourceDirChars=%s errno=%d", sourceDirChars, errno);
return 0; return 0;
} }
dictBuf = malloc(sizeof(char) * dictSize); dictBuf = malloc(sizeof(char) * dictSize);
if (!dictBuf) { if (!dictBuf) {
LOGE("DICT: Can't allocate memory region for dictionary. errno=%d", errno); AKLOGE("DICT: Can't allocate memory region for dictionary. errno=%d", errno);
return 0; return 0;
} }
int ret = fseek(file, (long)dictOffset, SEEK_SET); int ret = fseek(file, (long)dictOffset, SEEK_SET);
if (ret != 0) { if (ret != 0) {
LOGE("DICT: Failure in fseek. ret=%d errno=%d", ret, errno); AKLOGE("DICT: Failure in fseek. ret=%d errno=%d", ret, errno);
return 0; return 0;
} }
ret = fread(dictBuf, sizeof(char) * dictSize, 1, file); ret = fread(dictBuf, sizeof(char) * dictSize, 1, file);
if (ret != 1) { if (ret != 1) {
LOGE("DICT: Failure in fread. ret=%d errno=%d", ret, errno); AKLOGE("DICT: Failure in fread. ret=%d errno=%d", ret, errno);
return 0; return 0;
} }
ret = fclose(file); ret = fclose(file);
if (ret != 0) { if (ret != 0) {
LOGE("DICT: Failure in fclose. ret=%d errno=%d", ret, errno); AKLOGE("DICT: Failure in fclose. ret=%d errno=%d", ret, errno);
return 0; return 0;
} }
#endif // USE_MMAP_FOR_DICTIONARY #endif // USE_MMAP_FOR_DICTIONARY
env->ReleaseStringUTFChars(sourceDir, sourceDirChars); env->ReleaseStringUTFChars(sourceDir, sourceDirChars);
if (!dictBuf) { if (!dictBuf) {
LOGE("DICT: dictBuf is null"); AKLOGE("DICT: dictBuf is null");
return 0; return 0;
} }
Dictionary *dictionary = 0; Dictionary *dictionary = 0;
if (BinaryFormat::UNKNOWN_FORMAT == BinaryFormat::detectFormat((uint8_t*)dictBuf)) { if (BinaryFormat::UNKNOWN_FORMAT == BinaryFormat::detectFormat((uint8_t*)dictBuf)) {
LOGE("DICT: dictionary format is unknown, bad magic number"); AKLOGE("DICT: dictionary format is unknown, bad magic number");
#ifdef USE_MMAP_FOR_DICTIONARY #ifdef USE_MMAP_FOR_DICTIONARY
releaseDictBuf(((char*)dictBuf) - adjust, adjDictSize, fd); releaseDictBuf(((char*)dictBuf) - adjust, adjDictSize, fd);
#else // USE_MMAP_FOR_DICTIONARY #else // USE_MMAP_FOR_DICTIONARY
@ -230,11 +230,11 @@ void releaseDictBuf(void* dictBuf, const size_t length, int fd) {
#ifdef USE_MMAP_FOR_DICTIONARY #ifdef USE_MMAP_FOR_DICTIONARY
int ret = munmap(dictBuf, length); int ret = munmap(dictBuf, length);
if (ret != 0) { if (ret != 0) {
LOGE("DICT: Failure in munmap. ret=%d errno=%d", ret, errno); AKLOGE("DICT: Failure in munmap. ret=%d errno=%d", ret, errno);
} }
ret = close(fd); ret = close(fd);
if (ret != 0) { if (ret != 0) {
LOGE("DICT: Failure in close. ret=%d errno=%d", ret, errno); AKLOGE("DICT: Failure in close. ret=%d errno=%d", ret, errno);
} }
#else // USE_MMAP_FOR_DICTIONARY #else // USE_MMAP_FOR_DICTIONARY
free(dictBuf); free(dictBuf);

View File

@ -36,18 +36,18 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
jint result = -1; jint result = -1;
if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
LOGE("ERROR: GetEnv failed"); AKLOGE("ERROR: GetEnv failed");
goto bail; goto bail;
} }
assert(env != 0); assert(env != 0);
if (!register_BinaryDictionary(env)) { if (!register_BinaryDictionary(env)) {
LOGE("ERROR: BinaryDictionary native registration failed"); AKLOGE("ERROR: BinaryDictionary native registration failed");
goto bail; goto bail;
} }
if (!register_ProximityInfo(env)) { if (!register_ProximityInfo(env)) {
LOGE("ERROR: ProximityInfo native registration failed"); AKLOGE("ERROR: ProximityInfo native registration failed");
goto bail; goto bail;
} }
@ -64,11 +64,11 @@ int registerNativeMethods(JNIEnv* env, const char* className, JNINativeMethod* m
int numMethods) { int numMethods) {
jclass clazz = env->FindClass(className); jclass clazz = env->FindClass(className);
if (clazz == 0) { if (clazz == 0) {
LOGE("Native registration unable to find class '%s'", className); AKLOGE("Native registration unable to find class '%s'", className);
return JNI_FALSE; return JNI_FALSE;
} }
if (env->RegisterNatives(clazz, methods, numMethods) < 0) { if (env->RegisterNatives(clazz, methods, numMethods) < 0) {
LOGE("RegisterNatives failed for '%s'", className); AKLOGE("RegisterNatives failed for '%s'", className);
env->DeleteLocalRef(clazz); env->DeleteLocalRef(clazz);
return JNI_FALSE; return JNI_FALSE;
} }

View File

@ -32,8 +32,8 @@ BigramDictionary::BigramDictionary(const unsigned char *dict, int maxWordLength,
MAX_ALTERNATIVES(maxAlternatives), IS_LATEST_DICT_VERSION(isLatestDictVersion), MAX_ALTERNATIVES(maxAlternatives), IS_LATEST_DICT_VERSION(isLatestDictVersion),
HAS_BIGRAM(hasBigram), mParentDictionary(parentDictionary) { HAS_BIGRAM(hasBigram), mParentDictionary(parentDictionary) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("BigramDictionary - constructor"); AKLOGI("BigramDictionary - constructor");
LOGI("Has Bigram : %d", hasBigram); AKLOGI("Has Bigram : %d", hasBigram);
} }
} }
@ -46,7 +46,7 @@ bool BigramDictionary::addWordBigram(unsigned short *word, int length, int frequ
#ifdef FLAG_DBG #ifdef FLAG_DBG
char s[length + 1]; char s[length + 1];
for (int i = 0; i <= length; i++) s[i] = word[i]; for (int i = 0; i <= length; i++) s[i] = word[i];
LOGI("Bigram: Found word = %s, freq = %d :", s, frequency); AKLOGI("Bigram: Found word = %s, freq = %d :", s, frequency);
#endif #endif
} }
@ -60,7 +60,7 @@ bool BigramDictionary::addWordBigram(unsigned short *word, int length, int frequ
insertAt++; insertAt++;
} }
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("Bigram: InsertAt -> %d maxBigrams: %d", insertAt, mMaxBigrams); AKLOGI("Bigram: InsertAt -> %d maxBigrams: %d", insertAt, mMaxBigrams);
} }
if (insertAt < mMaxBigrams) { if (insertAt < mMaxBigrams) {
memmove((char*) mBigramFreq + (insertAt + 1) * sizeof(mBigramFreq[0]), memmove((char*) mBigramFreq + (insertAt + 1) * sizeof(mBigramFreq[0]),
@ -76,7 +76,7 @@ bool BigramDictionary::addWordBigram(unsigned short *word, int length, int frequ
} }
*dest = 0; // NULL terminate *dest = 0; // NULL terminate
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("Bigram: Added word at %d", insertAt); AKLOGI("Bigram: Added word at %d", insertAt);
} }
return true; return true;
} }

View File

@ -42,7 +42,7 @@ inline static void initEditDistance(int *editDistanceTable) {
inline static void dumpEditDistance10ForDebug(int *editDistanceTable, const int inputLength, inline static void dumpEditDistance10ForDebug(int *editDistanceTable, const int inputLength,
const int outputLength) { const int outputLength) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("EditDistanceTable"); AKLOGI("EditDistanceTable");
for (int i = 0; i <= 10; ++i) { for (int i = 0; i <= 10; ++i) {
int c[11]; int c[11];
for (int j = 0; j <= 10; ++j) { for (int j = 0; j <= 10; ++j) {
@ -52,7 +52,7 @@ inline static void dumpEditDistance10ForDebug(int *editDistanceTable, const int
c[j] = -1; c[j] = -1;
} }
} }
LOGI("[ %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d ]", AKLOGI("[ %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d ]",
c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9], c[10]); c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9], c[10]);
} }
} }
@ -84,7 +84,7 @@ inline static void calcEditDistanceOneStep(int *editDistanceTable, const unsigne
inline static int getCurrentEditDistance( inline static int getCurrentEditDistance(
int *editDistanceTable, const int inputLength, const int outputLength) { int *editDistanceTable, const int inputLength, const int outputLength) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("getCurrentEditDistance %d, %d", inputLength, outputLength); AKLOGI("getCurrentEditDistance %d, %d", inputLength, outputLength);
} }
return editDistanceTable[(inputLength + 1) * (outputLength + 1) - 1]; return editDistanceTable[(inputLength + 1) * (outputLength + 1) - 1];
} }
@ -378,7 +378,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
--mTransposedCount; --mTransposedCount;
if (DEBUG_CORRECTION) { if (DEBUG_CORRECTION) {
DUMP_WORD(mWord, mOutputIndex); DUMP_WORD(mWord, mOutputIndex);
LOGI("UNRELATED(0): %d, %d, %d, %d, %c", mProximityCount, mSkippedCount, AKLOGI("UNRELATED(0): %d, %d, %d, %d, %c", mProximityCount, mSkippedCount,
mTransposedCount, mExcessiveCount, c); mTransposedCount, mExcessiveCount, c);
} }
return UNRELATED; return UNRELATED;
@ -404,7 +404,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
&& isEquivalentChar(mProximityInfo->getMatchedProximityId( && isEquivalentChar(mProximityInfo->getMatchedProximityId(
mInputIndex, mWord[mOutputIndex - 1], false))) { mInputIndex, mWord[mOutputIndex - 1], false))) {
if (DEBUG_CORRECTION) { if (DEBUG_CORRECTION) {
LOGI("CONVERSION p->e %c", mWord[mOutputIndex - 1]); AKLOGI("CONVERSION p->e %c", mWord[mOutputIndex - 1]);
} }
// Conversion p->e // Conversion p->e
// Example: // Example:
@ -481,7 +481,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
} else { } else {
if (DEBUG_CORRECTION) { if (DEBUG_CORRECTION) {
DUMP_WORD(mWord, mOutputIndex); DUMP_WORD(mWord, mOutputIndex);
LOGI("UNRELATED(1): %d, %d, %d, %d, %c", mProximityCount, mSkippedCount, AKLOGI("UNRELATED(1): %d, %d, %d, %d, %c", mProximityCount, mSkippedCount,
mTransposedCount, mExcessiveCount, c); mTransposedCount, mExcessiveCount, c);
} }
return UNRELATED; return UNRELATED;
@ -534,7 +534,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
mTerminalOutputIndex = mOutputIndex - 1; mTerminalOutputIndex = mOutputIndex - 1;
if (DEBUG_CORRECTION) { if (DEBUG_CORRECTION) {
DUMP_WORD(mWord, mOutputIndex); DUMP_WORD(mWord, mOutputIndex);
LOGI("ONTERMINAL(1): %d, %d, %d, %d, %c", mProximityCount, mSkippedCount, AKLOGI("ONTERMINAL(1): %d, %d, %d, %d, %c", mProximityCount, mSkippedCount,
mTransposedCount, mExcessiveCount, c); mTransposedCount, mExcessiveCount, c);
} }
return ON_TERMINAL; return ON_TERMINAL;
@ -703,7 +703,7 @@ int Correction::RankingAlgorithm::calculateFinalFreq(const int inputIndex, const
/ (10 * inputLength / (10 * inputLength
- WORDS_WITH_MISSING_CHARACTER_DEMOTION_START_POS_10X + 10); - WORDS_WITH_MISSING_CHARACTER_DEMOTION_START_POS_10X + 10);
if (DEBUG_DICT_FULL) { if (DEBUG_DICT_FULL) {
LOGI("Demotion rate for missing character is %d.", demotionRate); AKLOGI("Demotion rate for missing character is %d.", demotionRate);
} }
multiplyRate(demotionRate, &finalFreq); multiplyRate(demotionRate, &finalFreq);
} }
@ -717,7 +717,7 @@ int Correction::RankingAlgorithm::calculateFinalFreq(const int inputIndex, const
multiplyRate(WORDS_WITH_EXCESSIVE_CHARACTER_DEMOTION_RATE, &finalFreq); multiplyRate(WORDS_WITH_EXCESSIVE_CHARACTER_DEMOTION_RATE, &finalFreq);
if (!lastCharExceeded && !proximityInfo->existsAdjacentProximityChars(excessivePos)) { if (!lastCharExceeded && !proximityInfo->existsAdjacentProximityChars(excessivePos)) {
if (DEBUG_CORRECTION_FREQ) { if (DEBUG_CORRECTION_FREQ) {
LOGI("Double excessive demotion"); AKLOGI("Double excessive demotion");
} }
// If an excessive character is not adjacent to the left char or the right char, // If an excessive character is not adjacent to the left char or the right char,
// we will demote this word. // we will demote this word.
@ -767,7 +767,7 @@ int Correction::RankingAlgorithm::calculateFinalFreq(const int inputIndex, const
for (int i = 0; i < adjustedProximityMatchedCount; ++i) { for (int i = 0; i < adjustedProximityMatchedCount; ++i) {
// A word with proximity corrections // A word with proximity corrections
if (DEBUG_DICT_FULL) { if (DEBUG_DICT_FULL) {
LOGI("Found a proximity correction."); AKLOGI("Found a proximity correction.");
} }
multiplyIntCapped(typedLetterMultiplier, &finalFreq); multiplyIntCapped(typedLetterMultiplier, &finalFreq);
multiplyRate(WORDS_WITH_PROXIMITY_CHARACTER_DEMOTION_RATE, &finalFreq); multiplyRate(WORDS_WITH_PROXIMITY_CHARACTER_DEMOTION_RATE, &finalFreq);
@ -828,12 +828,12 @@ int Correction::RankingAlgorithm::calculateFinalFreq(const int inputIndex, const
} }
if (DEBUG_DICT_FULL) { if (DEBUG_DICT_FULL) {
LOGI("calc: %d, %d", outputIndex, sameLength); AKLOGI("calc: %d, %d", outputIndex, sameLength);
} }
if (DEBUG_CORRECTION_FREQ) { if (DEBUG_CORRECTION_FREQ) {
DUMP_WORD(correction->mWord, outputIndex + 1); DUMP_WORD(correction->mWord, outputIndex + 1);
LOGI("FinalFreq: [P%d, S%d, T%d, E%d] %d, %d, %d, %d, %d", proximityMatchedCount, AKLOGI("FinalFreq: [P%d, S%d, T%d, E%d] %d, %d, %d, %d, %d", proximityMatchedCount,
skippedCount, transposedCount, excessiveCount, lastCharExceeded, sameLength, skippedCount, transposedCount, excessiveCount, lastCharExceeded, sameLength,
quoteDiffCount, ed, finalFreq); quoteDiffCount, ed, finalFreq);
} }
@ -874,7 +874,8 @@ int Correction::RankingAlgorithm::calcFreqForSplitTwoWords(
firstCapitalizedWordDemotion ^ secondCapitalizedWordDemotion; firstCapitalizedWordDemotion ^ secondCapitalizedWordDemotion;
if (DEBUG_DICT_FULL) { if (DEBUG_DICT_FULL) {
LOGI("Two words: %c, %c, %d", word[0], word[firstWordLength + 1], capitalizedWordDemotion); AKLOGI("Two words: %c, %c, %d",
word[0], word[firstWordLength + 1], capitalizedWordDemotion);
} }
if (firstWordLength == 0 || secondWordLength == 0) { if (firstWordLength == 0 || secondWordLength == 0) {
@ -919,7 +920,7 @@ int Correction::RankingAlgorithm::calcFreqForSplitTwoWords(
if (isSpaceProximity) { if (isSpaceProximity) {
// A word pair with one space proximity correction // A word pair with one space proximity correction
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("Found a word pair with space proximity correction."); AKLOGI("Found a word pair with space proximity correction.");
} }
multiplyIntCapped(typedLetterMultiplier, &totalFreq); multiplyIntCapped(typedLetterMultiplier, &totalFreq);
multiplyRate(WORDS_WITH_PROXIMITY_CHARACTER_DEMOTION_RATE, &totalFreq); multiplyRate(WORDS_WITH_PROXIMITY_CHARACTER_DEMOTION_RATE, &totalFreq);
@ -965,10 +966,10 @@ inline static int editDistanceInternal(
} }
if (DEBUG_EDIT_DISTANCE) { if (DEBUG_EDIT_DISTANCE) {
LOGI("IN = %d, OUT = %d", beforeLength, afterLength); AKLOGI("IN = %d, OUT = %d", beforeLength, afterLength);
for (int i = 0; i < li; ++i) { for (int i = 0; i < li; ++i) {
for (int j = 0; j < lo; ++j) { for (int j = 0; j < lo; ++j) {
LOGI("EDIT[%d][%d], %d", i, j, dp[i * lo + j]); AKLOGI("EDIT[%d][%d], %d", i, j, dp[i * lo + j]);
} }
} }
} }

View File

@ -42,7 +42,7 @@ static inline unsigned char* convertToUnibyteStringAndReplaceLastChar(unsigned s
static inline void LOGI_S16(unsigned short* string, const unsigned int length) { static inline void LOGI_S16(unsigned short* string, const unsigned int length) {
unsigned char tmp_buffer[length]; unsigned char tmp_buffer[length];
convertToUnibyteString(string, tmp_buffer, length); convertToUnibyteString(string, tmp_buffer, length);
LOGI(">> %s", tmp_buffer); AKLOGI(">> %s", tmp_buffer);
// The log facility is throwing out log that comes too fast. The following // The log facility is throwing out log that comes too fast. The following
// is a dirty way of slowing down processing so that we can see all log. // is a dirty way of slowing down processing so that we can see all log.
// TODO : refactor this in a blocking log or something. // TODO : refactor this in a blocking log or something.
@ -53,7 +53,7 @@ static inline void LOGI_S16_PLUS(unsigned short* string, const unsigned int leng
unsigned char c) { unsigned char c) {
unsigned char tmp_buffer[length+1]; unsigned char tmp_buffer[length+1];
convertToUnibyteStringAndReplaceLastChar(string, tmp_buffer, length, c); convertToUnibyteStringAndReplaceLastChar(string, tmp_buffer, length, c);
LOGI(">> %s", tmp_buffer); AKLOGI(">> %s", tmp_buffer);
// Likewise // Likewise
// usleep(10); // usleep(10);
} }
@ -64,7 +64,7 @@ static inline void printDebug(const char* tag, int* codes, int codesSize, int MA
buf[codesSize] = 0; buf[codesSize] = 0;
while (--codesSize >= 0) while (--codesSize >= 0)
buf[codesSize] = (unsigned char)codes[codesSize * MAX_PROXIMITY_CHARS]; buf[codesSize] = (unsigned char)codes[codesSize * MAX_PROXIMITY_CHARS];
LOGI("%s, WORD = %s", tag, buf); AKLOGI("%s, WORD = %s", tag, buf);
free(buf); free(buf);
} }

View File

@ -20,15 +20,18 @@
#if defined(FLAG_DO_PROFILE) || defined(FLAG_DBG) #if defined(FLAG_DO_PROFILE) || defined(FLAG_DBG)
#include <cutils/log.h> #include <cutils/log.h>
#define AKLOGE ALOGE
#define AKLOGI ALOGI
#else #else
#define LOGE(fmt, ...) #define AKLOGE(fmt, ...)
#define LOGI(fmt, ...) #define AKLOGI(fmt, ...)
#endif #endif
#ifdef FLAG_DO_PROFILE #ifdef FLAG_DO_PROFILE
// Profiler // Profiler
#include <cutils/log.h> #include <cutils/log.h>
#include <time.h> #include <time.h>
#define PROF_BUF_SIZE 100 #define PROF_BUF_SIZE 100
static double profile_buf[PROF_BUF_SIZE]; static double profile_buf[PROF_BUF_SIZE];
static double profile_old[PROF_BUF_SIZE]; static double profile_old[PROF_BUF_SIZE];
@ -42,8 +45,8 @@ static unsigned int profile_counter[PROF_BUF_SIZE];
#define PROF_CLOSE do { PROF_END(PROF_BUF_SIZE - 1); PROF_OUTALL; } while(0) #define PROF_CLOSE do { PROF_END(PROF_BUF_SIZE - 1); PROF_OUTALL; } while(0)
#define PROF_END(prof_buf_id) profile_buf[prof_buf_id] += ((clock()) - profile_old[prof_buf_id]) #define PROF_END(prof_buf_id) profile_buf[prof_buf_id] += ((clock()) - profile_old[prof_buf_id])
#define PROF_CLOCKOUT(prof_buf_id) \ #define PROF_CLOCKOUT(prof_buf_id) \
LOGI("%s : clock is %f", __FUNCTION__, (clock() - profile_old[prof_buf_id])) AKLOGI("%s : clock is %f", __FUNCTION__, (clock() - profile_old[prof_buf_id]))
#define PROF_OUTALL do { LOGI("--- %s ---", __FUNCTION__); prof_out(); } while(0) #define PROF_OUTALL do { AKLOGI("--- %s ---", __FUNCTION__); prof_out(); } while(0)
static void prof_reset(void) { static void prof_reset(void) {
for (int i = 0; i < PROF_BUF_SIZE; ++i) { for (int i = 0; i < PROF_BUF_SIZE; ++i) {
@ -55,9 +58,9 @@ static void prof_reset(void) {
static void prof_out(void) { static void prof_out(void) {
if (profile_counter[PROF_BUF_SIZE - 1] != 1) { if (profile_counter[PROF_BUF_SIZE - 1] != 1) {
LOGI("Error: You must call PROF_OPEN before PROF_CLOSE."); AKLOGI("Error: You must call PROF_OPEN before PROF_CLOSE.");
} }
LOGI("Total time is %6.3f ms.", AKLOGI("Total time is %6.3f ms.",
profile_buf[PROF_BUF_SIZE - 1] * 1000 / (double)CLOCKS_PER_SEC); profile_buf[PROF_BUF_SIZE - 1] * 1000 / (double)CLOCKS_PER_SEC);
double all = 0; double all = 0;
for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) { for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
@ -66,7 +69,7 @@ static void prof_out(void) {
if (all == 0) all = 1; if (all == 0) all = 1;
for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) { for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
if (profile_buf[i] != 0) { if (profile_buf[i] != 0) {
LOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.", AKLOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.",
i, (profile_buf[i] * 100 / all), i, (profile_buf[i] * 100 / all),
profile_buf[i] * 1000 / (double)CLOCKS_PER_SEC, profile_counter[i]); profile_buf[i] * 1000 / (double)CLOCKS_PER_SEC, profile_counter[i]);
} }
@ -112,7 +115,7 @@ static void dumpWord(const unsigned short* word, const int length) {
charBuf[i] = word[i]; charBuf[i] = word[i];
} }
charBuf[length] = 0; charBuf[length] = 0;
LOGI("[ %s ]", charBuf); AKLOGI("[ %s ]", charBuf);
} }
#else // FLAG_DBG #else // FLAG_DBG

View File

@ -33,9 +33,9 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
IS_LATEST_DICT_VERSION((((unsigned char*) dict)[0] & 0xFF) >= DICTIONARY_VERSION_MIN) { IS_LATEST_DICT_VERSION((((unsigned char*) dict)[0] & 0xFF) >= DICTIONARY_VERSION_MIN) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
if (MAX_WORD_LENGTH_INTERNAL < maxWordLength) { if (MAX_WORD_LENGTH_INTERNAL < maxWordLength) {
LOGI("Max word length (%d) is greater than %d", AKLOGI("Max word length (%d) is greater than %d",
maxWordLength, MAX_WORD_LENGTH_INTERNAL); maxWordLength, MAX_WORD_LENGTH_INTERNAL);
LOGI("IN NATIVE SUGGEST Version: %d", (mDict[0] & 0xFF)); AKLOGI("IN NATIVE SUGGEST Version: %d", (mDict[0] & 0xFF));
} }
} }
mCorrection = new Correction(typedLetterMultiplier, fullWordMultiplier); mCorrection = new Correction(typedLetterMultiplier, fullWordMultiplier);

View File

@ -52,7 +52,7 @@ ProximityInfo::ProximityInfo(const int maxProximityCharsSize, const int keyboard
const int proximityGridLength = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE; const int proximityGridLength = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE;
mProximityCharsArray = new uint32_t[proximityGridLength]; mProximityCharsArray = new uint32_t[proximityGridLength];
if (DEBUG_PROXIMITY_INFO) { if (DEBUG_PROXIMITY_INFO) {
LOGI("Create proximity info array %d", proximityGridLength); AKLOGI("Create proximity info array %d", proximityGridLength);
} }
memcpy(mProximityCharsArray, proximityCharsArray, memcpy(mProximityCharsArray, proximityCharsArray,
proximityGridLength * sizeof(mProximityCharsArray[0])); proximityGridLength * sizeof(mProximityCharsArray[0]));
@ -102,7 +102,7 @@ inline int ProximityInfo::getStartIndexFromCoordinates(const int x, const int y)
bool ProximityInfo::hasSpaceProximity(const int x, const int y) const { bool ProximityInfo::hasSpaceProximity(const int x, const int y) const {
if (x < 0 || y < 0) { if (x < 0 || y < 0) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("HasSpaceProximity: Illegal coordinates (%d, %d)", x, y); AKLOGI("HasSpaceProximity: Illegal coordinates (%d, %d)", x, y);
assert(false); assert(false);
} }
return false; return false;
@ -110,11 +110,11 @@ bool ProximityInfo::hasSpaceProximity(const int x, const int y) const {
const int startIndex = getStartIndexFromCoordinates(x, y); const int startIndex = getStartIndexFromCoordinates(x, y);
if (DEBUG_PROXIMITY_INFO) { if (DEBUG_PROXIMITY_INFO) {
LOGI("hasSpaceProximity: index %d, %d, %d", startIndex, x, y); AKLOGI("hasSpaceProximity: index %d, %d, %d", startIndex, x, y);
} }
for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) { for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) {
if (DEBUG_PROXIMITY_INFO) { if (DEBUG_PROXIMITY_INFO) {
LOGI("Index: %d", mProximityCharsArray[startIndex + i]); AKLOGI("Index: %d", mProximityCharsArray[startIndex + i]);
} }
if (mProximityCharsArray[startIndex + i] == KEYCODE_SPACE) { if (mProximityCharsArray[startIndex + i] == KEYCODE_SPACE) {
return true; return true;

View File

@ -47,7 +47,7 @@ UnigramDictionary::UnigramDictionary(const uint8_t* const streamStart, int typed
BYTES_IN_ONE_CHAR(MAX_PROXIMITY_CHARS * sizeof(int)), BYTES_IN_ONE_CHAR(MAX_PROXIMITY_CHARS * sizeof(int)),
MAX_UMLAUT_SEARCH_DEPTH(DEFAULT_MAX_UMLAUT_SEARCH_DEPTH) { MAX_UMLAUT_SEARCH_DEPTH(DEFAULT_MAX_UMLAUT_SEARCH_DEPTH) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("UnigramDictionary - constructor"); AKLOGI("UnigramDictionary - constructor");
} }
} }
@ -163,14 +163,14 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo,
queuePool->getMasterQueue()->outputSuggestions(frequencies, outWords); queuePool->getMasterQueue()->outputSuggestions(frequencies, outWords);
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("Returning %d words", suggestedWordsCount); AKLOGI("Returning %d words", suggestedWordsCount);
/// Print the returned words /// Print the returned words
for (int j = 0; j < suggestedWordsCount; ++j) { for (int j = 0; j < suggestedWordsCount; ++j) {
#ifdef FLAG_DBG #ifdef FLAG_DBG
short unsigned int* w = outWords + j * MAX_WORD_LENGTH; short unsigned int* w = outWords + j * MAX_WORD_LENGTH;
char s[MAX_WORD_LENGTH]; char s[MAX_WORD_LENGTH];
for (int i = 0; i <= MAX_WORD_LENGTH; i++) s[i] = w[i]; for (int i = 0; i <= MAX_WORD_LENGTH; i++) s[i] = w[i];
LOGI("%s %i", s, frequencies[j]); AKLOGI("%s %i", s, frequencies[j]);
#endif #endif
} }
} }
@ -213,7 +213,7 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
&& inputLength >= MIN_USER_TYPED_LENGTH_FOR_MISSING_SPACE_SUGGESTION) { && inputLength >= MIN_USER_TYPED_LENGTH_FOR_MISSING_SPACE_SUGGESTION) {
for (int i = 1; i < inputLength; ++i) { for (int i = 1; i < inputLength; ++i) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("--- Suggest missing space characters %d", i); AKLOGI("--- Suggest missing space characters %d", i);
} }
getMissingSpaceWords(proximityInfo, xcoordinates, ycoordinates, codes, getMissingSpaceWords(proximityInfo, xcoordinates, ycoordinates, codes,
useFullEditDistance, inputLength, i, correction, queuePool); useFullEditDistance, inputLength, i, correction, queuePool);
@ -226,12 +226,12 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
// The first and last "mistyped spaces" are taken care of by excessive character handling // The first and last "mistyped spaces" are taken care of by excessive character handling
for (int i = 1; i < inputLength - 1; ++i) { for (int i = 1; i < inputLength - 1; ++i) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("--- Suggest words with proximity space %d", i); AKLOGI("--- Suggest words with proximity space %d", i);
} }
const int x = xcoordinates[i]; const int x = xcoordinates[i];
const int y = ycoordinates[i]; const int y = ycoordinates[i];
if (DEBUG_PROXIMITY_INFO) { if (DEBUG_PROXIMITY_INFO) {
LOGI("Input[%d] x = %d, y = %d, has space proximity = %d", AKLOGI("Input[%d] x = %d, y = %d, has space proximity = %d",
i, x, y, proximityInfo->hasSpaceProximity(x, y)); i, x, y, proximityInfo->hasSpaceProximity(x, y));
} }
if (proximityInfo->hasSpaceProximity(x, y)) { if (proximityInfo->hasSpaceProximity(x, y)) {
@ -247,7 +247,7 @@ void UnigramDictionary::initSuggestions(ProximityInfo *proximityInfo, const int
const int *yCoordinates, const int *codes, const int inputLength, const int *yCoordinates, const int *codes, const int inputLength,
WordsPriorityQueue *queue, Correction *correction) { WordsPriorityQueue *queue, Correction *correction) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("initSuggest"); AKLOGI("initSuggest");
} }
proximityInfo->setInputParams(codes, inputLength, xCoordinates, yCoordinates); proximityInfo->setInputParams(codes, inputLength, xCoordinates, yCoordinates);
if (queue) { if (queue) {
@ -390,7 +390,7 @@ void UnigramDictionary::getSplitTwoWordsSuggestions(ProximityInfo *proximityInfo
const int firstFreq = getMostFrequentWordLike( const int firstFreq = getMostFrequentWordLike(
firstWordStartPos, firstWordLength, proximityInfo, mWord); firstWordStartPos, firstWordLength, proximityInfo, mWord);
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("First freq: %d", firstFreq); AKLOGI("First freq: %d", firstFreq);
} }
if (firstFreq <= 0) return; if (firstFreq <= 0) return;
@ -401,7 +401,7 @@ void UnigramDictionary::getSplitTwoWordsSuggestions(ProximityInfo *proximityInfo
const int secondFreq = getMostFrequentWordLike( const int secondFreq = getMostFrequentWordLike(
secondWordStartPos, secondWordLength, proximityInfo, mWord); secondWordStartPos, secondWordLength, proximityInfo, mWord);
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("Second freq: %d", secondFreq); AKLOGI("Second freq: %d", secondFreq);
} }
if (secondFreq <= 0) return; if (secondFreq <= 0) return;
@ -419,7 +419,7 @@ void UnigramDictionary::getSplitTwoWordsSuggestions(ProximityInfo *proximityInfo
useFullEditDistance, false /* doAutoCompletion */, MAX_ERRORS_FOR_TWO_WORDS); useFullEditDistance, false /* doAutoCompletion */, MAX_ERRORS_FOR_TWO_WORDS);
const int pairFreq = correction->getFreqForSplitTwoWords(firstFreq, secondFreq, word); const int pairFreq = correction->getFreqForSplitTwoWords(firstFreq, secondFreq, word);
if (DEBUG_DICT) { if (DEBUG_DICT) {
LOGI("Split two words: %d, %d, %d, %d", firstFreq, secondFreq, pairFreq, inputLength); AKLOGI("Split two words: %d, %d, %d, %d", firstFreq, secondFreq, pairFreq, inputLength);
} }
addWord(word, newWordLength, pairFreq, masterQueue); addWord(word, newWordLength, pairFreq, masterQueue);
return; return;
@ -690,7 +690,7 @@ inline bool UnigramDictionary::processCurrentNode(const int initialPos,
*nextSiblingPosition = *nextSiblingPosition =
BinaryFormat::skipChildrenPosAndAttributes(DICT_ROOT, flags, pos); BinaryFormat::skipChildrenPosAndAttributes(DICT_ROOT, flags, pos);
if (DEBUG_DICT_FULL) { if (DEBUG_DICT_FULL) {
LOGI("Traversing was pruned."); AKLOGI("Traversing was pruned.");
} }
return false; return false;
} }

View File

@ -71,11 +71,11 @@ class WordsPriorityQueue {
sw->setParams(score, word, wordLength); sw->setParams(score, word, wordLength);
} }
if (sw == 0) { if (sw == 0) {
LOGE("SuggestedWord is accidentally null."); AKLOGE("SuggestedWord is accidentally null.");
return; return;
} }
if (DEBUG_WORDS_PRIORITY_QUEUE) { if (DEBUG_WORDS_PRIORITY_QUEUE) {
LOGI("Push word. %d, %d", score, wordLength); AKLOGI("Push word. %d, %d", score, wordLength);
DUMP_WORD(word, wordLength); DUMP_WORD(word, wordLength);
} }
mSuggestions.push(sw); mSuggestions.push(sw);
@ -94,7 +94,7 @@ class WordsPriorityQueue {
while (!mSuggestions.empty() && index >= 0) { while (!mSuggestions.empty() && index >= 0) {
SuggestedWord* sw = mSuggestions.top(); SuggestedWord* sw = mSuggestions.top();
if (DEBUG_WORDS_PRIORITY_QUEUE) { if (DEBUG_WORDS_PRIORITY_QUEUE) {
LOGI("dump word. %d", sw->mScore); AKLOGI("dump word. %d", sw->mScore);
DUMP_WORD(sw->mWord, sw->mWordLength); DUMP_WORD(sw->mWord, sw->mWordLength);
} }
const unsigned int wordLength = sw->mWordLength; const unsigned int wordLength = sw->mWordLength;
@ -120,7 +120,7 @@ class WordsPriorityQueue {
while (!mSuggestions.empty()) { while (!mSuggestions.empty()) {
SuggestedWord* sw = mSuggestions.top(); SuggestedWord* sw = mSuggestions.top();
if (DEBUG_WORDS_PRIORITY_QUEUE) { if (DEBUG_WORDS_PRIORITY_QUEUE) {
LOGI("Clear word. %d", sw->mScore); AKLOGI("Clear word. %d", sw->mScore);
DUMP_WORD(sw->mWord, sw->mWordLength); DUMP_WORD(sw->mWord, sw->mWordLength);
} }
sw->mUsed = false; sw->mUsed = false;