blob: 8837c39e8e9791b0f857109e800dee0d3c3cd258 [file] [log] [blame]
Yiwei Zhang2d4c1882019-02-24 22:28:08 -08001/*
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
23#include <graphicsenv/GpuStatsAtoms.h>
24#include <graphicsenv/GraphicsEnv.h>
25#include <utils/String16.h>
26#include <utils/Vector.h>
27
28namespace android {
29
30class GpuStats {
31public:
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,
38 const std::string& appPackageName, GraphicsEnv::Driver driver, bool isDriverLoaded,
39 int64_t driverLoadingTime);
40 // dumpsys interface
41 void dump(const Vector<String16>& args, std::string* result);
42
43private:
44 // Dump global stats
45 void dumpGlobalLocked(std::string* result);
46 // Dump app stats
47 void dumpAppLocked(std::string* result);
48
49 // This limits the memory usage of GpuStats to be less than 30KB. This is
50 // the maximum atom size statsd could afford.
51 static const size_t MAX_NUM_APP_RECORDS = 300;
52 // GpuStats access should be guarded by mLock.
53 std::mutex mLock;
54 // Key is driver version code.
55 std::unordered_map<uint64_t, GpuStatsGlobalAtom> mGlobalStats;
56 // Key is <app package name>+<driver version code>.
57 std::unordered_map<std::string, GpuStatsAppAtom> mAppStats;
58};
59
60} // namespace android