Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #undef LOG_TAG |
| 17 | #define LOG_TAG "GpuStats" |
| 18 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 19 | |
Yiwei Zhang | 29f8593 | 2020-02-04 17:14:54 -0800 | [diff] [blame] | 20 | #include "gpustats/GpuStats.h" |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 21 | |
Yiwei Zhang | 29f8593 | 2020-02-04 17:14:54 -0800 | [diff] [blame] | 22 | #include <android/util/ProtoOutputStream.h> |
Yiwei Zhang | 174a2a0 | 2019-05-06 19:08:31 -0700 | [diff] [blame] | 23 | #include <cutils/properties.h> |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 24 | #include <log/log.h> |
Yiwei Zhang | b59a127 | 2020-02-04 14:58:01 -0800 | [diff] [blame] | 25 | #include <stats_event.h> |
| 26 | #include <statslog.h> |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 27 | #include <utils/Trace.h> |
| 28 | |
Yiwei Zhang | 174a2a0 | 2019-05-06 19:08:31 -0700 | [diff] [blame] | 29 | #include <unordered_set> |
| 30 | |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 31 | namespace android { |
| 32 | |
Yiwei Zhang | b59a127 | 2020-02-04 14:58:01 -0800 | [diff] [blame] | 33 | GpuStats::~GpuStats() { |
Alec Mouri | 822b10a | 2020-03-17 17:51:27 -0700 | [diff] [blame^] | 34 | if (mStatsdRegistered) { |
| 35 | AStatsManager_unregisterPullAtomCallback(android::util::GPU_STATS_GLOBAL_INFO); |
| 36 | AStatsManager_unregisterPullAtomCallback(android::util::GPU_STATS_APP_INFO); |
| 37 | } |
Yiwei Zhang | b59a127 | 2020-02-04 14:58:01 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 40 | static void addLoadingCount(GpuStatsInfo::Driver driver, bool isDriverLoaded, |
Yiwei Zhang | f40fb10 | 2019-02-27 21:05:06 -0800 | [diff] [blame] | 41 | GpuStatsGlobalInfo* const outGlobalInfo) { |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 42 | switch (driver) { |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 43 | case GpuStatsInfo::Driver::GL: |
| 44 | case GpuStatsInfo::Driver::GL_UPDATED: |
Yiwei Zhang | f40fb10 | 2019-02-27 21:05:06 -0800 | [diff] [blame] | 45 | outGlobalInfo->glLoadingCount++; |
| 46 | if (!isDriverLoaded) outGlobalInfo->glLoadingFailureCount++; |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 47 | break; |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 48 | case GpuStatsInfo::Driver::VULKAN: |
| 49 | case GpuStatsInfo::Driver::VULKAN_UPDATED: |
Yiwei Zhang | f40fb10 | 2019-02-27 21:05:06 -0800 | [diff] [blame] | 50 | outGlobalInfo->vkLoadingCount++; |
| 51 | if (!isDriverLoaded) outGlobalInfo->vkLoadingFailureCount++; |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 52 | break; |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 53 | case GpuStatsInfo::Driver::ANGLE: |
Yiwei Zhang | 8e7c4b6 | 2019-05-08 15:57:59 -0700 | [diff] [blame] | 54 | outGlobalInfo->angleLoadingCount++; |
| 55 | if (!isDriverLoaded) outGlobalInfo->angleLoadingFailureCount++; |
| 56 | break; |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 57 | default: |
Yiwei Zhang | 8e7c4b6 | 2019-05-08 15:57:59 -0700 | [diff] [blame] | 58 | break; |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 59 | } |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 62 | static void addLoadingTime(GpuStatsInfo::Driver driver, int64_t driverLoadingTime, |
Yiwei Zhang | f40fb10 | 2019-02-27 21:05:06 -0800 | [diff] [blame] | 63 | GpuStatsAppInfo* const outAppInfo) { |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 64 | switch (driver) { |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 65 | case GpuStatsInfo::Driver::GL: |
| 66 | case GpuStatsInfo::Driver::GL_UPDATED: |
Yiwei Zhang | 8e7c4b6 | 2019-05-08 15:57:59 -0700 | [diff] [blame] | 67 | if (outAppInfo->glDriverLoadingTime.size() < GpuStats::MAX_NUM_LOADING_TIMES) { |
| 68 | outAppInfo->glDriverLoadingTime.emplace_back(driverLoadingTime); |
| 69 | } |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 70 | break; |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 71 | case GpuStatsInfo::Driver::VULKAN: |
| 72 | case GpuStatsInfo::Driver::VULKAN_UPDATED: |
Yiwei Zhang | 8e7c4b6 | 2019-05-08 15:57:59 -0700 | [diff] [blame] | 73 | if (outAppInfo->vkDriverLoadingTime.size() < GpuStats::MAX_NUM_LOADING_TIMES) { |
| 74 | outAppInfo->vkDriverLoadingTime.emplace_back(driverLoadingTime); |
| 75 | } |
| 76 | break; |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 77 | case GpuStatsInfo::Driver::ANGLE: |
Yiwei Zhang | 8e7c4b6 | 2019-05-08 15:57:59 -0700 | [diff] [blame] | 78 | if (outAppInfo->angleDriverLoadingTime.size() < GpuStats::MAX_NUM_LOADING_TIMES) { |
| 79 | outAppInfo->angleDriverLoadingTime.emplace_back(driverLoadingTime); |
| 80 | } |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 81 | break; |
| 82 | default: |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | |
Yiwei Zhang | fdd7e78 | 2020-01-31 15:59:34 -0800 | [diff] [blame] | 87 | void GpuStats::insertDriverStats(const std::string& driverPackageName, |
| 88 | const std::string& driverVersionName, uint64_t driverVersionCode, |
| 89 | int64_t driverBuildTime, const std::string& appPackageName, |
| 90 | const int32_t vulkanVersion, GpuStatsInfo::Driver driver, |
| 91 | bool isDriverLoaded, int64_t driverLoadingTime) { |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 92 | ATRACE_CALL(); |
| 93 | |
| 94 | std::lock_guard<std::mutex> lock(mLock); |
Alec Mouri | 822b10a | 2020-03-17 17:51:27 -0700 | [diff] [blame^] | 95 | registerStatsdCallbacksIfNeeded(); |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 96 | ALOGV("Received:\n" |
| 97 | "\tdriverPackageName[%s]\n" |
| 98 | "\tdriverVersionName[%s]\n" |
| 99 | "\tdriverVersionCode[%" PRIu64 "]\n" |
| 100 | "\tdriverBuildTime[%" PRId64 "]\n" |
| 101 | "\tappPackageName[%s]\n" |
Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 102 | "\tvulkanVersion[%d]\n" |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 103 | "\tdriver[%d]\n" |
| 104 | "\tisDriverLoaded[%d]\n" |
| 105 | "\tdriverLoadingTime[%" PRId64 "]", |
| 106 | driverPackageName.c_str(), driverVersionName.c_str(), driverVersionCode, driverBuildTime, |
Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 107 | appPackageName.c_str(), vulkanVersion, static_cast<int32_t>(driver), isDriverLoaded, |
| 108 | driverLoadingTime); |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 109 | |
| 110 | if (!mGlobalStats.count(driverVersionCode)) { |
Yiwei Zhang | f40fb10 | 2019-02-27 21:05:06 -0800 | [diff] [blame] | 111 | GpuStatsGlobalInfo globalInfo; |
Yiwei Zhang | 8e7c4b6 | 2019-05-08 15:57:59 -0700 | [diff] [blame] | 112 | addLoadingCount(driver, isDriverLoaded, &globalInfo); |
Yiwei Zhang | f40fb10 | 2019-02-27 21:05:06 -0800 | [diff] [blame] | 113 | globalInfo.driverPackageName = driverPackageName; |
| 114 | globalInfo.driverVersionName = driverVersionName; |
| 115 | globalInfo.driverVersionCode = driverVersionCode; |
| 116 | globalInfo.driverBuildTime = driverBuildTime; |
Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 117 | globalInfo.vulkanVersion = vulkanVersion; |
Yiwei Zhang | f40fb10 | 2019-02-27 21:05:06 -0800 | [diff] [blame] | 118 | mGlobalStats.insert({driverVersionCode, globalInfo}); |
Yiwei Zhang | 8e7c4b6 | 2019-05-08 15:57:59 -0700 | [diff] [blame] | 119 | } else { |
| 120 | addLoadingCount(driver, isDriverLoaded, &mGlobalStats[driverVersionCode]); |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 123 | const std::string appStatsKey = appPackageName + std::to_string(driverVersionCode); |
| 124 | if (!mAppStats.count(appStatsKey)) { |
Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 125 | if (mAppStats.size() >= MAX_NUM_APP_RECORDS) { |
| 126 | ALOGV("GpuStatsAppInfo has reached maximum size. Ignore new stats."); |
| 127 | return; |
| 128 | } |
| 129 | |
Yiwei Zhang | f40fb10 | 2019-02-27 21:05:06 -0800 | [diff] [blame] | 130 | GpuStatsAppInfo appInfo; |
| 131 | addLoadingTime(driver, driverLoadingTime, &appInfo); |
| 132 | appInfo.appPackageName = appPackageName; |
| 133 | appInfo.driverVersionCode = driverVersionCode; |
| 134 | mAppStats.insert({appStatsKey, appInfo}); |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 135 | return; |
| 136 | } |
| 137 | |
| 138 | addLoadingTime(driver, driverLoadingTime, &mAppStats[appStatsKey]); |
| 139 | } |
| 140 | |
Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 141 | void GpuStats::insertTargetStats(const std::string& appPackageName, |
| 142 | const uint64_t driverVersionCode, const GpuStatsInfo::Stats stats, |
| 143 | const uint64_t /*value*/) { |
| 144 | ATRACE_CALL(); |
| 145 | |
Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 146 | const std::string appStatsKey = appPackageName + std::to_string(driverVersionCode); |
Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 147 | |
| 148 | std::lock_guard<std::mutex> lock(mLock); |
Alec Mouri | 822b10a | 2020-03-17 17:51:27 -0700 | [diff] [blame^] | 149 | registerStatsdCallbacksIfNeeded(); |
Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 150 | if (!mAppStats.count(appStatsKey)) { |
| 151 | return; |
| 152 | } |
| 153 | |
Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 154 | switch (stats) { |
| 155 | case GpuStatsInfo::Stats::CPU_VULKAN_IN_USE: |
| 156 | mAppStats[appStatsKey].cpuVulkanInUse = true; |
| 157 | break; |
Yiwei Zhang | 69395cd | 2019-07-03 16:55:39 -0700 | [diff] [blame] | 158 | case GpuStatsInfo::Stats::FALSE_PREROTATION: |
| 159 | mAppStats[appStatsKey].falsePrerotation = true; |
| 160 | break; |
Yiwei Zhang | 011538f | 2019-12-20 14:37:21 -0800 | [diff] [blame] | 161 | case GpuStatsInfo::Stats::GLES_1_IN_USE: |
| 162 | mAppStats[appStatsKey].gles1InUse = true; |
| 163 | break; |
Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 164 | default: |
| 165 | break; |
| 166 | } |
Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Yiwei Zhang | 174a2a0 | 2019-05-06 19:08:31 -0700 | [diff] [blame] | 169 | void GpuStats::interceptSystemDriverStatsLocked() { |
| 170 | // Append cpuVulkanVersion and glesVersion to system driver stats |
| 171 | if (!mGlobalStats.count(0) || mGlobalStats[0].glesVersion) { |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | mGlobalStats[0].cpuVulkanVersion = property_get_int32("ro.cpuvulkan.version", 0); |
| 176 | mGlobalStats[0].glesVersion = property_get_int32("ro.opengles.version", 0); |
| 177 | } |
| 178 | |
Alec Mouri | 822b10a | 2020-03-17 17:51:27 -0700 | [diff] [blame^] | 179 | void GpuStats::registerStatsdCallbacksIfNeeded() { |
| 180 | if (!mStatsdRegistered) { |
| 181 | AStatsManager_registerPullAtomCallback(android::util::GPU_STATS_GLOBAL_INFO, |
| 182 | GpuStats::pullAtomCallback, nullptr, this); |
| 183 | AStatsManager_registerPullAtomCallback(android::util::GPU_STATS_APP_INFO, |
| 184 | GpuStats::pullAtomCallback, nullptr, this); |
| 185 | mStatsdRegistered = true; |
| 186 | } |
| 187 | } |
| 188 | |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 189 | void GpuStats::dump(const Vector<String16>& args, std::string* result) { |
| 190 | ATRACE_CALL(); |
| 191 | |
| 192 | if (!result) { |
| 193 | ALOGE("Dump result shouldn't be nullptr."); |
| 194 | return; |
| 195 | } |
| 196 | |
| 197 | std::lock_guard<std::mutex> lock(mLock); |
| 198 | bool dumpAll = true; |
| 199 | |
| 200 | std::unordered_set<std::string> argsSet; |
| 201 | for (size_t i = 0; i < args.size(); i++) { |
| 202 | argsSet.insert(String8(args[i]).c_str()); |
| 203 | } |
| 204 | |
| 205 | const bool dumpGlobal = argsSet.count("--global") != 0; |
| 206 | if (dumpGlobal) { |
| 207 | dumpGlobalLocked(result); |
| 208 | dumpAll = false; |
| 209 | } |
| 210 | |
| 211 | const bool dumpApp = argsSet.count("--app") != 0; |
| 212 | if (dumpApp) { |
| 213 | dumpAppLocked(result); |
| 214 | dumpAll = false; |
| 215 | } |
| 216 | |
Yiwei Zhang | fdd7e78 | 2020-01-31 15:59:34 -0800 | [diff] [blame] | 217 | if (dumpAll) { |
| 218 | dumpGlobalLocked(result); |
| 219 | dumpAppLocked(result); |
| 220 | } |
| 221 | |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 222 | if (argsSet.count("--clear")) { |
| 223 | bool clearAll = true; |
| 224 | |
| 225 | if (dumpGlobal) { |
| 226 | mGlobalStats.clear(); |
| 227 | clearAll = false; |
| 228 | } |
| 229 | |
| 230 | if (dumpApp) { |
| 231 | mAppStats.clear(); |
| 232 | clearAll = false; |
| 233 | } |
| 234 | |
| 235 | if (clearAll) { |
| 236 | mGlobalStats.clear(); |
| 237 | mAppStats.clear(); |
| 238 | } |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
| 242 | void GpuStats::dumpGlobalLocked(std::string* result) { |
Yiwei Zhang | 174a2a0 | 2019-05-06 19:08:31 -0700 | [diff] [blame] | 243 | interceptSystemDriverStatsLocked(); |
| 244 | |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 245 | for (const auto& ele : mGlobalStats) { |
Yiwei Zhang | f40fb10 | 2019-02-27 21:05:06 -0800 | [diff] [blame] | 246 | result->append(ele.second.toString()); |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 247 | result->append("\n"); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | void GpuStats::dumpAppLocked(std::string* result) { |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 252 | for (const auto& ele : mAppStats) { |
Yiwei Zhang | f40fb10 | 2019-02-27 21:05:06 -0800 | [diff] [blame] | 253 | result->append(ele.second.toString()); |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 254 | result->append("\n"); |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
Yiwei Zhang | 29f8593 | 2020-02-04 17:14:54 -0800 | [diff] [blame] | 258 | static std::string protoOutputStreamToByteString(android::util::ProtoOutputStream& proto) { |
| 259 | if (!proto.size()) return ""; |
| 260 | |
| 261 | std::string byteString; |
| 262 | sp<android::util::ProtoReader> reader = proto.data(); |
| 263 | while (reader->readBuffer() != nullptr) { |
| 264 | const size_t toRead = reader->currentToRead(); |
| 265 | byteString.append((char*)reader->readBuffer(), toRead); |
| 266 | reader->move(toRead); |
| 267 | } |
| 268 | |
| 269 | if (byteString.size() != proto.size()) return ""; |
| 270 | |
| 271 | return byteString; |
| 272 | } |
| 273 | |
| 274 | static std::string int64VectorToProtoByteString(const std::vector<int64_t>& value) { |
| 275 | if (value.empty()) return ""; |
| 276 | |
| 277 | android::util::ProtoOutputStream proto; |
| 278 | for (const auto& ele : value) { |
| 279 | proto.write(android::util::FIELD_TYPE_INT64 | android::util::FIELD_COUNT_REPEATED | |
| 280 | 1 /* field id */, |
| 281 | (long long)ele); |
| 282 | } |
| 283 | |
| 284 | return protoOutputStreamToByteString(proto); |
| 285 | } |
| 286 | |
| 287 | AStatsManager_PullAtomCallbackReturn GpuStats::pullAppInfoAtom(AStatsEventList* data) { |
| 288 | ATRACE_CALL(); |
| 289 | |
| 290 | std::lock_guard<std::mutex> lock(mLock); |
| 291 | |
| 292 | if (data) { |
| 293 | for (const auto& ele : mAppStats) { |
| 294 | AStatsEvent* event = AStatsEventList_addStatsEvent(data); |
| 295 | AStatsEvent_setAtomId(event, android::util::GPU_STATS_APP_INFO); |
| 296 | AStatsEvent_writeString(event, ele.second.appPackageName.c_str()); |
| 297 | AStatsEvent_writeInt64(event, ele.second.driverVersionCode); |
| 298 | |
| 299 | std::string bytes = int64VectorToProtoByteString(ele.second.glDriverLoadingTime); |
| 300 | AStatsEvent_writeByteArray(event, (const uint8_t*)bytes.c_str(), bytes.length()); |
| 301 | |
| 302 | bytes = int64VectorToProtoByteString(ele.second.vkDriverLoadingTime); |
| 303 | AStatsEvent_writeByteArray(event, (const uint8_t*)bytes.c_str(), bytes.length()); |
| 304 | |
| 305 | bytes = int64VectorToProtoByteString(ele.second.angleDriverLoadingTime); |
| 306 | AStatsEvent_writeByteArray(event, (const uint8_t*)bytes.c_str(), bytes.length()); |
| 307 | |
| 308 | AStatsEvent_writeBool(event, ele.second.cpuVulkanInUse); |
| 309 | AStatsEvent_writeBool(event, ele.second.falsePrerotation); |
| 310 | AStatsEvent_writeBool(event, ele.second.gles1InUse); |
| 311 | AStatsEvent_build(event); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | mAppStats.clear(); |
| 316 | |
| 317 | return AStatsManager_PULL_SUCCESS; |
| 318 | } |
| 319 | |
Yiwei Zhang | b59a127 | 2020-02-04 14:58:01 -0800 | [diff] [blame] | 320 | AStatsManager_PullAtomCallbackReturn GpuStats::pullGlobalInfoAtom(AStatsEventList* data) { |
| 321 | ATRACE_CALL(); |
| 322 | |
| 323 | std::lock_guard<std::mutex> lock(mLock); |
| 324 | // flush cpuVulkanVersion and glesVersion to builtin driver stats |
| 325 | interceptSystemDriverStatsLocked(); |
| 326 | |
| 327 | if (data) { |
| 328 | for (const auto& ele : mGlobalStats) { |
| 329 | AStatsEvent* event = AStatsEventList_addStatsEvent(data); |
| 330 | AStatsEvent_setAtomId(event, android::util::GPU_STATS_GLOBAL_INFO); |
| 331 | AStatsEvent_writeString(event, ele.second.driverPackageName.c_str()); |
| 332 | AStatsEvent_writeString(event, ele.second.driverVersionName.c_str()); |
| 333 | AStatsEvent_writeInt64(event, ele.second.driverVersionCode); |
| 334 | AStatsEvent_writeInt64(event, ele.second.driverBuildTime); |
| 335 | AStatsEvent_writeInt64(event, ele.second.glLoadingCount); |
| 336 | AStatsEvent_writeInt64(event, ele.second.glLoadingFailureCount); |
| 337 | AStatsEvent_writeInt64(event, ele.second.vkLoadingCount); |
| 338 | AStatsEvent_writeInt64(event, ele.second.vkLoadingFailureCount); |
| 339 | AStatsEvent_writeInt32(event, ele.second.vulkanVersion); |
| 340 | AStatsEvent_writeInt32(event, ele.second.cpuVulkanVersion); |
| 341 | AStatsEvent_writeInt32(event, ele.second.glesVersion); |
| 342 | AStatsEvent_writeInt64(event, ele.second.angleLoadingCount); |
| 343 | AStatsEvent_writeInt64(event, ele.second.angleLoadingFailureCount); |
| 344 | AStatsEvent_build(event); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | mGlobalStats.clear(); |
| 349 | |
| 350 | return AStatsManager_PULL_SUCCESS; |
| 351 | } |
| 352 | |
| 353 | AStatsManager_PullAtomCallbackReturn GpuStats::pullAtomCallback(int32_t atomTag, |
| 354 | AStatsEventList* data, |
| 355 | void* cookie) { |
| 356 | ATRACE_CALL(); |
| 357 | |
| 358 | GpuStats* pGpuStats = reinterpret_cast<GpuStats*>(cookie); |
| 359 | if (atomTag == android::util::GPU_STATS_GLOBAL_INFO) { |
| 360 | return pGpuStats->pullGlobalInfoAtom(data); |
Yiwei Zhang | 29f8593 | 2020-02-04 17:14:54 -0800 | [diff] [blame] | 361 | } else if (atomTag == android::util::GPU_STATS_APP_INFO) { |
| 362 | return pGpuStats->pullAppInfoAtom(data); |
Yiwei Zhang | b59a127 | 2020-02-04 14:58:01 -0800 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | return AStatsManager_PULL_SKIP; |
| 366 | } |
| 367 | |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 368 | } // namespace android |