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 | |
| 17 | #ifndef ANDROID_GPUSERVICE_H |
| 18 | #define ANDROID_GPUSERVICE_H |
| 19 | |
| 20 | #include <binder/IInterface.h> |
| 21 | #include <cutils/compiler.h> |
Yiwei Zhang | baea97f | 2019-02-27 16:35:37 -0800 | [diff] [blame] | 22 | #include <graphicsenv/GpuStatsInfo.h> |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 23 | #include <graphicsenv/IGpuService.h> |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 24 | #include <serviceutils/PriorityDumper.h> |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 25 | |
| 26 | #include <mutex> |
| 27 | #include <vector> |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 28 | #include <unordered_map> |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 32 | class GpuStats; |
| 33 | |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 34 | struct 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()' |
| 42 | using GpuMemoryMap = std::unordered_map<int32_t, std::unordered_map<std::string, MemoryStruct>>; |
| 43 | |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 44 | class GpuService : public BnGpuService, public PriorityDumper { |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 45 | public: |
| 46 | static const char* const SERVICE_NAME ANDROID_API; |
| 47 | |
| 48 | GpuService() ANDROID_API; |
| 49 | |
| 50 | protected: |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 51 | status_t shellCommand(int in, int out, int err, std::vector<String16>& args) override; |
| 52 | |
| 53 | private: |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 54 | /* |
| 55 | * IGpuService interface |
| 56 | */ |
Greg Kaiser | 210bb7e | 2019-02-12 12:40:05 -0800 | [diff] [blame] | 57 | void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName, |
Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 58 | uint64_t driverVersionCode, int64_t driverBuildTime, |
Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 59 | const std::string& appPackageName, const int32_t vulkanVersion, |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 60 | GpuStatsInfo::Driver driver, bool isDriverLoaded, |
Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 61 | int64_t driverLoadingTime) override; |
Yiwei Zhang | baea97f | 2019-02-27 16:35:37 -0800 | [diff] [blame] | 62 | status_t getGpuStatsGlobalInfo(std::vector<GpuStatsGlobalInfo>* outStats) const override; |
Yiwei Zhang | 178e067 | 2019-03-04 14:17:12 -0800 | [diff] [blame] | 63 | status_t getGpuStatsAppInfo(std::vector<GpuStatsAppInfo>* outStats) const override; |
Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 64 | void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, |
| 65 | const GpuStatsInfo::Stats stats, const uint64_t value) override; |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 66 | |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 67 | /* |
| 68 | * IBinder interface |
| 69 | */ |
| 70 | status_t dump(int fd, const Vector<String16>& args) override { return priorityDump(fd, args); } |
| 71 | |
| 72 | /* |
| 73 | * Debugging & dumpsys |
| 74 | */ |
| 75 | status_t dumpCritical(int fd, const Vector<String16>& /*args*/, bool asProto) override { |
| 76 | return doDump(fd, Vector<String16>(), asProto); |
| 77 | } |
| 78 | |
| 79 | status_t dumpAll(int fd, const Vector<String16>& args, bool asProto) override { |
| 80 | return doDump(fd, args, asProto); |
| 81 | } |
| 82 | |
| 83 | status_t doDump(int fd, const Vector<String16>& args, bool asProto); |
| 84 | |
Mikael Pessa | 3d14605 | 2019-07-09 09:25:38 -0700 | [diff] [blame] | 85 | status_t getQCommGpuMemoryInfo(GpuMemoryMap* memories, std::string* result, int32_t dumpPid) const; |
| 86 | |
Yiwei Zhang | bb4eaf6 | 2019-02-23 17:53:27 -0800 | [diff] [blame] | 87 | /* |
| 88 | * Attributes |
| 89 | */ |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 90 | std::unique_ptr<GpuStats> mGpuStats; |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | } // namespace android |
| 94 | |
| 95 | #endif // ANDROID_GPUSERVICE_H |