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

Commit 6b979fa9 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "More benchmark tweaks" into sc-dev am: 5c681088

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

Change-Id: I44266a17ef7f5d8fc6f2caf1ceb2bb8e9586f0ea
parents 368a5235 5c681088
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -86,12 +86,9 @@ void SkiaMemoryTracer::processElement() {
            }
        }

        // if we don't have a resource name then we don't know how to label the
        // data and should abort.
        // if we don't have a pretty name then use the dumpName
        if (resourceName == nullptr) {
            mCurrentElement.clear();
            mCurrentValues.clear();
            return;
            resourceName = mCurrentElement.c_str();
        }

        auto result = mResults.find(resourceName);
@@ -157,6 +154,14 @@ void SkiaMemoryTracer::logOutput(String8& log) {
    }
}

size_t SkiaMemoryTracer::total() {
    processElement();
    if (!strcmp("bytes", mTotalSize.units)) {
        return mTotalSize.value;
    }
    return 0;
}

void SkiaMemoryTracer::logTotals(String8& log) {
    TraceValue total = convertUnits(mTotalSize);
    TraceValue purgeable = convertUnits(mPurgeableSize);
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ public:
    bool hasOutput();
    void logOutput(String8& log);
    void logTotals(String8& log);
    size_t total();

    void dumpNumericValue(const char* dumpName, const char* valueName, const char* units,
                          uint64_t value) override;
+20 −4
Original line number Diff line number Diff line
@@ -130,27 +130,43 @@ void CacheManager::trimStaleResources() {
    mGrContext->purgeResourcesNotUsedInMs(std::chrono::seconds(30));
}

void CacheManager::getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage) {
    *cpuUsage = 0;
    *gpuUsage = 0;
    if (!mGrContext) {
        return;
    }

    skiapipeline::SkiaMemoryTracer cpuTracer("category", true);
    SkGraphics::DumpMemoryStatistics(&cpuTracer);
    *cpuUsage += cpuTracer.total();

    skiapipeline::SkiaMemoryTracer gpuTracer("category", true);
    mGrContext->dumpMemoryStatistics(&gpuTracer);
    *gpuUsage += gpuTracer.total();
}

void CacheManager::dumpMemoryUsage(String8& log, const RenderState* renderState) {
    if (!mGrContext) {
        log.appendFormat("No valid cache instance.\n");
        return;
    }

    log.appendFormat("Font Cache (CPU):\n");
    log.appendFormat("  Size: %.2f kB \n", SkGraphics::GetFontCacheUsed() / 1024.0f);
    log.appendFormat("  Glyph Count: %d \n", SkGraphics::GetFontCacheCountUsed());

    std::vector<skiapipeline::ResourcePair> cpuResourceMap = {
            {"skia/sk_resource_cache/bitmap_", "Bitmaps"},
            {"skia/sk_resource_cache/rrect-blur_", "Masks"},
            {"skia/sk_resource_cache/rects-blur_", "Masks"},
            {"skia/sk_resource_cache/tessellated", "Shadows"},
            {"skia/sk_glyph_cache", "Glyph Cache"},
    };
    skiapipeline::SkiaMemoryTracer cpuTracer(cpuResourceMap, false);
    SkGraphics::DumpMemoryStatistics(&cpuTracer);
    if (cpuTracer.hasOutput()) {
        log.appendFormat("CPU Caches:\n");
        cpuTracer.logOutput(log);
        log.appendFormat("  Glyph Count: %d \n", SkGraphics::GetFontCacheCountUsed());
        log.appendFormat("Total CPU memory usage:\n");
        cpuTracer.logTotals(log);
    }

    skiapipeline::SkiaMemoryTracer gpuTracer("category", true);
+1 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ public:
    void trimMemory(TrimMemoryMode mode);
    void trimStaleResources();
    void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr);
    void getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage);

    size_t getCacheSize() const { return mMaxResourceBytes; }
    size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; }
+18 −0
Original line number Diff line number Diff line
@@ -195,6 +195,17 @@ void RenderProxy::trimMemory(int level) {
    }
}

void RenderProxy::purgeCaches() {
    if (RenderThread::hasInstance()) {
        RenderThread& thread = RenderThread::getInstance();
        thread.queue().post([&thread]() {
            if (thread.getGrContext()) {
                thread.cacheManager().trimMemory(CacheManager::TrimMemoryMode::Complete);
            }
        });
    }
}

void RenderProxy::overrideProperty(const char* name, const char* value) {
    // expensive, but block here since name/value pointers owned by caller
    RenderThread::getInstance().queue().runSync(
@@ -256,6 +267,13 @@ void RenderProxy::dumpGraphicsMemory(int fd, bool includeProfileData) {
    }
}

void RenderProxy::getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage) {
    if (RenderThread::hasInstance()) {
        auto& thread = RenderThread::getInstance();
        thread.queue().runSync([&]() { thread.getMemoryUsage(cpuUsage, gpuUsage); });
    }
}

void RenderProxy::setProcessStatsBuffer(int fd) {
    auto& rt = RenderThread::getInstance();
    rt.queue().post([&rt, fd = dup(fd)]() {
Loading