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

Commit b625effb authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add default shortcut for tracing Skia's GPU memory usage" into main

parents 0ad1bead 1083707b
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ std::optional<std::int32_t> render_ahead() {

bool Properties::debugLayersUpdates = false;
bool Properties::debugOverdraw = false;
bool Properties::debugTraceGpuResourceCategories = false;
bool Properties::showDirtyRegions = false;
bool Properties::skipEmptyFrames = true;
bool Properties::useBufferAge = true;
@@ -151,10 +152,12 @@ bool Properties::load() {

    skpCaptureEnabled = debuggingEnabled && base::GetBoolProperty(PROPERTY_CAPTURE_SKP_ENABLED, false);

    SkAndroidFrameworkTraceUtil::setEnableTracing(
            base::GetBoolProperty(PROPERTY_SKIA_TRACING_ENABLED, false));
    bool skiaBroadTracing = base::GetBoolProperty(PROPERTY_SKIA_TRACING_ENABLED, false);
    SkAndroidFrameworkTraceUtil::setEnableTracing(skiaBroadTracing);
    SkAndroidFrameworkTraceUtil::setUsePerfettoTrackEvents(
            base::GetBoolProperty(PROPERTY_SKIA_USE_PERFETTO_TRACK_EVENTS, false));
    debugTraceGpuResourceCategories =
            base::GetBoolProperty(PROPERTY_TRACE_GPU_RESOURCES, skiaBroadTracing);

    runningInEmulator = base::GetBoolProperty(PROPERTY_IS_EMULATOR, false);

+10 −0
Original line number Diff line number Diff line
@@ -142,6 +142,15 @@ enum DebugLevel {
 */
#define PROPERTY_CAPTURE_SKP_ENABLED "debug.hwui.capture_skp_enabled"

/**
 * Might split Skia's GPU resource utilization into separate tracing tracks (slow).
 *
 * Aggregate total and purgeable numbers will still be reported under a "misc" track when this is
 * disabled, they just won't be split into distinct categories. Results may vary depending on GPU
 * backend/API, and the category mappings defined in ATraceMemoryDump's hardcoded sResourceMap.
 */
#define PROPERTY_TRACE_GPU_RESOURCES "debug.hwui.trace_gpu_resources"

/**
 * Allows broad recording of Skia drawing commands.
 *
@@ -254,6 +263,7 @@ public:

    static bool debugLayersUpdates;
    static bool debugOverdraw;
    static bool debugTraceGpuResourceCategories;
    static bool showDirtyRegions;
    // TODO: Remove after stabilization period
    static bool skipEmptyFrames;
+25 −1
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@

#include <cstring>

#include "GrDirectContext.h"

namespace android {
namespace uirenderer {
namespace skiapipeline {
@@ -114,8 +116,16 @@ void ATraceMemoryDump::startFrame() {

/**
 * logTraces reads from mCurrentValues and logs the counters with ATRACE.
 *
 * gpuMemoryIsAlreadyInDump must be true if GrDirectContext::dumpMemoryStatistics(...) was called
 * with this tracer, false otherwise. Leaving this false allows this function to quickly query total
 * and purgable GPU memory without the caller having to spend time in
 * GrDirectContext::dumpMemoryStatistics(...) first, which iterates over every resource in the GPU
 * cache. This can save significant time, but buckets all GPU memory into a single "misc" track,
 * which may be a loss of granularity depending on the GPU backend and the categories defined in
 * sResourceMap.
 */
void ATraceMemoryDump::logTraces() {
void ATraceMemoryDump::logTraces(bool gpuMemoryIsAlreadyInDump, GrDirectContext* grContext) {
    // Accumulate data from last dumpName
    recordAndResetCountersIfNeeded("");
    uint64_t hwui_all_frame_memory = 0;
@@ -126,6 +136,20 @@ void ATraceMemoryDump::logTraces() {
            ATRACE_INT64((std::string("Purgeable ") + it.first).c_str(), it.second.purgeableMemory);
        }
    }

    if (!gpuMemoryIsAlreadyInDump && grContext) {
        // Total GPU memory
        int gpuResourceCount;
        size_t gpuResourceBytes;
        grContext->getResourceCacheUsage(&gpuResourceCount, &gpuResourceBytes);
        hwui_all_frame_memory += (uint64_t)gpuResourceBytes;
        ATRACE_INT64("HWUI Misc Memory", gpuResourceBytes);

        // Purgable subset of GPU memory
        size_t purgeableGpuResourceBytes = grContext->getResourceCachePurgeableBytes();
        ATRACE_INT64("Purgeable HWUI Misc Memory", purgeableGpuResourceBytes);
    }

    ATRACE_INT64("HWUI All Memory", hwui_all_frame_memory);
}

+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#pragma once

#include <GrDirectContext.h>
#include <SkString.h>
#include <SkTraceMemoryDump.h>

@@ -50,7 +51,7 @@ public:

    void startFrame();

    void logTraces();
    void logTraces(bool gpuMemoryIsAlreadyInDump, GrDirectContext* grContext);

private:
    std::string mLastDumpName;
+3 −2
Original line number Diff line number Diff line
@@ -269,13 +269,14 @@ void CacheManager::onFrameCompleted() {
    cancelDestroyContext();
    mFrameCompletions.next() = systemTime(CLOCK_MONOTONIC);
    if (ATRACE_ENABLED()) {
        ATRACE_NAME("dumpingMemoryStatistics");
        static skiapipeline::ATraceMemoryDump tracer;
        tracer.startFrame();
        SkGraphics::DumpMemoryStatistics(&tracer);
        if (mGrContext) {
        if (mGrContext && Properties::debugTraceGpuResourceCategories) {
            mGrContext->dumpMemoryStatistics(&tracer);
        }
        tracer.logTraces();
        tracer.logTraces(Properties::debugTraceGpuResourceCategories, mGrContext.get());
    }
}