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

Commit 8e7c4b68 authored by Yiwei Zhang's avatar Yiwei Zhang
Browse files

GpuStats: Track ANGLE usage info

This change enables tracking for ANGLE usage and driver loading. This change
also removes a redundant api and some redundant logics, because driver loading
in GL loader has been cleaned up.

Bug: 132285967
Test: enable angle and dumpsys gpu
Change-Id: Idf20e86ddfb471a218d5ccd09a0e63f697e60274
parent 174a2a0e
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ status_t GpuStatsGlobalInfo::writeToParcel(Parcel* parcel) const {
    if ((status = parcel->writeInt32(vulkanVersion)) != OK) return status;
    if ((status = parcel->writeInt32(cpuVulkanVersion)) != OK) return status;
    if ((status = parcel->writeInt32(glesVersion)) != OK) return status;
    if ((status = parcel->writeInt32(angleLoadingCount)) != OK) return status;
    if ((status = parcel->writeInt32(angleLoadingFailureCount)) != OK) return status;
    return OK;
}

@@ -53,6 +55,8 @@ status_t GpuStatsGlobalInfo::readFromParcel(const Parcel* parcel) {
    if ((status = parcel->readInt32(&vulkanVersion)) != OK) return status;
    if ((status = parcel->readInt32(&cpuVulkanVersion)) != OK) return status;
    if ((status = parcel->readInt32(&glesVersion)) != OK) return status;
    if ((status = parcel->readInt32(&angleLoadingCount)) != OK) return status;
    if ((status = parcel->readInt32(&angleLoadingFailureCount)) != OK) return status;
    return OK;
}

@@ -64,6 +68,8 @@ std::string GpuStatsGlobalInfo::toString() const {
    StringAppendF(&result, "driverBuildTime = %" PRId64 "\n", driverBuildTime);
    StringAppendF(&result, "glLoadingCount = %d\n", glLoadingCount);
    StringAppendF(&result, "glLoadingFailureCount = %d\n", glLoadingFailureCount);
    StringAppendF(&result, "angleLoadingCount = %d\n", angleLoadingCount);
    StringAppendF(&result, "angleLoadingFailureCount = %d\n", angleLoadingFailureCount);
    StringAppendF(&result, "vkLoadingCount = %d\n", vkLoadingCount);
    StringAppendF(&result, "vkLoadingFailureCount = %d\n", vkLoadingFailureCount);
    StringAppendF(&result, "vulkanVersion = %d\n", vulkanVersion);
@@ -78,6 +84,7 @@ status_t GpuStatsAppInfo::writeToParcel(Parcel* parcel) const {
    if ((status = parcel->writeUint64(driverVersionCode)) != OK) return status;
    if ((status = parcel->writeInt64Vector(glDriverLoadingTime)) != OK) return status;
    if ((status = parcel->writeInt64Vector(vkDriverLoadingTime)) != OK) return status;
    if ((status = parcel->writeInt64Vector(angleDriverLoadingTime)) != OK) return status;
    return OK;
}

@@ -87,6 +94,7 @@ status_t GpuStatsAppInfo::readFromParcel(const Parcel* parcel) {
    if ((status = parcel->readUint64(&driverVersionCode)) != OK) return status;
    if ((status = parcel->readInt64Vector(&glDriverLoadingTime)) != OK) return status;
    if ((status = parcel->readInt64Vector(&vkDriverLoadingTime)) != OK) return status;
    if ((status = parcel->readInt64Vector(&angleDriverLoadingTime)) != OK) return status;
    return OK;
}

@@ -99,6 +107,11 @@ std::string GpuStatsAppInfo::toString() const {
        StringAppendF(&result, " %d", loadingTime);
    }
    result.append("\n");
    result.append("angleDriverLoadingTime:");
    for (int32_t loadingTime : angleDriverLoadingTime) {
        StringAppendF(&result, " %d", loadingTime);
    }
    result.append("\n");
    result.append("vkDriverLoadingTime:");
    for (int32_t loadingTime : vkDriverLoadingTime) {
        StringAppendF(&result, " %d", loadingTime);
+2 −13
Original line number Diff line number Diff line
@@ -228,9 +228,8 @@ void GraphicsEnv::setDriverLoaded(GraphicsEnv::Api api, bool isLoaded, int64_t d
    bool isIntendedDriverLoaded = false;
    if (api == GraphicsEnv::Api::API_GL) {
        driver = mGpuStats.glDriverToLoad;
        isIntendedDriverLoaded = isLoaded &&
                ((mGpuStats.glDriverFallback == GraphicsEnv::Driver::NONE) ||
                 (mGpuStats.glDriverToLoad == mGpuStats.glDriverFallback));
        isIntendedDriverLoaded =
                isLoaded && (mGpuStats.glDriverFallback == GraphicsEnv::Driver::NONE);
    } else {
        driver = mGpuStats.vkDriverToLoad;
        isIntendedDriverLoaded =
@@ -240,16 +239,6 @@ void GraphicsEnv::setDriverLoaded(GraphicsEnv::Api api, bool isLoaded, int64_t d
    sendGpuStatsLocked(driver, isIntendedDriverLoaded, driverLoadingTime);
}

void GraphicsEnv::clearDriverLoadingInfo(GraphicsEnv::Api api) {
    ATRACE_CALL();

    std::lock_guard<std::mutex> lock(mStatsLock);
    if (api == GraphicsEnv::Api::API_GL) {
        mGpuStats.glDriverToLoad = GraphicsEnv::Driver::NONE;
        mGpuStats.glDriverFallback = GraphicsEnv::Driver::NONE;
    }
}

static sp<IGpuService> getGpuService() {
    const sp<IBinder> binder = defaultServiceManager()->checkService(String16("gpu"));
    if (!binder) {
+3 −0
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ public:
    int32_t vulkanVersion = 0;
    int32_t cpuVulkanVersion = 0;
    int32_t glesVersion = 0;
    int32_t angleLoadingCount = 0;
    int32_t angleLoadingFailureCount = 0;
};

/*
@@ -66,6 +68,7 @@ public:
    uint64_t driverVersionCode = 0;
    std::vector<int64_t> glDriverLoadingTime = {};
    std::vector<int64_t> vkDriverLoadingTime = {};
    std::vector<int64_t> angleDriverLoadingTime = {};
};

} // namespace android
+0 −1
Original line number Diff line number Diff line
@@ -89,7 +89,6 @@ public:
                     const std::string& appPackageName, const int32_t vulkanVersion);
    void setDriverToLoad(Driver driver);
    void setDriverLoaded(Api api, bool isDriverLoaded, int64_t driverLoadingTime);
    void clearDriverLoadingInfo(Api api);
    void sendGpuStatsLocked(Driver driver, bool isDriverLoaded, int64_t driverLoadingTime);

    bool shouldUseAngle(std::string appName);
+20 −15
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@

namespace android {

static bool addLoadingCount(GraphicsEnv::Driver driver, bool isDriverLoaded,
static void addLoadingCount(GraphicsEnv::Driver driver, bool isDriverLoaded,
                            GpuStatsGlobalInfo* const outGlobalInfo) {
    switch (driver) {
        case GraphicsEnv::Driver::GL:
@@ -40,13 +40,13 @@ static bool addLoadingCount(GraphicsEnv::Driver driver, bool isDriverLoaded,
            outGlobalInfo->vkLoadingCount++;
            if (!isDriverLoaded) outGlobalInfo->vkLoadingFailureCount++;
            break;
        case GraphicsEnv::Driver::ANGLE:
            outGlobalInfo->angleLoadingCount++;
            if (!isDriverLoaded) outGlobalInfo->angleLoadingFailureCount++;
            break;
        default:
            // Currently we don't support GraphicsEnv::Driver::ANGLE because the
            // basic driver package info only belongs to system or updated driver.
            return false;
            break;
    }

    return true;
}

static void addLoadingTime(GraphicsEnv::Driver driver, int64_t driverLoadingTime,
@@ -54,13 +54,20 @@ static void addLoadingTime(GraphicsEnv::Driver driver, int64_t driverLoadingTime
    switch (driver) {
        case GraphicsEnv::Driver::GL:
        case GraphicsEnv::Driver::GL_UPDATED:
            if (outAppInfo->glDriverLoadingTime.size() >= GpuStats::MAX_NUM_LOADING_TIMES) break;
            if (outAppInfo->glDriverLoadingTime.size() < GpuStats::MAX_NUM_LOADING_TIMES) {
                outAppInfo->glDriverLoadingTime.emplace_back(driverLoadingTime);
            }
            break;
        case GraphicsEnv::Driver::VULKAN:
        case GraphicsEnv::Driver::VULKAN_UPDATED:
            if (outAppInfo->vkDriverLoadingTime.size() >= GpuStats::MAX_NUM_LOADING_TIMES) break;
            if (outAppInfo->vkDriverLoadingTime.size() < GpuStats::MAX_NUM_LOADING_TIMES) {
                outAppInfo->vkDriverLoadingTime.emplace_back(driverLoadingTime);
            }
            break;
        case GraphicsEnv::Driver::ANGLE:
            if (outAppInfo->angleDriverLoadingTime.size() < GpuStats::MAX_NUM_LOADING_TIMES) {
                outAppInfo->angleDriverLoadingTime.emplace_back(driverLoadingTime);
            }
            break;
        default:
            break;
@@ -90,17 +97,15 @@ void GpuStats::insert(const std::string& driverPackageName, const std::string& d

    if (!mGlobalStats.count(driverVersionCode)) {
        GpuStatsGlobalInfo globalInfo;
        if (!addLoadingCount(driver, isDriverLoaded, &globalInfo)) {
            return;
        }
        addLoadingCount(driver, isDriverLoaded, &globalInfo);
        globalInfo.driverPackageName = driverPackageName;
        globalInfo.driverVersionName = driverVersionName;
        globalInfo.driverVersionCode = driverVersionCode;
        globalInfo.driverBuildTime = driverBuildTime;
        globalInfo.vulkanVersion = vulkanVersion;
        mGlobalStats.insert({driverVersionCode, globalInfo});
    } else if (!addLoadingCount(driver, isDriverLoaded, &mGlobalStats[driverVersionCode])) {
        return;
    } else {
        addLoadingCount(driver, isDriverLoaded, &mGlobalStats[driverVersionCode]);
    }

    if (mAppStats.size() >= MAX_NUM_APP_RECORDS) {