Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 18 | |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 19 | #include "GpuService.h" |
| 20 | |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 21 | #include <android-base/stringprintf.h> |
| 22 | #include <binder/IPCThreadState.h> |
Jesse Hall | c0b1577 | 2016-12-20 14:47:45 -0800 | [diff] [blame] | 23 | #include <binder/IResultReceiver.h> |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 24 | #include <binder/Parcel.h> |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 25 | #include <binder/PermissionCache.h> |
Yiwei Zhang | 2a61c15 | 2019-02-27 11:27:18 -0800 | [diff] [blame] | 26 | #include <cutils/properties.h> |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 27 | #include <private/android_filesystem_config.h> |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 28 | #include <utils/String8.h> |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 29 | #include <utils/Trace.h> |
| 30 | |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 31 | #include <array> |
| 32 | #include <fstream> |
| 33 | #include <sstream> |
| 34 | #include <sys/types.h> |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 35 | #include <vkjson.h> |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 36 | #include <unistd.h> |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 37 | |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 38 | #include "gpustats/GpuStats.h" |
| 39 | |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 40 | namespace android { |
| 41 | |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 42 | using base::StringAppendF; |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 43 | |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 44 | namespace { |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 45 | status_t cmdHelp(int out); |
| 46 | status_t cmdVkjson(int out, int err); |
Yiwei Zhang | 2a61c15 | 2019-02-27 11:27:18 -0800 | [diff] [blame] | 47 | void dumpGameDriverInfo(std::string* result); |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 48 | void dumpMemoryInfo(std::string* result, const GpuMemoryMap& memories, uint32_t pid); |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 49 | } // namespace |
| 50 | |
| 51 | const String16 sDump("android.permission.DUMP"); |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 52 | |
Yiwei Zhang | 423d080 | 2018-11-16 10:56:12 -0800 | [diff] [blame] | 53 | const char* const GpuService::SERVICE_NAME = "gpu"; |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 54 | |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 55 | GpuService::GpuService() : mGpuStats(std::make_unique<GpuStats>()){}; |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 56 | |
Greg Kaiser | 210bb7e | 2019-02-12 12:40:05 -0800 | [diff] [blame] | 57 | void GpuService::setGpuStats(const std::string& driverPackageName, |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 58 | const std::string& driverVersionName, uint64_t driverVersionCode, |
Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 59 | int64_t driverBuildTime, const std::string& appPackageName, |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 60 | const int32_t vulkanVersion, GpuStatsInfo::Driver driver, |
Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 61 | bool isDriverLoaded, int64_t driverLoadingTime) { |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 62 | mGpuStats->insert(driverPackageName, driverVersionName, driverVersionCode, driverBuildTime, |
Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 63 | appPackageName, vulkanVersion, driver, isDriverLoaded, driverLoadingTime); |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Yiwei Zhang | baea97f | 2019-02-27 16:35:37 -0800 | [diff] [blame] | 66 | status_t GpuService::getGpuStatsGlobalInfo(std::vector<GpuStatsGlobalInfo>* outStats) const { |
Yiwei Zhang | baea97f | 2019-02-27 16:35:37 -0800 | [diff] [blame] | 67 | mGpuStats->pullGlobalStats(outStats); |
Yiwei Zhang | baea97f | 2019-02-27 16:35:37 -0800 | [diff] [blame] | 68 | return OK; |
| 69 | } |
| 70 | |
Yiwei Zhang | 178e067 | 2019-03-04 14:17:12 -0800 | [diff] [blame] | 71 | status_t GpuService::getGpuStatsAppInfo(std::vector<GpuStatsAppInfo>* outStats) const { |
Yiwei Zhang | 178e067 | 2019-03-04 14:17:12 -0800 | [diff] [blame] | 72 | mGpuStats->pullAppStats(outStats); |
Yiwei Zhang | 178e067 | 2019-03-04 14:17:12 -0800 | [diff] [blame] | 73 | return OK; |
| 74 | } |
| 75 | |
Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 76 | void GpuService::setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, |
| 77 | const GpuStatsInfo::Stats stats, const uint64_t value) { |
| 78 | mGpuStats->insertTargetStats(appPackageName, driverVersionCode, stats, value); |
Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 81 | bool isExpectedFormat(const char* str) { |
| 82 | // Should match in order: |
| 83 | // gpuaddr useraddr size id flags type usage sglen mapsize eglsrf eglimg |
| 84 | std::istringstream iss; |
| 85 | iss.str(str); |
| 86 | |
| 87 | std::string word; |
| 88 | iss >> word; |
| 89 | if (word != "gpuaddr") { return false; } |
| 90 | iss >> word; |
| 91 | if (word != "useraddr") { return false; } |
| 92 | iss >> word; |
| 93 | if (word != "size") { return false; } |
| 94 | iss >> word; |
| 95 | if (word != "id") { return false; } |
| 96 | iss >> word; |
| 97 | if (word != "flags") { return false; } |
| 98 | iss >> word; |
| 99 | if (word != "type") { return false; } |
| 100 | iss >> word; |
| 101 | if (word != "usage") { return false; } |
| 102 | iss >> word; |
| 103 | if (word != "sglen") { return false; } |
| 104 | iss >> word; |
| 105 | if (word != "mapsize") { return false; } |
| 106 | iss >> word; |
| 107 | if (word != "eglsrf") { return false; } |
| 108 | iss >> word; |
| 109 | if (word != "eglimg") { return false; } |
| 110 | return true; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | // Queries gpu memory via Qualcomm's /d/kgsl/proc/*/mem interface. |
| 115 | status_t GpuService::getQCommGpuMemoryInfo(GpuMemoryMap* memories, std::string* result, int32_t dumpPid) const { |
| 116 | const std::string kDirectoryPath = "/d/kgsl/proc"; |
| 117 | DIR* directory = opendir(kDirectoryPath.c_str()); |
| 118 | if (!directory) { return PERMISSION_DENIED; } |
| 119 | |
| 120 | // File Format: |
| 121 | // gpuaddr useraddr size id flags type usage sglen mapsize eglsrf eglimg |
| 122 | // 0000000000000000 0000000000000000 8359936 23 --w--pY-- gpumem VK/others( 38) 0 0 0 0 |
| 123 | // 0000000000000000 0000000000000000 16293888 24 --wL--N-- ion surface 41 0 0 1 |
| 124 | |
| 125 | const bool dumpAll = dumpPid == 0; |
| 126 | static constexpr size_t kMaxLineLength = 1024; |
| 127 | static char line[kMaxLineLength]; |
| 128 | while(dirent* subdir = readdir(directory)) { |
| 129 | // Skip "." and ".." in directory. |
| 130 | if (strcmp(subdir->d_name, ".") == 0 || strcmp(subdir->d_name, "..") == 0 ) { continue; } |
| 131 | |
| 132 | std::string pid_str(subdir->d_name); |
| 133 | const uint32_t pid(stoi(pid_str)); |
| 134 | |
| 135 | if (!dumpAll && dumpPid != pid) { |
| 136 | continue; |
| 137 | } |
| 138 | |
| 139 | std::string filepath(kDirectoryPath + "/" + pid_str + "/mem"); |
| 140 | std::ifstream file(filepath); |
| 141 | |
| 142 | // Check first line |
| 143 | file.getline(line, kMaxLineLength); |
| 144 | if (!isExpectedFormat(line)) { |
| 145 | continue; |
| 146 | } |
| 147 | |
| 148 | if (result) { |
| 149 | StringAppendF(result, "%d:\n%s\n", pid, line); |
| 150 | } |
| 151 | |
| 152 | while( file.getline(line, kMaxLineLength) ) { |
| 153 | if (result) { |
| 154 | StringAppendF(result, "%s\n", line); |
| 155 | } |
| 156 | |
| 157 | std::istringstream iss; |
| 158 | iss.str(line); |
| 159 | |
| 160 | // Skip gpuaddr, useraddr. |
| 161 | const char delimiter = ' '; |
| 162 | iss >> std::ws; |
| 163 | iss.ignore(kMaxLineLength, delimiter); |
| 164 | iss >> std::ws; |
| 165 | iss.ignore(kMaxLineLength, delimiter); |
| 166 | |
| 167 | // Get size. |
| 168 | int64_t memsize; |
| 169 | iss >> memsize; |
| 170 | |
| 171 | // Skip id, flags. |
| 172 | iss >> std::ws; |
| 173 | iss.ignore(kMaxLineLength, delimiter); |
| 174 | iss >> std::ws; |
| 175 | iss.ignore(kMaxLineLength, delimiter); |
| 176 | |
| 177 | // Get type, usage. |
| 178 | std::string memtype; |
| 179 | std::string usage; |
| 180 | iss >> memtype >> usage; |
| 181 | |
| 182 | // Adjust for the space in VK/others( #) |
| 183 | if (usage == "VK/others(") { |
| 184 | std::string vkTypeEnd; |
| 185 | iss >> vkTypeEnd; |
| 186 | usage.append(vkTypeEnd); |
| 187 | } |
| 188 | |
| 189 | // Skip sglen. |
| 190 | iss >> std::ws; |
| 191 | iss.ignore(kMaxLineLength, delimiter); |
| 192 | |
| 193 | // Get mapsize. |
| 194 | int64_t mapsize; |
| 195 | iss >> mapsize; |
| 196 | |
| 197 | if (memsize == 0 && mapsize == 0) { |
| 198 | continue; |
| 199 | } |
| 200 | |
| 201 | if (memtype == "gpumem") { |
| 202 | (*memories)[pid][usage].gpuMemory += memsize; |
| 203 | } else { |
| 204 | (*memories)[pid][usage].ionMemory += memsize; |
| 205 | } |
| 206 | |
| 207 | if (mapsize > 0) { |
| 208 | (*memories)[pid][usage].mappedMemory += mapsize; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | if (result) { |
| 213 | StringAppendF(result, "\n"); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | closedir(directory); |
| 218 | |
| 219 | return OK; |
| 220 | } |
| 221 | |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 222 | status_t GpuService::shellCommand(int /*in*/, int out, int err, std::vector<String16>& args) { |
| 223 | ATRACE_CALL(); |
| 224 | |
| 225 | ALOGV("shellCommand"); |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 226 | for (size_t i = 0, n = args.size(); i < n; i++) |
| 227 | ALOGV(" arg[%zu]: '%s'", i, String8(args[i]).string()); |
| 228 | |
Jesse Hall | 3e26b13 | 2016-12-20 14:31:28 -0800 | [diff] [blame] | 229 | if (args.size() >= 1) { |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 230 | if (args[0] == String16("vkjson")) return cmdVkjson(out, err); |
| 231 | if (args[0] == String16("help")) return cmdHelp(out); |
Jesse Hall | 3e26b13 | 2016-12-20 14:31:28 -0800 | [diff] [blame] | 232 | } |
| 233 | // no command, or unrecognized command |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 234 | cmdHelp(err); |
Jesse Hall | 3e26b13 | 2016-12-20 14:31:28 -0800 | [diff] [blame] | 235 | return BAD_VALUE; |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 238 | status_t GpuService::doDump(int fd, const Vector<String16>& args, bool /*asProto*/) { |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 239 | std::string result; |
| 240 | |
| 241 | IPCThreadState* ipc = IPCThreadState::self(); |
| 242 | const int pid = ipc->getCallingPid(); |
| 243 | const int uid = ipc->getCallingUid(); |
| 244 | |
| 245 | if ((uid != AID_SHELL) && !PermissionCache::checkPermission(sDump, pid, uid)) { |
| 246 | StringAppendF(&result, "Permission Denial: can't dump gpu from pid=%d, uid=%d\n", pid, uid); |
| 247 | } else { |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 248 | bool dumpAll = true; |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 249 | bool dumpDriverInfo = false; |
| 250 | bool dumpStats = false; |
| 251 | bool dumpMemory = false; |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 252 | size_t numArgs = args.size(); |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 253 | int32_t pid = 0; |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 254 | |
| 255 | if (numArgs) { |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 256 | dumpAll = false; |
| 257 | for (size_t index = 0; index < numArgs; ++index) { |
| 258 | if (args[index] == String16("--gpustats")) { |
| 259 | dumpStats = true; |
| 260 | } else if (args[index] == String16("--gpudriverinfo")) { |
| 261 | dumpDriverInfo = true; |
| 262 | } else if (args[index] == String16("--gpumem")) { |
| 263 | dumpMemory = true; |
Peter Collingbourne | d09003d | 2019-08-20 10:31:18 -0700 | [diff] [blame] | 264 | } else if (args[index].startsWith(String16("--gpumem="))) { |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 265 | dumpMemory = true; |
| 266 | pid = atoi(String8(&args[index][9])); |
| 267 | } |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 271 | if (dumpAll || dumpDriverInfo) { |
Yiwei Zhang | 2a61c15 | 2019-02-27 11:27:18 -0800 | [diff] [blame] | 272 | dumpGameDriverInfo(&result); |
| 273 | result.append("\n"); |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 274 | } |
| 275 | if (dumpAll || dumpStats) { |
Yiwei Zhang | 8cf7c7b | 2019-08-28 13:07:30 -0700 | [diff] [blame^] | 276 | mGpuStats->dump(args, &result); |
Yiwei Zhang | 2a61c15 | 2019-02-27 11:27:18 -0800 | [diff] [blame] | 277 | result.append("\n"); |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 278 | } |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 279 | if (dumpAll || dumpMemory) { |
| 280 | GpuMemoryMap memories; |
| 281 | // Currently only queries Qualcomm gpu memory. More will be added later. |
| 282 | if (getQCommGpuMemoryInfo(&memories, &result, pid) == OK) { |
| 283 | dumpMemoryInfo(&result, memories, pid); |
| 284 | result.append("\n"); |
| 285 | } |
| 286 | } |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | write(fd, result.c_str(), result.size()); |
| 290 | return NO_ERROR; |
| 291 | } |
| 292 | |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 293 | namespace { |
| 294 | |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 295 | status_t cmdHelp(int out) { |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 296 | FILE* outs = fdopen(out, "w"); |
| 297 | if (!outs) { |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 298 | ALOGE("vkjson: failed to create out stream: %s (%d)", strerror(errno), errno); |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 299 | return BAD_VALUE; |
| 300 | } |
| 301 | fprintf(outs, |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 302 | "GPU Service commands:\n" |
| 303 | " vkjson dump Vulkan properties as JSON\n"); |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 304 | fclose(outs); |
| 305 | return NO_ERROR; |
| 306 | } |
| 307 | |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 308 | void vkjsonPrint(FILE* out) { |
| 309 | std::string json = VkJsonInstanceToJson(VkJsonGetInstance()); |
| 310 | fwrite(json.data(), 1, json.size(), out); |
| 311 | fputc('\n', out); |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 314 | status_t cmdVkjson(int out, int /*err*/) { |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 315 | FILE* outs = fdopen(out, "w"); |
| 316 | if (!outs) { |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 317 | int errnum = errno; |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 318 | ALOGE("vkjson: failed to create output stream: %s", strerror(errnum)); |
| 319 | return -errnum; |
| 320 | } |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 321 | vkjsonPrint(outs); |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 322 | fclose(outs); |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 323 | return NO_ERROR; |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Yiwei Zhang | 2a61c15 | 2019-02-27 11:27:18 -0800 | [diff] [blame] | 326 | void dumpGameDriverInfo(std::string* result) { |
| 327 | if (!result) return; |
| 328 | |
| 329 | char stableGameDriver[PROPERTY_VALUE_MAX] = {}; |
| 330 | property_get("ro.gfx.driver.0", stableGameDriver, "unsupported"); |
| 331 | StringAppendF(result, "Stable Game Driver: %s\n", stableGameDriver); |
| 332 | |
| 333 | char preReleaseGameDriver[PROPERTY_VALUE_MAX] = {}; |
| 334 | property_get("ro.gfx.driver.1", preReleaseGameDriver, "unsupported"); |
| 335 | StringAppendF(result, "Pre-release Game Driver: %s\n", preReleaseGameDriver); |
| 336 | } |
| 337 | |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 338 | // Read and print all memory info for each process from /d/kgsl/proc/<pid>/mem. |
| 339 | void dumpMemoryInfo(std::string* result, const GpuMemoryMap& memories, uint32_t pid) { |
| 340 | if (!result) return; |
| 341 | |
| 342 | // Write results. |
| 343 | StringAppendF(result, "GPU Memory Summary:\n"); |
| 344 | for(auto& mem : memories) { |
| 345 | uint32_t process = mem.first; |
| 346 | if (pid != 0 && pid != process) { |
| 347 | continue; |
| 348 | } |
| 349 | |
| 350 | StringAppendF(result, "%d:\n", process); |
| 351 | for(auto& memStruct : mem.second) { |
| 352 | StringAppendF(result, " %s", memStruct.first.c_str()); |
| 353 | |
| 354 | if(memStruct.second.gpuMemory > 0) |
| 355 | StringAppendF(result, ", GPU memory = %" PRId64, memStruct.second.gpuMemory); |
| 356 | if(memStruct.second.mappedMemory > 0) |
| 357 | StringAppendF(result, ", Mapped memory = %" PRId64, memStruct.second.mappedMemory); |
| 358 | if(memStruct.second.ionMemory > 0) |
| 359 | StringAppendF(result, ", Ion memory = %" PRId64, memStruct.second.ionMemory); |
| 360 | |
| 361 | StringAppendF(result, "\n"); |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 366 | } // anonymous namespace |
| 367 | |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 368 | } // namespace android |