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
diff --git a/services/gpuservice/gpustats/GpuStats.cpp b/services/gpuservice/gpustats/GpuStats.cpp
index 43c9492..c4256df 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 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 @@
           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::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");
     }
 }