blob: 68c185c11900aa88397077c09f2931ee3ddd4e99 [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,
41 const std::string& driverVersionName, const uint64_t driverVersionCode,
42 const std::string& appPackageName) {
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080043 ATRACE_CALL();
44
45 std::lock_guard<std::mutex> lock(mStateLock);
46 ALOGV("Received:\n"
47 "\tdriverPackageName[%s]\n"
48 "\tdriverVersionName[%s]\n"
49 "\tdriverVersionCode[%llu]\n"
50 "\tappPackageName[%s]\n",
51 driverPackageName.c_str(), driverVersionName.c_str(),
52 (unsigned long long)driverVersionCode, appPackageName.c_str());
53}
54
55status_t GpuService::shellCommand(int /*in*/, int out, int err, std::vector<String16>& args) {
56 ATRACE_CALL();
57
58 ALOGV("shellCommand");
Jesse Hall8b0d55e2016-03-31 19:29:36 -070059 for (size_t i = 0, n = args.size(); i < n; i++)
60 ALOGV(" arg[%zu]: '%s'", i, String8(args[i]).string());
61
Jesse Hall3e26b132016-12-20 14:31:28 -080062 if (args.size() >= 1) {
63 if (args[0] == String16("vkjson"))
64 return cmd_vkjson(out, err);
65 if (args[0] == String16("help"))
66 return cmd_help(out);
67 }
68 // no command, or unrecognized command
69 cmd_help(err);
70 return BAD_VALUE;
Jesse Hallfc038bd2016-03-26 22:20:22 -070071}
72
Jesse Hall8b0d55e2016-03-31 19:29:36 -070073namespace {
74
75status_t cmd_help(int out) {
76 FILE* outs = fdopen(out, "w");
77 if (!outs) {
78 ALOGE("vkjson: failed to create out stream: %s (%d)", strerror(errno),
79 errno);
80 return BAD_VALUE;
81 }
82 fprintf(outs,
83 "GPU Service commands:\n"
Jesse Hall3841bf42016-06-12 15:08:28 -070084 " vkjson dump Vulkan properties as JSON\n");
Jesse Hall8b0d55e2016-03-31 19:29:36 -070085 fclose(outs);
86 return NO_ERROR;
87}
88
Jesse Hall3841bf42016-06-12 15:08:28 -070089void vkjsonPrint(FILE* out) {
90 std::string json = VkJsonInstanceToJson(VkJsonGetInstance());
91 fwrite(json.data(), 1, json.size(), out);
92 fputc('\n', out);
Jesse Hall8b0d55e2016-03-31 19:29:36 -070093}
94
Jesse Hall3841bf42016-06-12 15:08:28 -070095status_t cmd_vkjson(int out, int /*err*/) {
Jesse Hall8b0d55e2016-03-31 19:29:36 -070096 FILE* outs = fdopen(out, "w");
97 if (!outs) {
Jesse Hall3841bf42016-06-12 15:08:28 -070098 int errnum = errno;
Jesse Hall8b0d55e2016-03-31 19:29:36 -070099 ALOGE("vkjson: failed to create output stream: %s", strerror(errnum));
100 return -errnum;
101 }
Jesse Hall3841bf42016-06-12 15:08:28 -0700102 vkjsonPrint(outs);
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700103 fclose(outs);
Jesse Hall3841bf42016-06-12 15:08:28 -0700104 return NO_ERROR;
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700105}
106
107} // anonymous namespace
108
Jesse Hallfc038bd2016-03-26 22:20:22 -0700109} // namespace android