From 7e6330353eb46822337f534a3cfc07ed017d20fb Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Fri, 1 Mar 2019 17:25:27 -0800 Subject: [PATCH] Game Driver Metrics: add GpuStatsPuller to get gpu global stats Bug: 123529932 Test: adb shell cmd stats pull-source 10054 Change-Id: Ib43a93661d24ce0d4b1e1ae6b6d0b50dbdfd3c15 --- cmds/statsd/Android.bp | 2 + cmds/statsd/src/external/GpuStatsPuller.cpp | 91 +++++++++++++++++++ cmds/statsd/src/external/GpuStatsPuller.h | 36 ++++++++ .../src/external/StatsPullerManager.cpp | 4 + 4 files changed, 133 insertions(+) create mode 100644 cmds/statsd/src/external/GpuStatsPuller.cpp create mode 100644 cmds/statsd/src/external/GpuStatsPuller.h diff --git a/cmds/statsd/Android.bp b/cmds/statsd/Android.bp index ca48881ca519e..da720021512d8 100644 --- a/cmds/statsd/Android.bp +++ b/cmds/statsd/Android.bp @@ -68,6 +68,7 @@ cc_defaults { "src/config/ConfigKey.cpp", "src/config/ConfigListener.cpp", "src/config/ConfigManager.cpp", + "src/external/GpuStatsPuller.cpp", "src/external/Perfetto.cpp", "src/external/Perfprofd.cpp", "src/external/StatsPuller.cpp", @@ -122,6 +123,7 @@ cc_defaults { shared_libs: [ "libbase", "libbinder", + "libgraphicsenv", "libincident", "liblog", "libutils", diff --git a/cmds/statsd/src/external/GpuStatsPuller.cpp b/cmds/statsd/src/external/GpuStatsPuller.cpp new file mode 100644 index 0000000000000..8445803217195 --- /dev/null +++ b/cmds/statsd/src/external/GpuStatsPuller.cpp @@ -0,0 +1,91 @@ +/* + * 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 "GpuStatsPuller.h" + +#include +#include +#include + +#include "logd/LogEvent.h" + +#include "stats_log_util.h" +#include "statslog.h" + +namespace android { +namespace os { +namespace statsd { + +GpuStatsPuller::GpuStatsPuller(const int tagId) : StatsPuller(tagId) { +} + +static sp getGpuService() { + const sp binder = defaultServiceManager()->checkService(String16("gpu")); + if (!binder) { + ALOGE("Failed to get gpu service"); + return nullptr; + } + + return interface_cast(binder); +} + +static bool pullGpuStatsGlobalInfo(const sp& gpuService, + std::vector>* data) { + std::vector stats; + status_t status = gpuService->getGpuStatsGlobalInfo(&stats); + if (status != OK) { + return false; + } + + data->clear(); + data->reserve(stats.size()); + for (const auto& info : stats) { + std::shared_ptr event = make_shared( + android::util::GPU_STATS_GLOBAL_INFO, getWallClockNs(), getElapsedRealtimeNs()); + if (!event->write(info.driverPackageName)) return false; + if (!event->write(info.driverVersionName)) return false; + if (!event->write((int64_t)info.driverVersionCode)) return false; + if (!event->write(info.driverBuildTime)) return false; + if (!event->write((int64_t)info.glLoadingCount)) return false; + if (!event->write((int64_t)info.glLoadingFailureCount)) return false; + if (!event->write((int64_t)info.vkLoadingCount)) return false; + if (!event->write((int64_t)info.vkLoadingFailureCount)) return false; + event->init(); + data->emplace_back(event); + } + + return true; +} + +bool GpuStatsPuller::PullInternal(std::vector>* data) { + const sp gpuService = getGpuService(); + if (!gpuService) { + return false; + } + + switch (mTagId) { + case android::util::GPU_STATS_GLOBAL_INFO: + return pullGpuStatsGlobalInfo(gpuService, data); + default: + break; + } + + return false; +} + +} // namespace statsd +} // namespace os +} // namespace android diff --git a/cmds/statsd/src/external/GpuStatsPuller.h b/cmds/statsd/src/external/GpuStatsPuller.h new file mode 100644 index 0000000000000..4c7a4d6042528 --- /dev/null +++ b/cmds/statsd/src/external/GpuStatsPuller.h @@ -0,0 +1,36 @@ +/* + * 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. + */ + +#pragma once + +#include "StatsPuller.h" + +namespace android { +namespace os { +namespace statsd { + +/** + * Pull GpuStats from GpuService. + */ +class GpuStatsPuller : public StatsPuller { +public: + explicit GpuStatsPuller(const int tagId); + bool PullInternal(std::vector>* data) override; +}; + +} // namespace statsd +} // namespace os +} // namespace android diff --git a/cmds/statsd/src/external/StatsPullerManager.cpp b/cmds/statsd/src/external/StatsPullerManager.cpp index 1513834b67244..924704ba6db55 100644 --- a/cmds/statsd/src/external/StatsPullerManager.cpp +++ b/cmds/statsd/src/external/StatsPullerManager.cpp @@ -27,6 +27,7 @@ #include "../logd/LogEvent.h" #include "../stats_log_util.h" #include "../statscompanion_util.h" +#include "GpuStatsPuller.h" #include "PowerStatsPuller.h" #include "ResourceHealthManagerPuller.h" #include "StatsCallbackPuller.h" @@ -240,6 +241,9 @@ std::map StatsPullerManager::kAllPullAtomInfo = { // SDCardInfo {android::util::SDCARD_INFO, {.puller = new StatsCompanionServicePuller(android::util::SDCARD_INFO)}}, + // GpuStatsGlobalInfo + {android::util::GPU_STATS_GLOBAL_INFO, + {.puller = new GpuStatsPuller(android::util::GPU_STATS_GLOBAL_INFO)}}, }; StatsPullerManager::StatsPullerManager() : mNextPullTimeNs(NO_ALARM_UPDATE) {