summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yiwei Zhang <zzyiwei@google.com> 2019-02-27 21:05:06 -0800
committer Yiwei Zhang <zzyiwei@google.com> 2019-02-28 11:18:53 -0800
commitf40fb10f1dfbbc17edbd15ee102d772dd1df6adf (patch)
treee8aaa8b96c9e3d4933c433538e6d9d08defbe0a4
parent70435e9b3a53fee8610e6ba2d5c99c05faac3743 (diff)
Game Driver Metrics: make gpu stats info parcelable
This change also rename the GpuStats*Atom to GpuStats*Info because we'd like to make GpuStats generic to all the authorized recipients, but atom is too specific to statsd. Bug: 126560138 Test: adb shell dumpsys gpu --gpustats Change-Id: Ie071277ae849a32607979d07aca7682febaf4368
-rw-r--r--libs/graphicsenv/Android.bp1
-rw-r--r--libs/graphicsenv/GpuStatsInfo.cpp101
-rw-r--r--libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h (renamed from libs/graphicsenv/include/graphicsenv/GpuStatsAtoms.h)30
-rw-r--r--services/gpuservice/gpustats/GpuStats.cpp76
-rw-r--r--services/gpuservice/gpustats/GpuStats.h6
5 files changed, 158 insertions, 56 deletions
diff --git a/libs/graphicsenv/Android.bp b/libs/graphicsenv/Android.bp
index d940752396..0571dccfdc 100644
--- a/libs/graphicsenv/Android.bp
+++ b/libs/graphicsenv/Android.bp
@@ -16,6 +16,7 @@ cc_library_shared {
name: "libgraphicsenv",
srcs: [
+ "GpuStatsInfo.cpp",
"GraphicsEnv.cpp",
"IGpuService.cpp"
],
diff --git a/libs/graphicsenv/GpuStatsInfo.cpp b/libs/graphicsenv/GpuStatsInfo.cpp
new file mode 100644
index 0000000000..0fa0d9e32c
--- /dev/null
+++ b/libs/graphicsenv/GpuStatsInfo.cpp
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <inttypes.h>
+
+#include <android-base/stringprintf.h>
+#include <binder/Parcel.h>
+#include <graphicsenv/GpuStatsInfo.h>
+
+namespace android {
+
+using base::StringAppendF;
+
+status_t GpuStatsGlobalInfo::writeToParcel(Parcel* parcel) const {
+ status_t status;
+ if ((status = parcel->writeUtf8AsUtf16(driverPackageName)) != OK) return status;
+ if ((status = parcel->writeUtf8AsUtf16(driverVersionName)) != OK) return status;
+ if ((status = parcel->writeUint64(driverVersionCode)) != OK) return status;
+ if ((status = parcel->writeInt64(driverBuildTime)) != OK) return status;
+ if ((status = parcel->writeInt32(glLoadingCount)) != OK) return status;
+ if ((status = parcel->writeInt32(glLoadingFailureCount)) != OK) return status;
+ if ((status = parcel->writeInt32(vkLoadingCount)) != OK) return status;
+ if ((status = parcel->writeInt32(vkLoadingFailureCount)) != OK) return status;
+ return OK;
+}
+
+status_t GpuStatsGlobalInfo::readFromParcel(const Parcel* parcel) {
+ status_t status;
+ if ((status = parcel->readUtf8FromUtf16(&driverPackageName)) != OK) return status;
+ if ((status = parcel->readUtf8FromUtf16(&driverVersionName)) != OK) return status;
+ if ((status = parcel->readUint64(&driverVersionCode)) != OK) return status;
+ if ((status = parcel->readInt64(&driverBuildTime)) != OK) return status;
+ if ((status = parcel->readInt32(&glLoadingCount)) != OK) return status;
+ if ((status = parcel->readInt32(&glLoadingFailureCount)) != OK) return status;
+ if ((status = parcel->readInt32(&vkLoadingCount)) != OK) return status;
+ if ((status = parcel->readInt32(&vkLoadingFailureCount)) != OK) return status;
+ return OK;
+}
+
+std::string GpuStatsGlobalInfo::toString() const {
+ std::string result;
+ StringAppendF(&result, "driverPackageName = %s\n", driverPackageName.c_str());
+ StringAppendF(&result, "driverVersionName = %s\n", driverVersionName.c_str());
+ StringAppendF(&result, "driverVersionCode = %" PRIu64 "\n", driverVersionCode);
+ StringAppendF(&result, "driverBuildTime = %" PRId64 "\n", driverBuildTime);
+ StringAppendF(&result, "glLoadingCount = %d\n", glLoadingCount);
+ StringAppendF(&result, "glLoadingFailureCount = %d\n", glLoadingFailureCount);
+ StringAppendF(&result, "vkLoadingCount = %d\n", vkLoadingCount);
+ StringAppendF(&result, "vkLoadingFailureCount = %d\n", vkLoadingFailureCount);
+ return result;
+}
+
+status_t GpuStatsAppInfo::writeToParcel(Parcel* parcel) const {
+ status_t status;
+ if ((status = parcel->writeUtf8AsUtf16(appPackageName)) != OK) return status;
+ if ((status = parcel->writeUint64(driverVersionCode)) != OK) return status;
+ if ((status = parcel->writeInt64Vector(glDriverLoadingTime)) != OK) return status;
+ if ((status = parcel->writeInt64Vector(vkDriverLoadingTime)) != OK) return status;
+ return OK;
+}
+
+status_t GpuStatsAppInfo::readFromParcel(const Parcel* parcel) {
+ status_t status;
+ if ((status = parcel->readUtf8FromUtf16(&appPackageName)) != OK) return status;
+ if ((status = parcel->readUint64(&driverVersionCode)) != OK) return status;
+ if ((status = parcel->readInt64Vector(&glDriverLoadingTime)) != OK) return status;
+ if ((status = parcel->readInt64Vector(&vkDriverLoadingTime)) != OK) return status;
+ return OK;
+}
+
+std::string GpuStatsAppInfo::toString() const {
+ std::string result;
+ StringAppendF(&result, "appPackageName = %s\n", appPackageName.c_str());
+ StringAppendF(&result, "driverVersionCode = %" PRIu64 "\n", driverVersionCode);
+ result.append("glDriverLoadingTime:");
+ for (int32_t loadingTime : glDriverLoadingTime) {
+ StringAppendF(&result, " %d", loadingTime);
+ }
+ result.append("\n");
+ result.append("vkDriverLoadingTime:");
+ for (int32_t loadingTime : vkDriverLoadingTime) {
+ StringAppendF(&result, " %d", loadingTime);
+ }
+ result.append("\n");
+ return result;
+}
+
+} // namespace android
diff --git a/libs/graphicsenv/include/graphicsenv/GpuStatsAtoms.h b/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h
index f8b0ad72a1..a92ca70493 100644
--- a/libs/graphicsenv/include/graphicsenv/GpuStatsAtoms.h
+++ b/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h
@@ -19,9 +19,23 @@
#include <string>
#include <vector>
+#include <binder/Parcelable.h>
+
namespace android {
-struct GpuStatsGlobalAtom {
+/*
+ * class for transporting gpu global stats from GpuService to authorized
+ * recipents. This class is intended to be a data container.
+ */
+class GpuStatsGlobalInfo : public Parcelable {
+public:
+ GpuStatsGlobalInfo() = default;
+ GpuStatsGlobalInfo(const GpuStatsGlobalInfo&) = default;
+ virtual ~GpuStatsGlobalInfo() = default;
+ virtual status_t writeToParcel(Parcel* parcel) const;
+ virtual status_t readFromParcel(const Parcel* parcel);
+ std::string toString() const;
+
std::string driverPackageName = "";
std::string driverVersionName = "";
uint64_t driverVersionCode = 0;
@@ -32,7 +46,19 @@ struct GpuStatsGlobalAtom {
int32_t vkLoadingFailureCount = 0;
};
-struct GpuStatsAppAtom {
+/*
+ * class for transporting gpu app stats from GpuService to authorized recipents.
+ * This class is intended to be a data container.
+ */
+class GpuStatsAppInfo : public Parcelable {
+public:
+ GpuStatsAppInfo() = default;
+ GpuStatsAppInfo(const GpuStatsAppInfo&) = default;
+ virtual ~GpuStatsAppInfo() = default;
+ virtual status_t writeToParcel(Parcel* parcel) const;
+ virtual status_t readFromParcel(const Parcel* parcel);
+ std::string toString() const;
+
std::string appPackageName = "";
uint64_t driverVersionCode = 0;
std::vector<int64_t> glDriverLoadingTime = {};
diff --git a/services/gpuservice/gpustats/GpuStats.cpp b/services/gpuservice/gpustats/GpuStats.cpp
index 43c9492765..c4256df4c4 100644
--- a/services/gpuservice/gpustats/GpuStats.cpp
+++ b/services/gpuservice/gpustats/GpuStats.cpp
@@ -19,28 +19,25 @@
#include "GpuStats.h"
-#include <android-base/stringprintf.h>
+#include <unordered_set>
+
#include <log/log.h>
#include <utils/Trace.h>
-#include <unordered_set>
-
namespace android {
-using base::StringAppendF;
-
static bool addLoadingCount(GraphicsEnv::Driver driver, bool isDriverLoaded,
- GpuStatsGlobalAtom* const outGlobalAtom) {
+ GpuStatsGlobalInfo* const outGlobalInfo) {
switch (driver) {
case GraphicsEnv::Driver::GL:
case GraphicsEnv::Driver::GL_UPDATED:
- outGlobalAtom->glLoadingCount++;
- if (!isDriverLoaded) outGlobalAtom->glLoadingFailureCount++;
+ outGlobalInfo->glLoadingCount++;
+ if (!isDriverLoaded) outGlobalInfo->glLoadingFailureCount++;
break;
case GraphicsEnv::Driver::VULKAN:
case GraphicsEnv::Driver::VULKAN_UPDATED:
- outGlobalAtom->vkLoadingCount++;
- if (!isDriverLoaded) outGlobalAtom->vkLoadingFailureCount++;
+ outGlobalInfo->vkLoadingCount++;
+ if (!isDriverLoaded) outGlobalInfo->vkLoadingFailureCount++;
break;
default:
// Currently we don't support GraphicsEnv::Driver::ANGLE because the
@@ -52,15 +49,15 @@ static bool addLoadingCount(GraphicsEnv::Driver driver, bool isDriverLoaded,
}
static void addLoadingTime(GraphicsEnv::Driver driver, int64_t driverLoadingTime,
- GpuStatsAppAtom* const outAppAtom) {
+ GpuStatsAppInfo* const outAppInfo) {
switch (driver) {
case GraphicsEnv::Driver::GL:
case GraphicsEnv::Driver::GL_UPDATED:
- outAppAtom->glDriverLoadingTime.emplace_back(driverLoadingTime);
+ outAppInfo->glDriverLoadingTime.emplace_back(driverLoadingTime);
break;
case GraphicsEnv::Driver::VULKAN:
case GraphicsEnv::Driver::VULKAN_UPDATED:
- outAppAtom->vkDriverLoadingTime.emplace_back(driverLoadingTime);
+ outAppInfo->vkDriverLoadingTime.emplace_back(driverLoadingTime);
break;
default:
break;
@@ -87,31 +84,31 @@ void GpuStats::insert(const std::string& driverPackageName, const std::string& d
appPackageName.c_str(), static_cast<int32_t>(driver), isDriverLoaded, driverLoadingTime);
if (!mGlobalStats.count(driverVersionCode)) {
- GpuStatsGlobalAtom globalAtom;
- if (!addLoadingCount(driver, isDriverLoaded, &globalAtom)) {
+ GpuStatsGlobalInfo globalInfo;
+ if (!addLoadingCount(driver, isDriverLoaded, &globalInfo)) {
return;
}
- globalAtom.driverPackageName = driverPackageName;
- globalAtom.driverVersionName = driverVersionName;
- globalAtom.driverVersionCode = driverVersionCode;
- globalAtom.driverBuildTime = driverBuildTime;
- mGlobalStats.insert({driverVersionCode, globalAtom});
+ globalInfo.driverPackageName = driverPackageName;
+ globalInfo.driverVersionName = driverVersionName;
+ globalInfo.driverVersionCode = driverVersionCode;
+ globalInfo.driverBuildTime = driverBuildTime;
+ mGlobalStats.insert({driverVersionCode, globalInfo});
} else if (!addLoadingCount(driver, isDriverLoaded, &mGlobalStats[driverVersionCode])) {
return;
}
if (mAppStats.size() >= MAX_NUM_APP_RECORDS) {
- ALOGV("GpuStatsAppAtom has reached maximum size. Ignore new stats.");
+ ALOGV("GpuStatsAppInfo has reached maximum size. Ignore new stats.");
return;
}
const std::string appStatsKey = appPackageName + std::to_string(driverVersionCode);
if (!mAppStats.count(appStatsKey)) {
- GpuStatsAppAtom appAtom;
- addLoadingTime(driver, driverLoadingTime, &appAtom);
- appAtom.appPackageName = appPackageName;
- appAtom.driverVersionCode = driverVersionCode;
- mAppStats.insert({appStatsKey, appAtom});
+ GpuStatsAppInfo appInfo;
+ addLoadingTime(driver, driverLoadingTime, &appInfo);
+ appInfo.appPackageName = appPackageName;
+ appInfo.driverVersionCode = driverVersionCode;
+ mAppStats.insert({appStatsKey, appInfo});
return;
}
@@ -174,39 +171,16 @@ void GpuStats::dump(const Vector<String16>& args, std::string* result) {
}
void GpuStats::dumpGlobalLocked(std::string* result) {
- result->append("GpuStats global:\n");
-
for (const auto& ele : mGlobalStats) {
- StringAppendF(result, " driverPackageName = %s\n", ele.second.driverPackageName.c_str());
- StringAppendF(result, " driverVersionName = %s\n", ele.second.driverVersionName.c_str());
- StringAppendF(result, " driverVersionCode = %" PRIu64 "\n", ele.second.driverVersionCode);
- StringAppendF(result, " driverBuildTime = %" PRId64 "\n", ele.second.driverBuildTime);
- StringAppendF(result, " glLoadingCount = %d\n", ele.second.glLoadingCount);
- StringAppendF(result, " glLoadingFailureCount = %d\n", ele.second.glLoadingFailureCount);
- StringAppendF(result, " vkLoadingCount = %d\n", ele.second.vkLoadingCount);
- StringAppendF(result, " vkLoadingFailureCount = %d\n", ele.second.vkLoadingFailureCount);
+ result->append(ele.second.toString());
result->append("\n");
}
}
void GpuStats::dumpAppLocked(std::string* result) {
- result->append("GpuStats app:\n");
-
for (const auto& ele : mAppStats) {
- StringAppendF(result, " appPackageName = %s\n", ele.second.appPackageName.c_str());
- StringAppendF(result, " driverVersionCode = %" PRIu64 "\n", ele.second.driverVersionCode);
-
- result->append(" glDriverLoadingTime:");
- for (int32_t loadingTime : ele.second.glDriverLoadingTime) {
- StringAppendF(result, " %d", loadingTime);
- }
+ result->append(ele.second.toString());
result->append("\n");
-
- result->append(" vkDriverLoadingTime:");
- for (int32_t loadingTime : ele.second.vkDriverLoadingTime) {
- StringAppendF(result, " %d", loadingTime);
- }
- result->append("\n\n");
}
}
diff --git a/services/gpuservice/gpustats/GpuStats.h b/services/gpuservice/gpustats/GpuStats.h
index 8837c39e8e..da7fd3357d 100644
--- a/services/gpuservice/gpustats/GpuStats.h
+++ b/services/gpuservice/gpustats/GpuStats.h
@@ -20,7 +20,7 @@
#include <unordered_map>
#include <vector>
-#include <graphicsenv/GpuStatsAtoms.h>
+#include <graphicsenv/GpuStatsInfo.h>
#include <graphicsenv/GraphicsEnv.h>
#include <utils/String16.h>
#include <utils/Vector.h>
@@ -52,9 +52,9 @@ private:
// GpuStats access should be guarded by mLock.
std::mutex mLock;
// Key is driver version code.
- std::unordered_map<uint64_t, GpuStatsGlobalAtom> mGlobalStats;
+ std::unordered_map<uint64_t, GpuStatsGlobalInfo> mGlobalStats;
// Key is <app package name>+<driver version code>.
- std::unordered_map<std::string, GpuStatsAppAtom> mAppStats;
+ std::unordered_map<std::string, GpuStatsAppInfo> mAppStats;
};
} // namespace android