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