blob: ed56c49764fa960f5136281f325ca01f945d04a1 [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 Zhang96c01712019-02-19 16:00:25 -080042 int64_t driverBuildTime, const std::string& appPackageName,
Yiwei Zhang512a7232019-02-15 16:04:41 -080043 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"
Yiwei Zhang96c01712019-02-19 16:00:25 -080051 "\tdriverVersionCode[%" PRIu64 "]\n"
52 "\tdriverBuildTime[%" PRId64 "]\n"
Yiwei Zhangd9861812019-02-13 11:51:55 -080053 "\tappPackageName[%s]\n"
54 "\tdriver[%d]\n"
55 "\tisDriverLoaded[%d]\n"
Yiwei Zhang96c01712019-02-19 16:00:25 -080056 "\tdriverLoadingTime[%" PRId64 "]",
57 driverPackageName.c_str(), driverVersionName.c_str(), driverVersionCode, driverBuildTime,
58 appPackageName.c_str(), static_cast<int32_t>(driver), isDriverLoaded, driverLoadingTime);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080059}
60
61status_t GpuService::shellCommand(int /*in*/, int out, int err, std::vector<String16>& args) {
62 ATRACE_CALL();
63
64 ALOGV("shellCommand");
Jesse Hall8b0d55e2016-03-31 19:29:36 -070065 for (size_t i = 0, n = args.size(); i < n; i++)
66 ALOGV(" arg[%zu]: '%s'", i, String8(args[i]).string());
67
Jesse Hall3e26b132016-12-20 14:31:28 -080068 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 Hallfc038bd2016-03-26 22:20:22 -070077}
78
Jesse Hall8b0d55e2016-03-31 19:29:36 -070079namespace {
80
81status_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 Hall3841bf42016-06-12 15:08:28 -070090 " vkjson dump Vulkan properties as JSON\n");
Jesse Hall8b0d55e2016-03-31 19:29:36 -070091 fclose(outs);
92 return NO_ERROR;
93}
94
Jesse Hall3841bf42016-06-12 15:08:28 -070095void vkjsonPrint(FILE* out) {
96 std::string json = VkJsonInstanceToJson(VkJsonGetInstance());
97 fwrite(json.data(), 1, json.size(), out);
98 fputc('\n', out);
Jesse Hall8b0d55e2016-03-31 19:29:36 -070099}
100
Jesse Hall3841bf42016-06-12 15:08:28 -0700101status_t cmd_vkjson(int out, int /*err*/) {
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700102 FILE* outs = fdopen(out, "w");
103 if (!outs) {
Jesse Hall3841bf42016-06-12 15:08:28 -0700104 int errnum = errno;
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700105 ALOGE("vkjson: failed to create output stream: %s", strerror(errnum));
106 return -errnum;
107 }
Jesse Hall3841bf42016-06-12 15:08:28 -0700108 vkjsonPrint(outs);
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700109 fclose(outs);
Jesse Hall3841bf42016-06-12 15:08:28 -0700110 return NO_ERROR;
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700111}
112
113} // anonymous namespace
114
Jesse Hallfc038bd2016-03-26 22:20:22 -0700115} // namespace android