Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9fb6f47a authored by satok's avatar satok
Browse files

New LOG lib

Change-Id: I977e7e10fa58c0a64ca0c3c7b5cb2272446e3efe
parent b9604779
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
    PROF_START(66);
    const char *sourceDirChars = env->GetStringUTFChars(sourceDir, 0);
    if (sourceDirChars == 0) {
        LOGE("DICT: Can't get sourceDir string");
        AKLOGE("DICT: Can't get sourceDir string");
        return 0;
    }
    int fd = 0;
@@ -61,7 +61,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
    /* mmap version */
    fd = open(sourceDirChars, O_RDONLY);
    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;
    }
    int pagesize = getpagesize();
@@ -70,7 +70,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
    int adjDictSize = dictSize + adjust;
    dictBuf = mmap(0, sizeof(char) * adjDictSize, PROT_READ, MAP_PRIVATE, fd, adjDictOffset);
    if (dictBuf == MAP_FAILED) {
        LOGE("DICT: Can't mmap dictionary. errno=%d", errno);
        AKLOGE("DICT: Can't mmap dictionary. errno=%d", errno);
        return 0;
    }
    dictBuf = (void *)((char *)dictBuf + adjust);
@@ -79,39 +79,39 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
    FILE *file = 0;
    file = fopen(sourceDirChars, "rb");
    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;
    }
    dictBuf = malloc(sizeof(char) * dictSize);
    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;
    }
    int ret = fseek(file, (long)dictOffset, SEEK_SET);
    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;
    }
    ret = fread(dictBuf, sizeof(char) * dictSize, 1, file);
    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;
    }
    ret = fclose(file);
    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;
    }
#endif // USE_MMAP_FOR_DICTIONARY
    env->ReleaseStringUTFChars(sourceDir, sourceDirChars);

    if (!dictBuf) {
        LOGE("DICT: dictBuf is null");
        AKLOGE("DICT: dictBuf is null");
        return 0;
    }
    Dictionary *dictionary = 0;
    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
        releaseDictBuf(((char*)dictBuf) - adjust, adjDictSize, fd);
#else // USE_MMAP_FOR_DICTIONARY
@@ -230,11 +230,11 @@ void releaseDictBuf(void* dictBuf, const size_t length, int fd) {
#ifdef USE_MMAP_FOR_DICTIONARY
    int ret = munmap(dictBuf, length);
    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);
    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
    free(dictBuf);
+5 −5
Original line number Diff line number Diff line
@@ -36,18 +36,18 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
    jint result = -1;

    if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
        LOGE("ERROR: GetEnv failed");
        AKLOGE("ERROR: GetEnv failed");
        goto bail;
    }
    assert(env != 0);

    if (!register_BinaryDictionary(env)) {
        LOGE("ERROR: BinaryDictionary native registration failed");
        AKLOGE("ERROR: BinaryDictionary native registration failed");
        goto bail;
    }

    if (!register_ProximityInfo(env)) {
        LOGE("ERROR: ProximityInfo native registration failed");
        AKLOGE("ERROR: ProximityInfo native registration failed");
        goto bail;
    }

@@ -64,11 +64,11 @@ int registerNativeMethods(JNIEnv* env, const char* className, JNINativeMethod* m
        int numMethods) {
    jclass clazz = env->FindClass(className);
    if (clazz == 0) {
        LOGE("Native registration unable to find class '%s'", className);
        AKLOGE("Native registration unable to find class '%s'", className);
        return JNI_FALSE;
    }
    if (env->RegisterNatives(clazz, methods, numMethods) < 0) {
        LOGE("RegisterNatives failed for '%s'", className);
        AKLOGE("RegisterNatives failed for '%s'", className);
        env->DeleteLocalRef(clazz);
        return JNI_FALSE;
    }
+5 −5
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@ BigramDictionary::BigramDictionary(const unsigned char *dict, int maxWordLength,
    MAX_ALTERNATIVES(maxAlternatives), IS_LATEST_DICT_VERSION(isLatestDictVersion),
    HAS_BIGRAM(hasBigram), mParentDictionary(parentDictionary) {
    if (DEBUG_DICT) {
        LOGI("BigramDictionary - constructor");
        LOGI("Has Bigram : %d", hasBigram);
        AKLOGI("BigramDictionary - constructor");
        AKLOGI("Has Bigram : %d", hasBigram);
    }
}

@@ -46,7 +46,7 @@ bool BigramDictionary::addWordBigram(unsigned short *word, int length, int frequ
#ifdef FLAG_DBG
        char s[length + 1];
        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
    }

@@ -60,7 +60,7 @@ bool BigramDictionary::addWordBigram(unsigned short *word, int length, int frequ
        insertAt++;
    }
    if (DEBUG_DICT) {
        LOGI("Bigram: InsertAt -> %d maxBigrams: %d", insertAt, mMaxBigrams);
        AKLOGI("Bigram: InsertAt -> %d maxBigrams: %d", insertAt, mMaxBigrams);
    }
    if (insertAt < mMaxBigrams) {
        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
        if (DEBUG_DICT) {
            LOGI("Bigram: Added word at %d", insertAt);
            AKLOGI("Bigram: Added word at %d", insertAt);
        }
        return true;
    }
+17 −16
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ inline static void initEditDistance(int *editDistanceTable) {
inline static void dumpEditDistance10ForDebug(int *editDistanceTable, const int inputLength,
        const int outputLength) {
    if (DEBUG_DICT) {
        LOGI("EditDistanceTable");
        AKLOGI("EditDistanceTable");
        for (int i = 0; i <= 10; ++i) {
            int c[11];
            for (int j = 0; j <= 10; ++j) {
@@ -52,7 +52,7 @@ inline static void dumpEditDistance10ForDebug(int *editDistanceTable, const int
                    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]);
        }
    }
@@ -84,7 +84,7 @@ inline static void calcEditDistanceOneStep(int *editDistanceTable, const unsigne
inline static int getCurrentEditDistance(
        int *editDistanceTable, const int inputLength, const int outputLength) {
    if (DEBUG_DICT) {
        LOGI("getCurrentEditDistance %d, %d", inputLength, outputLength);
        AKLOGI("getCurrentEditDistance %d, %d", inputLength, outputLength);
    }
    return editDistanceTable[(inputLength + 1) * (outputLength + 1) - 1];
}
@@ -378,7 +378,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
            --mTransposedCount;
            if (DEBUG_CORRECTION) {
                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);
            }
            return UNRELATED;
@@ -404,7 +404,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
                && isEquivalentChar(mProximityInfo->getMatchedProximityId(
                        mInputIndex, mWord[mOutputIndex - 1], false))) {
            if (DEBUG_CORRECTION) {
                LOGI("CONVERSION p->e %c", mWord[mOutputIndex - 1]);
                AKLOGI("CONVERSION p->e %c", mWord[mOutputIndex - 1]);
            }
            // Conversion p->e
            // Example:
@@ -481,7 +481,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
        } else {
            if (DEBUG_CORRECTION) {
                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);
            }
            return UNRELATED;
@@ -534,7 +534,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
        mTerminalOutputIndex = mOutputIndex - 1;
        if (DEBUG_CORRECTION) {
            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);
        }
        return ON_TERMINAL;
@@ -703,7 +703,7 @@ int Correction::RankingAlgorithm::calculateFinalFreq(const int inputIndex, const
                / (10 * inputLength
                        - WORDS_WITH_MISSING_CHARACTER_DEMOTION_START_POS_10X + 10);
        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);
    }
@@ -717,7 +717,7 @@ int Correction::RankingAlgorithm::calculateFinalFreq(const int inputIndex, const
        multiplyRate(WORDS_WITH_EXCESSIVE_CHARACTER_DEMOTION_RATE, &finalFreq);
        if (!lastCharExceeded && !proximityInfo->existsAdjacentProximityChars(excessivePos)) {
            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,
            // we will demote this word.
@@ -767,7 +767,7 @@ int Correction::RankingAlgorithm::calculateFinalFreq(const int inputIndex, const
        for (int i = 0; i < adjustedProximityMatchedCount; ++i) {
            // A word with proximity corrections
            if (DEBUG_DICT_FULL) {
                LOGI("Found a proximity correction.");
                AKLOGI("Found a proximity correction.");
            }
            multiplyIntCapped(typedLetterMultiplier, &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) {
        LOGI("calc: %d, %d", outputIndex, sameLength);
        AKLOGI("calc: %d, %d", outputIndex, sameLength);
    }

    if (DEBUG_CORRECTION_FREQ) {
        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,
                quoteDiffCount, ed, finalFreq);
    }
@@ -874,7 +874,8 @@ int Correction::RankingAlgorithm::calcFreqForSplitTwoWords(
            firstCapitalizedWordDemotion ^ secondCapitalizedWordDemotion;

    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) {
@@ -919,7 +920,7 @@ int Correction::RankingAlgorithm::calcFreqForSplitTwoWords(
    if (isSpaceProximity) {
        // A word pair with one space proximity correction
        if (DEBUG_DICT) {
            LOGI("Found a word pair with space proximity correction.");
            AKLOGI("Found a word pair with space proximity correction.");
        }
        multiplyIntCapped(typedLetterMultiplier, &totalFreq);
        multiplyRate(WORDS_WITH_PROXIMITY_CHARACTER_DEMOTION_RATE, &totalFreq);
@@ -965,10 +966,10 @@ inline static int editDistanceInternal(
    }

    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 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]);
            }
        }
    }
+3 −3
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ static inline unsigned char* convertToUnibyteStringAndReplaceLastChar(unsigned s
static inline void LOGI_S16(unsigned short* string, const unsigned int length) {
    unsigned char 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
    // is a dirty way of slowing down processing so that we can see all log.
    // 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 tmp_buffer[length+1];
    convertToUnibyteStringAndReplaceLastChar(string, tmp_buffer, length, c);
    LOGI(">> %s", tmp_buffer);
    AKLOGI(">> %s", tmp_buffer);
    // Likewise
    // usleep(10);
}
@@ -64,7 +64,7 @@ static inline void printDebug(const char* tag, int* codes, int codesSize, int MA
    buf[codesSize] = 0;
    while (--codesSize >= 0)
        buf[codesSize] = (unsigned char)codes[codesSize * MAX_PROXIMITY_CHARS];
    LOGI("%s, WORD = %s", tag, buf);
    AKLOGI("%s, WORD = %s", tag, buf);

    free(buf);
}
Loading