blob: 81b70c092f414d3b9e78a0ce1f113a1bfd28151e [file] [log] [blame]
Jesse Hallfc038bd2016-03-26 22:20:22 -07001/*
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 Zhangcb9d4e42019-02-06 20:22:59 -080017#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18
Jesse Hallfc038bd2016-03-26 22:20:22 -070019#include "GpuService.h"
20
Jesse Hallc0b15772016-12-20 14:47:45 -080021#include <binder/IResultReceiver.h>
Jesse Hallfc038bd2016-03-26 22:20:22 -070022#include <binder/Parcel.h>
Jesse Hall8b0d55e2016-03-31 19:29:36 -070023#include <utils/String8.h>
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080024#include <utils/Trace.h>
25
Jesse Hall8b0d55e2016-03-31 19:29:36 -070026#include <vkjson.h>
Jesse Hallfc038bd2016-03-26 22:20:22 -070027
28namespace android {
29
Jesse Hallfc038bd2016-03-26 22:20:22 -070030
Jesse Hall8b0d55e2016-03-31 19:29:36 -070031namespace {
32 status_t cmd_help(int out);
33 status_t cmd_vkjson(int out, int err);
34}
35
Yiwei Zhang423d0802018-11-16 10:56:12 -080036const char* const GpuService::SERVICE_NAME = "gpu";
Jesse Hallfc038bd2016-03-26 22:20:22 -070037
Peiyong Lin2da74652018-11-01 10:34:57 -070038GpuService::GpuService() = default;
Jesse Hallfc038bd2016-03-26 22:20:22 -070039
Greg Kaiser210bb7e2019-02-12 12:40:05 -080040void GpuService::setGpuStats(const std::string& driverPackageName,
Yiwei Zhangd9861812019-02-13 11:51:55 -080041 const std::string& driverVersionName, uint64_t driverVersionCode,
Yiwei Zhang512a7232019-02-15 16:04:41 -080042 const std::string& driverBuildDate, const std::string& appPackageName,
43 GraphicsEnv::Driver driver, bool isDriverLoaded,
44 int64_t driverLoadingTime) {
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080045 ATRACE_CALL();
46
47 std::lock_guard<std::mutex> lock(mStateLock);
48 ALOGV("Received:\n"
49 "\tdriverPackageName[%s]\n"
50 "\tdriverVersionName[%s]\n"
51 "\tdriverVersionCode[%llu]\n"
Yiwei Zhang512a7232019-02-15 16:04:41 -080052 "\tdriverBuildDate[%s]\n"
Yiwei Zhangd9861812019-02-13 11:51:55 -080053 "\tappPackageName[%s]\n"
54 "\tdriver[%d]\n"
55 "\tisDriverLoaded[%d]\n"
56 "\tdriverLoadingTime[%lld]",
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080057 driverPackageName.c_str(), driverVersionName.c_str(),
Yiwei Zhang512a7232019-02-15 16:04:41 -080058 (unsigned long long)driverVersionCode, driverBuildDate.c_str(), appPackageName.c_str(),
Yiwei Zhangd9861812019-02-13 11:51:55 -080059 static_cast<int32_t>(driver), isDriverLoaded, (long long)driverLoadingTime);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080060}
61
62status_t GpuService::shellCommand(int /*in*/, int out, int err, std::vector<String16>& args) {
63 ATRACE_CALL();
64
65 ALOGV("shellCommand");
Jesse Hall8b0d55e2016-03-31 19:29:36 -070066 for (size_t i = 0, n = args.size(); i < n; i++)
67 ALOGV(" arg[%zu]: '%s'", i, String8(args[i]).string());
68
Jesse Hall3e26b132016-12-20 14:31:28 -080069 if (args.size() >= 1) {
70 if (args[0] == String16("vkjson"))
71 return cmd_vkjson(out, err);
72 if (args[0] == String16("help"))
73 return cmd_help(out);
74 }
75 // no command, or unrecognized command
76 cmd_help(err);
77 return BAD_VALUE;
Jesse Hallfc038bd2016-03-26 22:20:22 -070078}
79
Jesse Hall8b0d55e2016-03-31 19:29:36 -070080namespace {
81
82status_t cmd_help(int out) {
83 FILE* outs = fdopen(out, "w");
84 if (!outs) {
85 ALOGE("vkjson: failed to create out stream: %s (%d)", strerror(errno),
86 errno);
87 return BAD_VALUE;
88 }
89 fprintf(outs,
90 "GPU Service commands:\n"
Jesse Hall3841bf42016-06-12 15:08:28 -070091 " vkjson dump Vulkan properties as JSON\n");
Jesse Hall8b0d55e2016-03-31 19:29:36 -070092 fclose(outs);
93 return NO_ERROR;
94}
95
Jesse Hall3841bf42016-06-12 15:08:28 -070096void vkjsonPrint(FILE* out) {
97 std::string json = VkJsonInstanceToJson(VkJsonGetInstance());
98 fwrite(json.data(), 1, json.size(), out);
99 fputc('\n', out);
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700100}
101
Jesse Hall3841bf42016-06-12 15:08:28 -0700102status_t cmd_vkjson(int out, int /*err*/) {
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700103 FILE* outs = fdopen(out, "w");
104 if (!outs) {
Jesse Hall3841bf42016-06-12 15:08:28 -0700105 int errnum = errno;
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700106 ALOGE("vkjson: failed to create output stream: %s", strerror(errnum));
107 return -errnum;
108 }
Jesse Hall3841bf42016-06-12 15:08:28 -0700109 vkjsonPrint(outs);
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700110 fclose(outs);
Jesse Hall3841bf42016-06-12 15:08:28 -0700111 return NO_ERROR;
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700112}
113
114} // anonymous namespace
115
Jesse Hallfc038bd2016-03-26 22:20:22 -0700116} // namespace android