summaryrefslogtreecommitdiff
path: root/services/gpuservice/GpuService.h
blob: b3dc2e27188c6453fe158fd4a97c0d6a8aaa2889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * Copyright 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_GPUSERVICE_H
#define ANDROID_GPUSERVICE_H

#include <binder/IInterface.h>
#include <cutils/compiler.h>
#include <graphicsenv/GpuStatsInfo.h>
#include <graphicsenv/IGpuService.h>
#include <serviceutils/PriorityDumper.h>

#include <mutex>
#include <vector>
#include <unordered_map>

namespace android {

class GpuStats;

struct MemoryStruct {
  int64_t gpuMemory;
  int64_t mappedMemory;
  int64_t ionMemory;
};

// A map that keeps track of how much memory of each type is allocated by every process.
// Format: map[pid][memoryType] = MemoryStruct()'
using GpuMemoryMap = std::unordered_map<int32_t, std::unordered_map<std::string, MemoryStruct>>;

class GpuService : public BnGpuService, public PriorityDumper {
public:
    static const char* const SERVICE_NAME ANDROID_API;

    GpuService() ANDROID_API;

protected:
    status_t shellCommand(int in, int out, int err, std::vector<String16>& args) override;

private:
    /*
     * IGpuService interface
     */
    void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName,
                     uint64_t driverVersionCode, int64_t driverBuildTime,
                     const std::string& appPackageName, const int32_t vulkanVersion,
                     GpuStatsInfo::Driver driver, bool isDriverLoaded,
                     int64_t driverLoadingTime) override;
    status_t getGpuStatsGlobalInfo(std::vector<GpuStatsGlobalInfo>* outStats) const override;
    status_t getGpuStatsAppInfo(std::vector<GpuStatsAppInfo>* outStats) const override;
    void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode,
                        const GpuStatsInfo::Stats stats, const uint64_t value) override;

    /*
     * IBinder interface
     */
    status_t dump(int fd, const Vector<String16>& args) override { return priorityDump(fd, args); }

    /*
     * Debugging & dumpsys
     */
    status_t dumpCritical(int fd, const Vector<String16>& /*args*/, bool asProto) override {
        return doDump(fd, Vector<String16>(), asProto);
    }

    status_t dumpAll(int fd, const Vector<String16>& args, bool asProto) override {
        return doDump(fd, args, asProto);
    }

    status_t doDump(int fd, const Vector<String16>& args, bool asProto);

    status_t getQCommGpuMemoryInfo(GpuMemoryMap* memories, std::string* result, int32_t dumpPid) const;

    /*
     * Attributes
     */
    std::unique_ptr<GpuStats> mGpuStats;
};

} // namespace android

#endif // ANDROID_GPUSERVICE_H