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

Commit 76a4b3e6 authored by Andy Hung's avatar Andy Hung Committed by Automerger Merge Worker
Browse files

Merge "MediaMetrics: Tune garbage collection" into rvc-dev am: d25de3ab

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/av/+/11931278

Change-Id: Ib64efb3b60e8bbd0d5f49bb3cd91ad2b7c0599b2
parents 53134271 d25de3ab
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -93,7 +93,7 @@ public:
        int32_t ll = lines;
        int32_t ll = lines;


        if (ll > 0) {
        if (ll > 0) {
            ss << "TransactionLog:\n";
            ss << "TransactionLog: gc(" << mTransactionLog.getGarbageCollectionCount() << ")\n";
            --ll;
            --ll;
        }
        }
        if (ll > 0) {
        if (ll > 0) {
@@ -102,7 +102,7 @@ public:
            ll -= l;
            ll -= l;
        }
        }
        if (ll > 0) {
        if (ll > 0) {
            ss << "TimeMachine:\n";
            ss << "TimeMachine: gc(" << mTimeMachine.getGarbageCollectionCount() << ")\n";
            --ll;
            --ll;
        }
        }
        if (ll > 0) {
        if (ll > 0) {
+14 −6
Original line number Original line Diff line number Diff line
@@ -220,10 +220,10 @@ private:


    using History = std::map<std::string /* key */, std::shared_ptr<KeyHistory>>;
    using History = std::map<std::string /* key */, std::shared_ptr<KeyHistory>>;


    static inline constexpr size_t kTimeSequenceMaxElements = 100;
    static inline constexpr size_t kTimeSequenceMaxElements = 50;
    static inline constexpr size_t kKeyMaxProperties = 100;
    static inline constexpr size_t kKeyMaxProperties = 50;
    static inline constexpr size_t kKeyLowWaterMark = 500;
    static inline constexpr size_t kKeyLowWaterMark = 400;
    static inline constexpr size_t kKeyHighWaterMark = 1000;
    static inline constexpr size_t kKeyHighWaterMark = 500;


    // Estimated max data space usage is 3KB * kKeyHighWaterMark.
    // Estimated max data space usage is 3KB * kKeyHighWaterMark.


@@ -255,6 +255,7 @@ public:
        {
        {
            std::lock_guard lock2(other.mLock);
            std::lock_guard lock2(other.mLock);
            mHistory = other.mHistory;
            mHistory = other.mHistory;
            mGarbageCollectionCount = other.mGarbageCollectionCount.load();
        }
        }


        // Now that we safely have our own shared pointers, let's dup them
        // Now that we safely have our own shared pointers, let's dup them
@@ -420,6 +421,7 @@ public:
    void clear() {
    void clear() {
        std::lock_guard lock(mLock);
        std::lock_guard lock(mLock);
        mHistory.clear();
        mHistory.clear();
        mGarbageCollectionCount = 0;
    }
    }


    /**
    /**
@@ -453,6 +455,10 @@ public:
        return { ss.str(), lines - ll };
        return { ss.str(), lines - ll };
    }
    }


    size_t getGarbageCollectionCount() const {
        return mGarbageCollectionCount;
    }

private:
private:


    // Obtains the lock for a KeyHistory.
    // Obtains the lock for a KeyHistory.
@@ -496,8 +502,6 @@ private:
        // TODO: something better than this for garbage collection.
        // TODO: something better than this for garbage collection.
        if (mHistory.size() < mKeyHighWaterMark) return false;
        if (mHistory.size() < mKeyHighWaterMark) return false;


        ALOGD("%s: garbage collection", __func__);

        // erase everything explicitly expired.
        // erase everything explicitly expired.
        std::multimap<int64_t, std::string> accessList;
        std::multimap<int64_t, std::string> accessList;
        // use a stale vector with precise type to avoid type erasure overhead in garbage
        // use a stale vector with precise type to avoid type erasure overhead in garbage
@@ -534,12 +538,16 @@ private:
        ALOGD("%s(%zu, %zu): key size:%zu",
        ALOGD("%s(%zu, %zu): key size:%zu",
                __func__, mKeyLowWaterMark, mKeyHighWaterMark,
                __func__, mKeyLowWaterMark, mKeyHighWaterMark,
                mHistory.size());
                mHistory.size());

        ++mGarbageCollectionCount;
        return true;
        return true;
    }
    }


    const size_t mKeyLowWaterMark = kKeyLowWaterMark;
    const size_t mKeyLowWaterMark = kKeyLowWaterMark;
    const size_t mKeyHighWaterMark = kKeyHighWaterMark;
    const size_t mKeyHighWaterMark = kKeyHighWaterMark;


    std::atomic<size_t> mGarbageCollectionCount{};

    /**
    /**
     * Locking Strategy
     * Locking Strategy
     *
     *
+11 −4
Original line number Original line Diff line number Diff line
@@ -43,9 +43,9 @@ public:
    // Transaction Log between the Low Water Mark and the High Water Mark.
    // Transaction Log between the Low Water Mark and the High Water Mark.


    // low water mark
    // low water mark
    static inline constexpr size_t kLogItemsLowWater = 5000;
    static inline constexpr size_t kLogItemsLowWater = 1700;
    // high water mark
    // high water mark
    static inline constexpr size_t kLogItemsHighWater = 10000;
    static inline constexpr size_t kLogItemsHighWater = 2000;


    // Estimated max data usage is 1KB * kLogItemsHighWater.
    // Estimated max data usage is 1KB * kLogItemsHighWater.


@@ -79,6 +79,7 @@ public:
        std::lock_guard lock2(other.mLock);
        std::lock_guard lock2(other.mLock);
        mLog = other.mLog;
        mLog = other.mLog;
        mItemMap = other.mItemMap;
        mItemMap = other.mItemMap;
        mGarbageCollectionCount = other.mGarbageCollectionCount.load();


        return *this;
        return *this;
    }
    }
@@ -181,6 +182,11 @@ public:
        std::lock_guard lock(mLock);
        std::lock_guard lock(mLock);
        mLog.clear();
        mLog.clear();
        mItemMap.clear();
        mItemMap.clear();
        mGarbageCollectionCount = 0;
    }

    size_t getGarbageCollectionCount() const {
        return mGarbageCollectionCount;
    }
    }


private:
private:
@@ -216,8 +222,6 @@ private:
    bool gc(std::vector<std::any>& garbage) REQUIRES(mLock) {
    bool gc(std::vector<std::any>& garbage) REQUIRES(mLock) {
        if (mLog.size() < mHighWaterMark) return false;
        if (mLog.size() < mHighWaterMark) return false;


        ALOGD("%s: garbage collection", __func__);

        auto eraseEnd = mLog.begin();
        auto eraseEnd = mLog.begin();
        size_t toRemove = mLog.size() - mLowWaterMark;
        size_t toRemove = mLog.size() - mLowWaterMark;
        // remove at least those elements.
        // remove at least those elements.
@@ -265,6 +269,7 @@ private:
        ALOGD("%s(%zu, %zu): log size:%zu item map size:%zu, item map items:%zu",
        ALOGD("%s(%zu, %zu): log size:%zu item map size:%zu, item map items:%zu",
                __func__, mLowWaterMark, mHighWaterMark,
                __func__, mLowWaterMark, mHighWaterMark,
                mLog.size(), mItemMap.size(), itemMapCount);
                mLog.size(), mItemMap.size(), itemMapCount);
        ++mGarbageCollectionCount;
        return true;
        return true;
    }
    }


@@ -287,6 +292,8 @@ private:
    const size_t mLowWaterMark = kLogItemsLowWater;
    const size_t mLowWaterMark = kLogItemsLowWater;
    const size_t mHighWaterMark = kLogItemsHighWater;
    const size_t mHighWaterMark = kLogItemsHighWater;


    std::atomic<size_t> mGarbageCollectionCount{};

    mutable std::mutex mLock;
    mutable std::mutex mLock;


    MapTimeItem mLog GUARDED_BY(mLock);
    MapTimeItem mLog GUARDED_BY(mLock);