diff options
| author | 2020-02-06 07:57:29 +0000 | |
|---|---|---|
| committer | 2020-02-06 07:57:29 +0000 | |
| commit | 181231faf3ae80fee6a618a55efca6c19c9e309d (patch) | |
| tree | 3384b58d25308da32610cda5a34ed74e32e1eddc | |
| parent | 82b5b24a948723c4d4b15e1416233c5e214fbaeb (diff) | |
| parent | 29f8593e13f6d1af5223adb4ff3ad7f0eb39b4a0 (diff) | |
Merge changes from topic "new-puller-migration"
* changes:
GpuStats: migrate to new statsd native puller api (part 3)
GpuStats: migrate to new statsd native puller api (part 2)
GpuStats: migrate to new statsd native puller api (part 1)
| -rw-r--r-- | libs/graphicsenv/IGpuService.cpp | 70 | ||||
| -rw-r--r-- | libs/graphicsenv/include/graphicsenv/IGpuService.h | 13 | ||||
| -rw-r--r-- | services/gpuservice/GpuService.cpp | 10 | ||||
| -rw-r--r-- | services/gpuservice/GpuService.h | 2 | ||||
| -rw-r--r-- | services/gpuservice/gpustats/Android.bp | 8 | ||||
| -rw-r--r-- | services/gpuservice/gpustats/GpuStats.cpp | 123 | ||||
| -rw-r--r-- | services/gpuservice/gpustats/include/gpustats/GpuStats.h | 20 | ||||
| -rw-r--r-- | services/gpuservice/tests/unittests/Android.bp | 2 | ||||
| -rw-r--r-- | services/gpuservice/tests/unittests/GpuStatsTest.cpp | 54 | ||||
| -rw-r--r-- | services/gpuservice/tests/unittests/TestableGpuStats.h | 36 |
10 files changed, 225 insertions, 113 deletions
diff --git a/libs/graphicsenv/IGpuService.cpp b/libs/graphicsenv/IGpuService.cpp index 9f5b0ff46f..de3503bcf0 100644 --- a/libs/graphicsenv/IGpuService.cpp +++ b/libs/graphicsenv/IGpuService.cpp @@ -48,50 +48,6 @@ public: remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply, IBinder::FLAG_ONEWAY); } - virtual status_t getGpuStatsGlobalInfo(std::vector<GpuStatsGlobalInfo>* outStats) const { - if (!outStats) return UNEXPECTED_NULL; - - Parcel data, reply; - status_t status; - - if ((status = data.writeInterfaceToken(IGpuService::getInterfaceDescriptor())) != OK) - return status; - - if ((status = remote()->transact(BnGpuService::GET_GPU_STATS_GLOBAL_INFO, data, &reply)) != - OK) - return status; - - int32_t result = 0; - if ((status = reply.readInt32(&result)) != OK) return status; - if (result != OK) return result; - - outStats->clear(); - return reply.readParcelableVector(outStats); - } - - virtual status_t getGpuStatsAppInfo(std::vector<GpuStatsAppInfo>* outStats) const { - if (!outStats) return UNEXPECTED_NULL; - - Parcel data, reply; - status_t status; - - if ((status = data.writeInterfaceToken(IGpuService::getInterfaceDescriptor())) != OK) { - return status; - } - - if ((status = remote()->transact(BnGpuService::GET_GPU_STATS_APP_INFO, data, &reply)) != - OK) { - return status; - } - - int32_t result = 0; - if ((status = reply.readInt32(&result)) != OK) return status; - if (result != OK) return result; - - outStats->clear(); - return reply.readParcelableVector(outStats); - } - virtual void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, const GpuStatsInfo::Stats stats, const uint64_t value) { Parcel data, reply; @@ -150,32 +106,6 @@ status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* rep return OK; } - case GET_GPU_STATS_GLOBAL_INFO: { - CHECK_INTERFACE(IGpuService, data, reply); - - std::vector<GpuStatsGlobalInfo> stats; - const status_t result = getGpuStatsGlobalInfo(&stats); - - if ((status = reply->writeInt32(result)) != OK) return status; - if (result != OK) return result; - - if ((status = reply->writeParcelableVector(stats)) != OK) return status; - - return OK; - } - case GET_GPU_STATS_APP_INFO: { - CHECK_INTERFACE(IGpuService, data, reply); - - std::vector<GpuStatsAppInfo> stats; - const status_t result = getGpuStatsAppInfo(&stats); - - if ((status = reply->writeInt32(result)) != OK) return status; - if (result != OK) return result; - - if ((status = reply->writeParcelableVector(stats)) != OK) return status; - - return OK; - } case SET_TARGET_STATS: { CHECK_INTERFACE(IGpuService, data, reply); diff --git a/libs/graphicsenv/include/graphicsenv/IGpuService.h b/libs/graphicsenv/include/graphicsenv/IGpuService.h index f523d585be..c7c6d1e886 100644 --- a/libs/graphicsenv/include/graphicsenv/IGpuService.h +++ b/libs/graphicsenv/include/graphicsenv/IGpuService.h @@ -16,12 +16,11 @@ #pragma once -#include <vector> - #include <binder/IInterface.h> #include <cutils/compiler.h> #include <graphicsenv/GpuStatsInfo.h> -#include <graphicsenv/GraphicsEnv.h> + +#include <vector> namespace android { @@ -43,20 +42,12 @@ public: // set target stats. virtual void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, const GpuStatsInfo::Stats stats, const uint64_t value = 0) = 0; - - // get GPU global stats from GpuStats module. - virtual status_t getGpuStatsGlobalInfo(std::vector<GpuStatsGlobalInfo>* outStats) const = 0; - - // get GPU app stats from GpuStats module. - virtual status_t getGpuStatsAppInfo(std::vector<GpuStatsAppInfo>* outStats) const = 0; }; class BnGpuService : public BnInterface<IGpuService> { public: enum IGpuServiceTag { SET_GPU_STATS = IBinder::FIRST_CALL_TRANSACTION, - GET_GPU_STATS_GLOBAL_INFO, - GET_GPU_STATS_APP_INFO, SET_TARGET_STATS, // Always append new enum to the end. }; diff --git a/services/gpuservice/GpuService.cpp b/services/gpuservice/GpuService.cpp index 91a76f16eb..7bb0e4a751 100644 --- a/services/gpuservice/GpuService.cpp +++ b/services/gpuservice/GpuService.cpp @@ -57,16 +57,6 @@ void GpuService::setGpuStats(const std::string& driverPackageName, isDriverLoaded, driverLoadingTime); } -status_t GpuService::getGpuStatsGlobalInfo(std::vector<GpuStatsGlobalInfo>* outStats) const { - mGpuStats->pullGlobalStats(outStats); - return OK; -} - -status_t GpuService::getGpuStatsAppInfo(std::vector<GpuStatsAppInfo>* outStats) const { - mGpuStats->pullAppStats(outStats); - return OK; -} - void GpuService::setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, const GpuStatsInfo::Stats stats, const uint64_t value) { mGpuStats->insertTargetStats(appPackageName, driverVersionCode, stats, value); diff --git a/services/gpuservice/GpuService.h b/services/gpuservice/GpuService.h index 525fb4fada..b3e34d559e 100644 --- a/services/gpuservice/GpuService.h +++ b/services/gpuservice/GpuService.h @@ -48,8 +48,6 @@ private: const std::string& appPackageName, const int32_t vulkanVersion, 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; void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, const GpuStatsInfo::Stats stats, const uint64_t value) override; diff --git a/services/gpuservice/gpustats/Android.bp b/services/gpuservice/gpustats/Android.bp index 49a98cc450..f52602ab78 100644 --- a/services/gpuservice/gpustats/Android.bp +++ b/services/gpuservice/gpustats/Android.bp @@ -7,9 +7,17 @@ cc_library_shared { "libcutils", "libgraphicsenv", "liblog", + "libprotoutil", + "libstatslog", + "libstatspull", + "libstatssocket", "libutils", ], export_include_dirs: ["include"], + export_shared_lib_headers: [ + "libstatspull", + "libstatssocket", + ], cppflags: [ "-Wall", "-Werror", diff --git a/services/gpuservice/gpustats/GpuStats.cpp b/services/gpuservice/gpustats/GpuStats.cpp index 71e6b973d4..d0945326b3 100644 --- a/services/gpuservice/gpustats/GpuStats.cpp +++ b/services/gpuservice/gpustats/GpuStats.cpp @@ -17,16 +17,31 @@ #define LOG_TAG "GpuStats" #define ATRACE_TAG ATRACE_TAG_GRAPHICS -#include <gpustats/GpuStats.h> +#include "gpustats/GpuStats.h" +#include <android/util/ProtoOutputStream.h> #include <cutils/properties.h> #include <log/log.h> +#include <stats_event.h> +#include <statslog.h> #include <utils/Trace.h> #include <unordered_set> namespace android { +GpuStats::GpuStats() { + AStatsManager_registerPullAtomCallback(android::util::GPU_STATS_GLOBAL_INFO, + GpuStats::pullAtomCallback, nullptr, this); + AStatsManager_registerPullAtomCallback(android::util::GPU_STATS_APP_INFO, + GpuStats::pullAtomCallback, nullptr, this); +} + +GpuStats::~GpuStats() { + AStatsManager_unregisterPullAtomCallback(android::util::GPU_STATS_GLOBAL_INFO); + AStatsManager_unregisterPullAtomCallback(android::util::GPU_STATS_APP_INFO); +} + static void addLoadingCount(GpuStatsInfo::Driver driver, bool isDriverLoaded, GpuStatsGlobalInfo* const outGlobalInfo) { switch (driver) { @@ -233,34 +248,114 @@ void GpuStats::dumpAppLocked(std::string* result) { } } -void GpuStats::pullGlobalStats(std::vector<GpuStatsGlobalInfo>* outStats) { +static std::string protoOutputStreamToByteString(android::util::ProtoOutputStream& proto) { + if (!proto.size()) return ""; + + std::string byteString; + sp<android::util::ProtoReader> reader = proto.data(); + while (reader->readBuffer() != nullptr) { + const size_t toRead = reader->currentToRead(); + byteString.append((char*)reader->readBuffer(), toRead); + reader->move(toRead); + } + + if (byteString.size() != proto.size()) return ""; + + return byteString; +} + +static std::string int64VectorToProtoByteString(const std::vector<int64_t>& value) { + if (value.empty()) return ""; + + android::util::ProtoOutputStream proto; + for (const auto& ele : value) { + proto.write(android::util::FIELD_TYPE_INT64 | android::util::FIELD_COUNT_REPEATED | + 1 /* field id */, + (long long)ele); + } + + return protoOutputStreamToByteString(proto); +} + +AStatsManager_PullAtomCallbackReturn GpuStats::pullAppInfoAtom(AStatsEventList* data) { ATRACE_CALL(); std::lock_guard<std::mutex> lock(mLock); - outStats->clear(); - outStats->reserve(mGlobalStats.size()); - interceptSystemDriverStatsLocked(); + if (data) { + for (const auto& ele : mAppStats) { + AStatsEvent* event = AStatsEventList_addStatsEvent(data); + AStatsEvent_setAtomId(event, android::util::GPU_STATS_APP_INFO); + AStatsEvent_writeString(event, ele.second.appPackageName.c_str()); + AStatsEvent_writeInt64(event, ele.second.driverVersionCode); - for (const auto& ele : mGlobalStats) { - outStats->emplace_back(ele.second); + std::string bytes = int64VectorToProtoByteString(ele.second.glDriverLoadingTime); + AStatsEvent_writeByteArray(event, (const uint8_t*)bytes.c_str(), bytes.length()); + + bytes = int64VectorToProtoByteString(ele.second.vkDriverLoadingTime); + AStatsEvent_writeByteArray(event, (const uint8_t*)bytes.c_str(), bytes.length()); + + bytes = int64VectorToProtoByteString(ele.second.angleDriverLoadingTime); + AStatsEvent_writeByteArray(event, (const uint8_t*)bytes.c_str(), bytes.length()); + + AStatsEvent_writeBool(event, ele.second.cpuVulkanInUse); + AStatsEvent_writeBool(event, ele.second.falsePrerotation); + AStatsEvent_writeBool(event, ele.second.gles1InUse); + AStatsEvent_build(event); + } } - mGlobalStats.clear(); + mAppStats.clear(); + + return AStatsManager_PULL_SUCCESS; } -void GpuStats::pullAppStats(std::vector<GpuStatsAppInfo>* outStats) { +AStatsManager_PullAtomCallbackReturn GpuStats::pullGlobalInfoAtom(AStatsEventList* data) { ATRACE_CALL(); std::lock_guard<std::mutex> lock(mLock); - outStats->clear(); - outStats->reserve(mAppStats.size()); + // flush cpuVulkanVersion and glesVersion to builtin driver stats + interceptSystemDriverStatsLocked(); - for (const auto& ele : mAppStats) { - outStats->emplace_back(ele.second); + if (data) { + for (const auto& ele : mGlobalStats) { + AStatsEvent* event = AStatsEventList_addStatsEvent(data); + AStatsEvent_setAtomId(event, android::util::GPU_STATS_GLOBAL_INFO); + AStatsEvent_writeString(event, ele.second.driverPackageName.c_str()); + AStatsEvent_writeString(event, ele.second.driverVersionName.c_str()); + AStatsEvent_writeInt64(event, ele.second.driverVersionCode); + AStatsEvent_writeInt64(event, ele.second.driverBuildTime); + AStatsEvent_writeInt64(event, ele.second.glLoadingCount); + AStatsEvent_writeInt64(event, ele.second.glLoadingFailureCount); + AStatsEvent_writeInt64(event, ele.second.vkLoadingCount); + AStatsEvent_writeInt64(event, ele.second.vkLoadingFailureCount); + AStatsEvent_writeInt32(event, ele.second.vulkanVersion); + AStatsEvent_writeInt32(event, ele.second.cpuVulkanVersion); + AStatsEvent_writeInt32(event, ele.second.glesVersion); + AStatsEvent_writeInt64(event, ele.second.angleLoadingCount); + AStatsEvent_writeInt64(event, ele.second.angleLoadingFailureCount); + AStatsEvent_build(event); + } } - mAppStats.clear(); + mGlobalStats.clear(); + + return AStatsManager_PULL_SUCCESS; +} + +AStatsManager_PullAtomCallbackReturn GpuStats::pullAtomCallback(int32_t atomTag, + AStatsEventList* data, + void* cookie) { + ATRACE_CALL(); + + GpuStats* pGpuStats = reinterpret_cast<GpuStats*>(cookie); + if (atomTag == android::util::GPU_STATS_GLOBAL_INFO) { + return pGpuStats->pullGlobalInfoAtom(data); + } else if (atomTag == android::util::GPU_STATS_APP_INFO) { + return pGpuStats->pullAppInfoAtom(data); + } + + return AStatsManager_PULL_SKIP; } } // namespace android diff --git a/services/gpuservice/gpustats/include/gpustats/GpuStats.h b/services/gpuservice/gpustats/include/gpustats/GpuStats.h index bcb9e0d7dd..8ca4e4ed71 100644 --- a/services/gpuservice/gpustats/include/gpustats/GpuStats.h +++ b/services/gpuservice/gpustats/include/gpustats/GpuStats.h @@ -18,6 +18,7 @@ #include <graphicsenv/GpuStatsInfo.h> #include <graphicsenv/GraphicsEnv.h> +#include <stats_pull_atom_callback.h> #include <utils/String16.h> #include <utils/Vector.h> @@ -29,8 +30,8 @@ namespace android { class GpuStats { public: - GpuStats() = default; - ~GpuStats() = default; + GpuStats(); + ~GpuStats(); // Insert new gpu driver stats into global stats and app stats. void insertDriverStats(const std::string& driverPackageName, @@ -43,15 +44,22 @@ public: const GpuStatsInfo::Stats stats, const uint64_t value); // dumpsys interface void dump(const Vector<String16>& args, std::string* result); - // Pull gpu global stats - void pullGlobalStats(std::vector<GpuStatsGlobalInfo>* outStats); - // Pull gpu app stats - void pullAppStats(std::vector<GpuStatsAppInfo>* outStats); // This limits the worst case number of loading times tracked. static const size_t MAX_NUM_LOADING_TIMES = 50; private: + // Friend class for testing. + friend class TestableGpuStats; + + // Native atom puller callback registered in statsd. + static AStatsManager_PullAtomCallbackReturn pullAtomCallback(int32_t atomTag, + AStatsEventList* data, + void* cookie); + // Pull global into into global atom. + AStatsManager_PullAtomCallbackReturn pullGlobalInfoAtom(AStatsEventList* data); + // Pull app into into app atom. + AStatsManager_PullAtomCallbackReturn pullAppInfoAtom(AStatsEventList* data); // Dump global stats void dumpGlobalLocked(std::string* result); // Dump app stats diff --git a/services/gpuservice/tests/unittests/Android.bp b/services/gpuservice/tests/unittests/Android.bp index fee5bd4a56..538506da77 100644 --- a/services/gpuservice/tests/unittests/Android.bp +++ b/services/gpuservice/tests/unittests/Android.bp @@ -26,6 +26,8 @@ cc_test { "libgfxstats", "libgraphicsenv", "liblog", + "libstatslog", + "libstatspull", "libutils", ], static_libs: [ diff --git a/services/gpuservice/tests/unittests/GpuStatsTest.cpp b/services/gpuservice/tests/unittests/GpuStatsTest.cpp index f038c8afda..37ebeae18d 100644 --- a/services/gpuservice/tests/unittests/GpuStatsTest.cpp +++ b/services/gpuservice/tests/unittests/GpuStatsTest.cpp @@ -21,9 +21,13 @@ #include <gmock/gmock.h> #include <gpustats/GpuStats.h> #include <gtest/gtest.h> +#include <stats_pull_atom_callback.h> +#include <statslog.h> #include <utils/String16.h> #include <utils/Vector.h> +#include "TestableGpuStats.h" + namespace android { namespace { @@ -249,5 +253,55 @@ TEST_F(GpuStatsTest, canDumpAppBeforeClearApp) { EXPECT_FALSE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); } +TEST_F(GpuStatsTest, skipPullInvalidAtom) { + TestableGpuStats testableGpuStats(mGpuStats.get()); + mGpuStats->insertDriverStats(BUILTIN_DRIVER_PKG_NAME, BUILTIN_DRIVER_VER_NAME, + BUILTIN_DRIVER_VER_CODE, BUILTIN_DRIVER_BUILD_TIME, APP_PKG_NAME_1, + VULKAN_VERSION, GpuStatsInfo::Driver::GL, true, + DRIVER_LOADING_TIME_1); + + EXPECT_FALSE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); + EXPECT_FALSE(inputCommand(InputCommand::DUMP_APP).empty()); + + EXPECT_TRUE(testableGpuStats.makePullAtomCallback(-1) == AStatsManager_PULL_SKIP); + + EXPECT_FALSE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); + EXPECT_FALSE(inputCommand(InputCommand::DUMP_APP).empty()); +} + +TEST_F(GpuStatsTest, canPullGlobalAtom) { + TestableGpuStats testableGpuStats(mGpuStats.get()); + mGpuStats->insertDriverStats(BUILTIN_DRIVER_PKG_NAME, BUILTIN_DRIVER_VER_NAME, + BUILTIN_DRIVER_VER_CODE, BUILTIN_DRIVER_BUILD_TIME, APP_PKG_NAME_1, + VULKAN_VERSION, GpuStatsInfo::Driver::GL, true, + DRIVER_LOADING_TIME_1); + + EXPECT_FALSE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); + EXPECT_FALSE(inputCommand(InputCommand::DUMP_APP).empty()); + + EXPECT_TRUE(testableGpuStats.makePullAtomCallback(android::util::GPU_STATS_GLOBAL_INFO) == + AStatsManager_PULL_SUCCESS); + + EXPECT_TRUE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); + EXPECT_FALSE(inputCommand(InputCommand::DUMP_APP).empty()); +} + +TEST_F(GpuStatsTest, canPullAppAtom) { + TestableGpuStats testableGpuStats(mGpuStats.get()); + mGpuStats->insertDriverStats(BUILTIN_DRIVER_PKG_NAME, BUILTIN_DRIVER_VER_NAME, + BUILTIN_DRIVER_VER_CODE, BUILTIN_DRIVER_BUILD_TIME, APP_PKG_NAME_1, + VULKAN_VERSION, GpuStatsInfo::Driver::GL, true, + DRIVER_LOADING_TIME_1); + + EXPECT_FALSE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); + EXPECT_FALSE(inputCommand(InputCommand::DUMP_APP).empty()); + + EXPECT_TRUE(testableGpuStats.makePullAtomCallback(android::util::GPU_STATS_APP_INFO) == + AStatsManager_PULL_SUCCESS); + + EXPECT_FALSE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); + EXPECT_TRUE(inputCommand(InputCommand::DUMP_APP).empty()); +} + } // namespace } // namespace android diff --git a/services/gpuservice/tests/unittests/TestableGpuStats.h b/services/gpuservice/tests/unittests/TestableGpuStats.h new file mode 100644 index 0000000000..4ea564c85d --- /dev/null +++ b/services/gpuservice/tests/unittests/TestableGpuStats.h @@ -0,0 +1,36 @@ +/* + * Copyright 2020 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. + */ + +#pragma once + +#include <gpustats/GpuStats.h> +#include <stdint.h> + +namespace android { + +class TestableGpuStats { +public: + explicit TestableGpuStats(GpuStats *gpuStats) : mGpuStats(gpuStats) {} + + AStatsManager_PullAtomCallbackReturn makePullAtomCallback(int32_t atomTag) { + return mGpuStats->pullAtomCallback(atomTag, nullptr, mGpuStats); + } + +private: + GpuStats *mGpuStats; +}; + +} // namespace android |