Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | #pragma once |
| 18 | |
| 19 | #include <mutex> |
| 20 | #include <unordered_map> |
| 21 | #include <vector> |
| 22 | |
Yiwei Zhang | f40fb10 | 2019-02-27 21:05:06 -0800 | [diff] [blame] | 23 | #include <graphicsenv/GpuStatsInfo.h> |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 24 | #include <graphicsenv/GraphicsEnv.h> |
| 25 | #include <utils/String16.h> |
| 26 | #include <utils/Vector.h> |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | class GpuStats { |
| 31 | public: |
| 32 | GpuStats() = default; |
| 33 | ~GpuStats() = default; |
| 34 | |
| 35 | // Insert new gpu stats into global stats and app stats. |
| 36 | void insert(const std::string& driverPackageName, const std::string& driverVersionName, |
| 37 | uint64_t driverVersionCode, int64_t driverBuildTime, |
Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 38 | const std::string& appPackageName, const int32_t vulkanVersion, |
| 39 | GraphicsEnv::Driver driver, bool isDriverLoaded, int64_t driverLoadingTime); |
Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 40 | // Set CPU Vulkan in use signal into app stats. |
| 41 | void setCpuVulkanInUse(const std::string& appPackageName, const uint64_t driverVersionCode); |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 42 | // dumpsys interface |
| 43 | void dump(const Vector<String16>& args, std::string* result); |
Yiwei Zhang | baea97f | 2019-02-27 16:35:37 -0800 | [diff] [blame] | 44 | // Pull gpu global stats |
| 45 | void pullGlobalStats(std::vector<GpuStatsGlobalInfo>* outStats); |
Yiwei Zhang | 178e067 | 2019-03-04 14:17:12 -0800 | [diff] [blame] | 46 | // Pull gpu app stats |
| 47 | void pullAppStats(std::vector<GpuStatsAppInfo>* outStats); |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 48 | |
Yiwei Zhang | f2d8413 | 2019-03-06 11:32:50 -0800 | [diff] [blame] | 49 | // This limits the worst case number of loading times tracked. |
| 50 | static const size_t MAX_NUM_LOADING_TIMES = 50; |
| 51 | |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 52 | private: |
| 53 | // Dump global stats |
| 54 | void dumpGlobalLocked(std::string* result); |
| 55 | // Dump app stats |
| 56 | void dumpAppLocked(std::string* result); |
Yiwei Zhang | 174a2a0 | 2019-05-06 19:08:31 -0700 | [diff] [blame] | 57 | // Append cpuVulkanVersion and glesVersion to system driver stats |
| 58 | void interceptSystemDriverStatsLocked(); |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 59 | |
Yiwei Zhang | f2d8413 | 2019-03-06 11:32:50 -0800 | [diff] [blame] | 60 | // Below limits the memory usage of GpuStats to be less than 10KB. This is |
| 61 | // the preferred number for statsd while maintaining nice data quality. |
| 62 | static const size_t MAX_NUM_APP_RECORDS = 100; |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 63 | // GpuStats access should be guarded by mLock. |
| 64 | std::mutex mLock; |
| 65 | // Key is driver version code. |
Yiwei Zhang | f40fb10 | 2019-02-27 21:05:06 -0800 | [diff] [blame] | 66 | std::unordered_map<uint64_t, GpuStatsGlobalInfo> mGlobalStats; |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 67 | // Key is <app package name>+<driver version code>. |
Yiwei Zhang | f40fb10 | 2019-02-27 21:05:06 -0800 | [diff] [blame] | 68 | std::unordered_map<std::string, GpuStatsAppInfo> mAppStats; |
Yiwei Zhang | 2d4c188 | 2019-02-24 22:28:08 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace android |