blob: 208a627f200bc109c148f0bde650026c42d8a7f9 [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
17#ifndef ANDROID_GPUSERVICE_H
18#define ANDROID_GPUSERVICE_H
19
20#include <binder/IInterface.h>
21#include <cutils/compiler.h>
Yiwei Zhangbaea97f2019-02-27 16:35:37 -080022#include <graphicsenv/GpuStatsInfo.h>
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080023#include <graphicsenv/IGpuService.h>
Yiwei Zhangbb4eaf62019-02-23 17:53:27 -080024#include <serviceutils/PriorityDumper.h>
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080025
26#include <mutex>
27#include <vector>
Mikael Pessa3d146052019-07-09 09:25:38 -070028#include <unordered_map>
Jesse Hallfc038bd2016-03-26 22:20:22 -070029
30namespace android {
31
Yiwei Zhang2d4c1882019-02-24 22:28:08 -080032class GpuStats;
33
Mikael Pessa3d146052019-07-09 09:25:38 -070034struct MemoryStruct {
35 int64_t gpuMemory;
36 int64_t mappedMemory;
37 int64_t ionMemory;
38};
39
40// A map that keeps track of how much memory of each type is allocated by every process.
41// Format: map[pid][memoryType] = MemoryStruct()'
42using GpuMemoryMap = std::unordered_map<int32_t, std::unordered_map<std::string, MemoryStruct>>;
43
Yiwei Zhangbb4eaf62019-02-23 17:53:27 -080044class GpuService : public BnGpuService, public PriorityDumper {
Jesse Hallfc038bd2016-03-26 22:20:22 -070045public:
46 static const char* const SERVICE_NAME ANDROID_API;
47
48 GpuService() ANDROID_API;
49
50protected:
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080051 status_t shellCommand(int in, int out, int err, std::vector<String16>& args) override;
52
53private:
Yiwei Zhangbb4eaf62019-02-23 17:53:27 -080054 /*
55 * IGpuService interface
56 */
Greg Kaiser210bb7e2019-02-12 12:40:05 -080057 void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName,
Yiwei Zhang96c01712019-02-19 16:00:25 -080058 uint64_t driverVersionCode, int64_t driverBuildTime,
Yiwei Zhang794d2952019-05-06 17:43:59 -070059 const std::string& appPackageName, const int32_t vulkanVersion,
Yiwei Zhang27ab3ac2019-07-02 18:10:55 -070060 GpuStatsInfo::Driver driver, bool isDriverLoaded,
Yiwei Zhang794d2952019-05-06 17:43:59 -070061 int64_t driverLoadingTime) override;
Yiwei Zhangbcba4112019-07-03 13:39:32 -070062 void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode,
63 const GpuStatsInfo::Stats stats, const uint64_t value) override;
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080064
Yiwei Zhangbb4eaf62019-02-23 17:53:27 -080065 /*
66 * IBinder interface
67 */
68 status_t dump(int fd, const Vector<String16>& args) override { return priorityDump(fd, args); }
69
70 /*
71 * Debugging & dumpsys
72 */
73 status_t dumpCritical(int fd, const Vector<String16>& /*args*/, bool asProto) override {
74 return doDump(fd, Vector<String16>(), asProto);
75 }
76
77 status_t dumpAll(int fd, const Vector<String16>& args, bool asProto) override {
78 return doDump(fd, args, asProto);
79 }
80
81 status_t doDump(int fd, const Vector<String16>& args, bool asProto);
82
Mikael Pessa3d146052019-07-09 09:25:38 -070083 status_t getQCommGpuMemoryInfo(GpuMemoryMap* memories, std::string* result, int32_t dumpPid) const;
84
Yiwei Zhangbb4eaf62019-02-23 17:53:27 -080085 /*
86 * Attributes
87 */
Yiwei Zhang2d4c1882019-02-24 22:28:08 -080088 std::unique_ptr<GpuStats> mGpuStats;
Jesse Hallfc038bd2016-03-26 22:20:22 -070089};
90
91} // namespace android
92
93#endif // ANDROID_GPUSERVICE_H