GpuStats: move GpuStats related structs and enums away from GraphicsEnv
Bug: 135210726
Test: build, flash and boot
Test: adb shell dumpsys gpu
Change-Id: I48c5c432aca916f923ab5674f8ec533d4f5aac0f
diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp
index 24b6c2d..a411dd5 100644
--- a/libs/graphicsenv/GraphicsEnv.cpp
+++ b/libs/graphicsenv/GraphicsEnv.cpp
@@ -170,11 +170,11 @@
std::lock_guard<std::mutex> lock(mStatsLock);
if (mGpuStats.glDriverToSend) {
mGpuStats.glDriverToSend = false;
- sendGpuStatsLocked(GraphicsEnv::Api::API_GL, true, mGpuStats.glDriverLoadingTime);
+ sendGpuStatsLocked(GpuStatsInfo::Api::API_GL, true, mGpuStats.glDriverLoadingTime);
}
if (mGpuStats.vkDriverToSend) {
mGpuStats.vkDriverToSend = false;
- sendGpuStatsLocked(GraphicsEnv::Api::API_VK, true, mGpuStats.vkDriverLoadingTime);
+ sendGpuStatsLocked(GpuStatsInfo::Api::API_VK, true, mGpuStats.vkDriverLoadingTime);
}
});
trySendGpuStatsThread.detach();
@@ -205,32 +205,32 @@
mGpuStats.vulkanVersion = vulkanVersion;
}
-void GraphicsEnv::setDriverToLoad(GraphicsEnv::Driver driver) {
+void GraphicsEnv::setDriverToLoad(GpuStatsInfo::Driver driver) {
ATRACE_CALL();
std::lock_guard<std::mutex> lock(mStatsLock);
switch (driver) {
- case GraphicsEnv::Driver::GL:
- case GraphicsEnv::Driver::GL_UPDATED:
- case GraphicsEnv::Driver::ANGLE: {
- if (mGpuStats.glDriverToLoad == GraphicsEnv::Driver::NONE) {
+ case GpuStatsInfo::Driver::GL:
+ case GpuStatsInfo::Driver::GL_UPDATED:
+ case GpuStatsInfo::Driver::ANGLE: {
+ if (mGpuStats.glDriverToLoad == GpuStatsInfo::Driver::NONE) {
mGpuStats.glDriverToLoad = driver;
break;
}
- if (mGpuStats.glDriverFallback == GraphicsEnv::Driver::NONE) {
+ if (mGpuStats.glDriverFallback == GpuStatsInfo::Driver::NONE) {
mGpuStats.glDriverFallback = driver;
}
break;
}
- case Driver::VULKAN:
- case Driver::VULKAN_UPDATED: {
- if (mGpuStats.vkDriverToLoad == GraphicsEnv::Driver::NONE) {
+ case GpuStatsInfo::Driver::VULKAN:
+ case GpuStatsInfo::Driver::VULKAN_UPDATED: {
+ if (mGpuStats.vkDriverToLoad == GpuStatsInfo::Driver::NONE) {
mGpuStats.vkDriverToLoad = driver;
break;
}
- if (mGpuStats.vkDriverFallback == GraphicsEnv::Driver::NONE) {
+ if (mGpuStats.vkDriverFallback == GpuStatsInfo::Driver::NONE) {
mGpuStats.vkDriverFallback = driver;
}
break;
@@ -240,13 +240,13 @@
}
}
-void GraphicsEnv::setDriverLoaded(GraphicsEnv::Api api, bool isDriverLoaded,
+void GraphicsEnv::setDriverLoaded(GpuStatsInfo::Api api, bool isDriverLoaded,
int64_t driverLoadingTime) {
ATRACE_CALL();
std::lock_guard<std::mutex> lock(mStatsLock);
const bool doNotSend = mGpuStats.appPackageName.empty();
- if (api == GraphicsEnv::Api::API_GL) {
+ if (api == GpuStatsInfo::Api::API_GL) {
if (doNotSend) mGpuStats.glDriverToSend = true;
mGpuStats.glDriverLoadingTime = driverLoadingTime;
} else {
@@ -278,7 +278,7 @@
}
}
-void GraphicsEnv::sendGpuStatsLocked(GraphicsEnv::Api api, bool isDriverLoaded,
+void GraphicsEnv::sendGpuStatsLocked(GpuStatsInfo::Api api, bool isDriverLoaded,
int64_t driverLoadingTime) {
ATRACE_CALL();
@@ -299,16 +299,16 @@
mGpuStats.driverVersionCode, mGpuStats.driverBuildTime, mGpuStats.appPackageName.c_str(),
mGpuStats.vulkanVersion, static_cast<int32_t>(api), isDriverLoaded, driverLoadingTime);
- GraphicsEnv::Driver driver = GraphicsEnv::Driver::NONE;
+ GpuStatsInfo::Driver driver = GpuStatsInfo::Driver::NONE;
bool isIntendedDriverLoaded = false;
- if (api == GraphicsEnv::Api::API_GL) {
+ if (api == GpuStatsInfo::Api::API_GL) {
driver = mGpuStats.glDriverToLoad;
isIntendedDriverLoaded =
- isDriverLoaded && (mGpuStats.glDriverFallback == GraphicsEnv::Driver::NONE);
+ isDriverLoaded && (mGpuStats.glDriverFallback == GpuStatsInfo::Driver::NONE);
} else {
driver = mGpuStats.vkDriverToLoad;
isIntendedDriverLoaded =
- isDriverLoaded && (mGpuStats.vkDriverFallback == GraphicsEnv::Driver::NONE);
+ isDriverLoaded && (mGpuStats.vkDriverFallback == GpuStatsInfo::Driver::NONE);
}
const sp<IGpuService> gpuService = getGpuService();
diff --git a/libs/graphicsenv/IGpuService.cpp b/libs/graphicsenv/IGpuService.cpp
index 5f96249..30e5370 100644
--- a/libs/graphicsenv/IGpuService.cpp
+++ b/libs/graphicsenv/IGpuService.cpp
@@ -30,7 +30,7 @@
virtual void setGpuStats(const std::string& driverPackageName,
const std::string& driverVersionName, uint64_t driverVersionCode,
int64_t driverBuildTime, const std::string& appPackageName,
- const int32_t vulkanVersion, GraphicsEnv::Driver driver,
+ const int32_t vulkanVersion, GpuStatsInfo::Driver driver,
bool isDriverLoaded, int64_t driverLoadingTime) {
Parcel data, reply;
data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
@@ -143,7 +143,7 @@
if ((status = data.readInt64(&driverLoadingTime)) != OK) return status;
setGpuStats(driverPackageName, driverVersionName, driverVersionCode, driverBuildTime,
- appPackageName, vulkanVersion, static_cast<GraphicsEnv::Driver>(driver),
+ appPackageName, vulkanVersion, static_cast<GpuStatsInfo::Driver>(driver),
isDriverLoaded, driverLoadingTime);
return OK;
diff --git a/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h b/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h
index edcccfe..c2fd10a 100644
--- a/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h
+++ b/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h
@@ -72,4 +72,43 @@
bool cpuVulkanInUse = false;
};
+/*
+ * class for holding the gpu stats in GraphicsEnv before sending to GpuService.
+ */
+class GpuStatsInfo {
+public:
+ enum Api {
+ API_GL = 0,
+ API_VK = 1,
+ };
+
+ enum Driver {
+ NONE = 0,
+ GL = 1,
+ GL_UPDATED = 2,
+ VULKAN = 3,
+ VULKAN_UPDATED = 4,
+ ANGLE = 5,
+ };
+
+ GpuStatsInfo() = default;
+ GpuStatsInfo(const GpuStatsInfo&) = default;
+ virtual ~GpuStatsInfo() = default;
+
+ std::string driverPackageName = "";
+ std::string driverVersionName = "";
+ uint64_t driverVersionCode = 0;
+ int64_t driverBuildTime = 0;
+ std::string appPackageName = "";
+ int32_t vulkanVersion = 0;
+ Driver glDriverToLoad = Driver::NONE;
+ Driver glDriverFallback = Driver::NONE;
+ Driver vkDriverToLoad = Driver::NONE;
+ Driver vkDriverFallback = Driver::NONE;
+ bool glDriverToSend = false;
+ bool vkDriverToSend = false;
+ int64_t glDriverLoadingTime = 0;
+ int64_t vkDriverLoadingTime = 0;
+};
+
} // namespace android
diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
index f5d19db..aa14059 100644
--- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
+++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_UI_GRAPHICS_ENV_H
#define ANDROID_UI_GRAPHICS_ENV_H 1
+#include <graphicsenv/GpuStatsInfo.h>
+
#include <mutex>
#include <string>
#include <vector>
@@ -29,55 +31,6 @@
class GraphicsEnv {
public:
- enum Api {
- API_GL = 0,
- API_VK = 1,
- };
-
- enum Driver {
- NONE = 0,
- GL = 1,
- GL_UPDATED = 2,
- VULKAN = 3,
- VULKAN_UPDATED = 4,
- ANGLE = 5,
- };
-
-private:
- struct GpuStats {
- std::string driverPackageName;
- std::string driverVersionName;
- uint64_t driverVersionCode;
- int64_t driverBuildTime;
- std::string appPackageName;
- int32_t vulkanVersion;
- Driver glDriverToLoad;
- Driver glDriverFallback;
- Driver vkDriverToLoad;
- Driver vkDriverFallback;
- bool glDriverToSend;
- bool vkDriverToSend;
- int64_t glDriverLoadingTime;
- int64_t vkDriverLoadingTime;
-
- GpuStats()
- : driverPackageName(""),
- driverVersionName(""),
- driverVersionCode(0),
- driverBuildTime(0),
- appPackageName(""),
- vulkanVersion(0),
- glDriverToLoad(Driver::NONE),
- glDriverFallback(Driver::NONE),
- vkDriverToLoad(Driver::NONE),
- vkDriverFallback(Driver::NONE),
- glDriverToSend(false),
- vkDriverToSend(false),
- glDriverLoadingTime(0),
- vkDriverLoadingTime(0) {}
- };
-
-public:
static GraphicsEnv& getInstance();
int getCanLoadSystemLibraries();
@@ -97,9 +50,9 @@
uint64_t versionCode, int64_t driverBuildTime,
const std::string& appPackageName, const int32_t vulkanVersion);
void setCpuVulkanInUse();
- void setDriverToLoad(Driver driver);
- void setDriverLoaded(Api api, bool isDriverLoaded, int64_t driverLoadingTime);
- void sendGpuStatsLocked(Api api, bool isDriverLoaded, int64_t driverLoadingTime);
+ void setDriverToLoad(GpuStatsInfo::Driver driver);
+ void setDriverLoaded(GpuStatsInfo::Api api, bool isDriverLoaded, int64_t driverLoadingTime);
+ void sendGpuStatsLocked(GpuStatsInfo::Api api, bool isDriverLoaded, int64_t driverLoadingTime);
bool shouldUseAngle(std::string appName);
bool shouldUseAngle();
@@ -135,7 +88,7 @@
std::string mDriverPath;
std::string mSphalLibraries;
std::mutex mStatsLock;
- GpuStats mGpuStats;
+ GpuStatsInfo mGpuStats;
std::string mAnglePath;
std::string mAngleAppName;
std::string mAngleDeveloperOptIn;
diff --git a/libs/graphicsenv/include/graphicsenv/IGpuService.h b/libs/graphicsenv/include/graphicsenv/IGpuService.h
index 34f1c7e..a47bbaf 100644
--- a/libs/graphicsenv/include/graphicsenv/IGpuService.h
+++ b/libs/graphicsenv/include/graphicsenv/IGpuService.h
@@ -37,7 +37,7 @@
virtual void setGpuStats(const std::string& driverPackageName,
const std::string& driverVersionName, uint64_t driverVersionCode,
int64_t driverBuildTime, const std::string& appPackageName,
- const int32_t vulkanVersion, GraphicsEnv::Driver driver,
+ const int32_t vulkanVersion, GpuStatsInfo::Driver driver,
bool isDriverLoaded, int64_t driverLoadingTime) = 0;
// set CPU Vulkan in use signal from GraphicsEnvironment.
diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp
index 038a432..23e11a8 100644
--- a/opengl/libs/EGL/Loader.cpp
+++ b/opengl/libs/EGL/Loader.cpp
@@ -311,7 +311,7 @@
}
if (!hnd) {
- android::GraphicsEnv::getInstance().setDriverLoaded(android::GraphicsEnv::Api::API_GL,
+ android::GraphicsEnv::getInstance().setDriverLoaded(android::GpuStatsInfo::Api::API_GL,
false, systemTime() - openTime);
}
@@ -330,7 +330,7 @@
}
if (!cnx->libEgl || !cnx->libGles2 || !cnx->libGles1) {
- android::GraphicsEnv::getInstance().setDriverLoaded(android::GraphicsEnv::Api::API_GL,
+ android::GraphicsEnv::getInstance().setDriverLoaded(android::GpuStatsInfo::Api::API_GL,
false, systemTime() - openTime);
}
@@ -340,7 +340,7 @@
LOG_ALWAYS_FATAL_IF(!cnx->libGles2 || !cnx->libGles1,
"couldn't load system OpenGL ES wrapper libraries");
- android::GraphicsEnv::getInstance().setDriverLoaded(android::GraphicsEnv::Api::API_GL, true,
+ android::GraphicsEnv::getInstance().setDriverLoaded(android::GpuStatsInfo::Api::API_GL, true,
systemTime() - openTime);
return (void*)hnd;
@@ -637,7 +637,7 @@
return nullptr;
}
- android::GraphicsEnv::getInstance().setDriverToLoad(android::GraphicsEnv::Driver::ANGLE);
+ android::GraphicsEnv::getInstance().setDriverToLoad(android::GpuStatsInfo::Driver::ANGLE);
driver_t* hnd = nullptr;
// ANGLE doesn't ship with GLES library, and thus we skip GLES driver.
@@ -666,7 +666,7 @@
}
ALOGD("Load updated gl driver.");
- android::GraphicsEnv::getInstance().setDriverToLoad(android::GraphicsEnv::Driver::GL_UPDATED);
+ android::GraphicsEnv::getInstance().setDriverToLoad(android::GpuStatsInfo::Driver::GL_UPDATED);
driver_t* hnd = nullptr;
void* dso = load_updated_driver("GLES", ns);
if (dso) {
@@ -697,7 +697,7 @@
Loader::driver_t* Loader::attempt_to_load_system_driver(egl_connection_t* cnx, const char* suffix,
const bool exact) {
ATRACE_CALL();
- android::GraphicsEnv::getInstance().setDriverToLoad(android::GraphicsEnv::Driver::GL);
+ android::GraphicsEnv::getInstance().setDriverToLoad(android::GpuStatsInfo::Driver::GL);
driver_t* hnd = nullptr;
void* dso = load_system_driver("GLES", suffix, exact);
if (dso) {
diff --git a/services/gpuservice/GpuService.cpp b/services/gpuservice/GpuService.cpp
index 8accf9d..72757dd 100644
--- a/services/gpuservice/GpuService.cpp
+++ b/services/gpuservice/GpuService.cpp
@@ -51,7 +51,7 @@
void GpuService::setGpuStats(const std::string& driverPackageName,
const std::string& driverVersionName, uint64_t driverVersionCode,
int64_t driverBuildTime, const std::string& appPackageName,
- const int32_t vulkanVersion, GraphicsEnv::Driver driver,
+ const int32_t vulkanVersion, GpuStatsInfo::Driver driver,
bool isDriverLoaded, int64_t driverLoadingTime) {
ATRACE_CALL();
diff --git a/services/gpuservice/GpuService.h b/services/gpuservice/GpuService.h
index 8226901..3e0e1b5 100644
--- a/services/gpuservice/GpuService.h
+++ b/services/gpuservice/GpuService.h
@@ -46,7 +46,7 @@
void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName,
uint64_t driverVersionCode, int64_t driverBuildTime,
const std::string& appPackageName, const int32_t vulkanVersion,
- GraphicsEnv::Driver driver, bool isDriverLoaded,
+ GpuStatsInfo::Driver driver, bool isDriverLoaded,
int64_t driverLoadingTime) override;
status_t getGpuStatsGlobalInfo(std::vector<GpuStatsGlobalInfo>* outStats) const override;
status_t getGpuStatsAppInfo(std::vector<GpuStatsAppInfo>* outStats) const override;
diff --git a/services/gpuservice/gpustats/GpuStats.cpp b/services/gpuservice/gpustats/GpuStats.cpp
index 37c6abc..576c72c 100644
--- a/services/gpuservice/gpustats/GpuStats.cpp
+++ b/services/gpuservice/gpustats/GpuStats.cpp
@@ -27,20 +27,20 @@
namespace android {
-static void addLoadingCount(GraphicsEnv::Driver driver, bool isDriverLoaded,
+static void addLoadingCount(GpuStatsInfo::Driver driver, bool isDriverLoaded,
GpuStatsGlobalInfo* const outGlobalInfo) {
switch (driver) {
- case GraphicsEnv::Driver::GL:
- case GraphicsEnv::Driver::GL_UPDATED:
+ case GpuStatsInfo::Driver::GL:
+ case GpuStatsInfo::Driver::GL_UPDATED:
outGlobalInfo->glLoadingCount++;
if (!isDriverLoaded) outGlobalInfo->glLoadingFailureCount++;
break;
- case GraphicsEnv::Driver::VULKAN:
- case GraphicsEnv::Driver::VULKAN_UPDATED:
+ case GpuStatsInfo::Driver::VULKAN:
+ case GpuStatsInfo::Driver::VULKAN_UPDATED:
outGlobalInfo->vkLoadingCount++;
if (!isDriverLoaded) outGlobalInfo->vkLoadingFailureCount++;
break;
- case GraphicsEnv::Driver::ANGLE:
+ case GpuStatsInfo::Driver::ANGLE:
outGlobalInfo->angleLoadingCount++;
if (!isDriverLoaded) outGlobalInfo->angleLoadingFailureCount++;
break;
@@ -49,22 +49,22 @@
}
}
-static void addLoadingTime(GraphicsEnv::Driver driver, int64_t driverLoadingTime,
+static void addLoadingTime(GpuStatsInfo::Driver driver, int64_t driverLoadingTime,
GpuStatsAppInfo* const outAppInfo) {
switch (driver) {
- case GraphicsEnv::Driver::GL:
- case GraphicsEnv::Driver::GL_UPDATED:
+ case GpuStatsInfo::Driver::GL:
+ case GpuStatsInfo::Driver::GL_UPDATED:
if (outAppInfo->glDriverLoadingTime.size() < GpuStats::MAX_NUM_LOADING_TIMES) {
outAppInfo->glDriverLoadingTime.emplace_back(driverLoadingTime);
}
break;
- case GraphicsEnv::Driver::VULKAN:
- case GraphicsEnv::Driver::VULKAN_UPDATED:
+ case GpuStatsInfo::Driver::VULKAN:
+ case GpuStatsInfo::Driver::VULKAN_UPDATED:
if (outAppInfo->vkDriverLoadingTime.size() < GpuStats::MAX_NUM_LOADING_TIMES) {
outAppInfo->vkDriverLoadingTime.emplace_back(driverLoadingTime);
}
break;
- case GraphicsEnv::Driver::ANGLE:
+ case GpuStatsInfo::Driver::ANGLE:
if (outAppInfo->angleDriverLoadingTime.size() < GpuStats::MAX_NUM_LOADING_TIMES) {
outAppInfo->angleDriverLoadingTime.emplace_back(driverLoadingTime);
}
@@ -77,7 +77,7 @@
void GpuStats::insert(const std::string& driverPackageName, const std::string& driverVersionName,
uint64_t driverVersionCode, int64_t driverBuildTime,
const std::string& appPackageName, const int32_t vulkanVersion,
- GraphicsEnv::Driver driver, bool isDriverLoaded, int64_t driverLoadingTime) {
+ GpuStatsInfo::Driver driver, bool isDriverLoaded, int64_t driverLoadingTime) {
ATRACE_CALL();
std::lock_guard<std::mutex> lock(mLock);
diff --git a/services/gpuservice/gpustats/GpuStats.h b/services/gpuservice/gpustats/GpuStats.h
index b293f59..a79b2ba 100644
--- a/services/gpuservice/gpustats/GpuStats.h
+++ b/services/gpuservice/gpustats/GpuStats.h
@@ -36,7 +36,7 @@
void insert(const std::string& driverPackageName, const std::string& driverVersionName,
uint64_t driverVersionCode, int64_t driverBuildTime,
const std::string& appPackageName, const int32_t vulkanVersion,
- GraphicsEnv::Driver driver, bool isDriverLoaded, int64_t driverLoadingTime);
+ GpuStatsInfo::Driver driver, bool isDriverLoaded, int64_t driverLoadingTime);
// Set CPU Vulkan in use signal into app stats.
void setCpuVulkanInUse(const std::string& appPackageName, const uint64_t driverVersionCode);
// dumpsys interface
diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp
index d33e552..680f94f 100644
--- a/vulkan/libvulkan/driver.cpp
+++ b/vulkan/libvulkan/driver.cpp
@@ -211,7 +211,7 @@
if (!ns)
return -ENOENT;
android::GraphicsEnv::getInstance().setDriverToLoad(
- android::GraphicsEnv::Driver::VULKAN);
+ android::GpuStatsInfo::Driver::VULKAN);
return LoadDriver(ns, module);
}
@@ -222,7 +222,7 @@
if (!ns)
return -ENOENT;
android::GraphicsEnv::getInstance().setDriverToLoad(
- android::GraphicsEnv::Driver::VULKAN_UPDATED);
+ android::GpuStatsInfo::Driver::VULKAN_UPDATED);
return LoadDriver(ns, module);
}
@@ -257,7 +257,7 @@
}
if (result != 0) {
android::GraphicsEnv::getInstance().setDriverLoaded(
- android::GraphicsEnv::Api::API_VK, false, systemTime() - openTime);
+ android::GpuStatsInfo::Api::API_VK, false, systemTime() - openTime);
ALOGV("unable to load Vulkan HAL, using stub HAL (result=%d)", result);
return true;
}
@@ -271,7 +271,7 @@
ATRACE_END();
if (result != 0) {
android::GraphicsEnv::getInstance().setDriverLoaded(
- android::GraphicsEnv::Api::API_VK, false, systemTime() - openTime);
+ android::GpuStatsInfo::Api::API_VK, false, systemTime() - openTime);
// Any device with a Vulkan HAL should be able to open the device.
ALOGE("failed to open Vulkan HAL device: %s (%d)", strerror(-result),
result);
@@ -283,7 +283,7 @@
hal_.InitDebugReportIndex();
android::GraphicsEnv::getInstance().setDriverLoaded(
- android::GraphicsEnv::Api::API_VK, true, systemTime() - openTime);
+ android::GpuStatsInfo::Api::API_VK, true, systemTime() - openTime);
return true;
}