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 | |
Jesse Hall | c0b1577 | 2016-12-20 14:47:45 -0800 | [diff] [blame] | 21 | #include <binder/IResultReceiver.h> |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 22 | #include <binder/Parcel.h> |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 23 | #include <utils/String8.h> |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 24 | #include <utils/Trace.h> |
| 25 | |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 26 | #include <vkjson.h> |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 30 | |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 31 | namespace { |
| 32 | status_t cmd_help(int out); |
| 33 | status_t cmd_vkjson(int out, int err); |
| 34 | } |
| 35 | |
Yiwei Zhang | 423d080 | 2018-11-16 10:56:12 -0800 | [diff] [blame] | 36 | const char* const GpuService::SERVICE_NAME = "gpu"; |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 37 | |
Peiyong Lin | 2da7465 | 2018-11-01 10:34:57 -0700 | [diff] [blame] | 38 | GpuService::GpuService() = default; |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 39 | |
Greg Kaiser | 210bb7e | 2019-02-12 12:40:05 -0800 | [diff] [blame] | 40 | void GpuService::setGpuStats(const std::string& driverPackageName, |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 41 | const std::string& driverVersionName, uint64_t driverVersionCode, |
Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame^] | 42 | int64_t driverBuildTime, const std::string& appPackageName, |
Yiwei Zhang | 512a723 | 2019-02-15 16:04:41 -0800 | [diff] [blame] | 43 | GraphicsEnv::Driver driver, bool isDriverLoaded, |
| 44 | int64_t driverLoadingTime) { |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 45 | ATRACE_CALL(); |
| 46 | |
| 47 | std::lock_guard<std::mutex> lock(mStateLock); |
| 48 | ALOGV("Received:\n" |
| 49 | "\tdriverPackageName[%s]\n" |
| 50 | "\tdriverVersionName[%s]\n" |
Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame^] | 51 | "\tdriverVersionCode[%" PRIu64 "]\n" |
| 52 | "\tdriverBuildTime[%" PRId64 "]\n" |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 53 | "\tappPackageName[%s]\n" |
| 54 | "\tdriver[%d]\n" |
| 55 | "\tisDriverLoaded[%d]\n" |
Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame^] | 56 | "\tdriverLoadingTime[%" PRId64 "]", |
| 57 | driverPackageName.c_str(), driverVersionName.c_str(), driverVersionCode, driverBuildTime, |
| 58 | appPackageName.c_str(), static_cast<int32_t>(driver), isDriverLoaded, driverLoadingTime); |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | status_t GpuService::shellCommand(int /*in*/, int out, int err, std::vector<String16>& args) { |
| 62 | ATRACE_CALL(); |
| 63 | |
| 64 | ALOGV("shellCommand"); |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 65 | for (size_t i = 0, n = args.size(); i < n; i++) |
| 66 | ALOGV(" arg[%zu]: '%s'", i, String8(args[i]).string()); |
| 67 | |
Jesse Hall | 3e26b13 | 2016-12-20 14:31:28 -0800 | [diff] [blame] | 68 | if (args.size() >= 1) { |
| 69 | if (args[0] == String16("vkjson")) |
| 70 | return cmd_vkjson(out, err); |
| 71 | if (args[0] == String16("help")) |
| 72 | return cmd_help(out); |
| 73 | } |
| 74 | // no command, or unrecognized command |
| 75 | cmd_help(err); |
| 76 | return BAD_VALUE; |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 79 | namespace { |
| 80 | |
| 81 | status_t cmd_help(int out) { |
| 82 | FILE* outs = fdopen(out, "w"); |
| 83 | if (!outs) { |
| 84 | ALOGE("vkjson: failed to create out stream: %s (%d)", strerror(errno), |
| 85 | errno); |
| 86 | return BAD_VALUE; |
| 87 | } |
| 88 | fprintf(outs, |
| 89 | "GPU Service commands:\n" |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 90 | " vkjson dump Vulkan properties as JSON\n"); |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 91 | fclose(outs); |
| 92 | return NO_ERROR; |
| 93 | } |
| 94 | |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 95 | void vkjsonPrint(FILE* out) { |
| 96 | std::string json = VkJsonInstanceToJson(VkJsonGetInstance()); |
| 97 | fwrite(json.data(), 1, json.size(), out); |
| 98 | fputc('\n', out); |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 101 | status_t cmd_vkjson(int out, int /*err*/) { |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 102 | FILE* outs = fdopen(out, "w"); |
| 103 | if (!outs) { |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 104 | int errnum = errno; |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 105 | ALOGE("vkjson: failed to create output stream: %s", strerror(errnum)); |
| 106 | return -errnum; |
| 107 | } |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 108 | vkjsonPrint(outs); |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 109 | fclose(outs); |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 110 | return NO_ERROR; |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | } // anonymous namespace |
| 114 | |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 115 | } // namespace android |