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 #include <inttypes.h>
18 
19 #include <android-base/stringprintf.h>
20 #include <binder/Parcel.h>
21 #include <graphicsenv/GpuStatsInfo.h>
22 
23 namespace android {
24 
25 using base::StringAppendF;
26 
writeToParcel(Parcel * parcel) const27 status_t GpuStatsGlobalInfo::writeToParcel(Parcel* parcel) const {
28     status_t status;
29     if ((status = parcel->writeUtf8AsUtf16(driverPackageName)) != OK) return status;
30     if ((status = parcel->writeUtf8AsUtf16(driverVersionName)) != OK) return status;
31     if ((status = parcel->writeUint64(driverVersionCode)) != OK) return status;
32     if ((status = parcel->writeInt64(driverBuildTime)) != OK) return status;
33     if ((status = parcel->writeInt32(glLoadingCount)) != OK) return status;
34     if ((status = parcel->writeInt32(glLoadingFailureCount)) != OK) return status;
35     if ((status = parcel->writeInt32(vkLoadingCount)) != OK) return status;
36     if ((status = parcel->writeInt32(vkLoadingFailureCount)) != OK) return status;
37     if ((status = parcel->writeInt32(vulkanVersion)) != OK) return status;
38     if ((status = parcel->writeInt32(cpuVulkanVersion)) != OK) return status;
39     if ((status = parcel->writeInt32(glesVersion)) != OK) return status;
40     if ((status = parcel->writeInt32(angleLoadingCount)) != OK) return status;
41     if ((status = parcel->writeInt32(angleLoadingFailureCount)) != OK) return status;
42     return OK;
43 }
44 
readFromParcel(const Parcel * parcel)45 status_t GpuStatsGlobalInfo::readFromParcel(const Parcel* parcel) {
46     status_t status;
47     if ((status = parcel->readUtf8FromUtf16(&driverPackageName)) != OK) return status;
48     if ((status = parcel->readUtf8FromUtf16(&driverVersionName)) != OK) return status;
49     if ((status = parcel->readUint64(&driverVersionCode)) != OK) return status;
50     if ((status = parcel->readInt64(&driverBuildTime)) != OK) return status;
51     if ((status = parcel->readInt32(&glLoadingCount)) != OK) return status;
52     if ((status = parcel->readInt32(&glLoadingFailureCount)) != OK) return status;
53     if ((status = parcel->readInt32(&vkLoadingCount)) != OK) return status;
54     if ((status = parcel->readInt32(&vkLoadingFailureCount)) != OK) return status;
55     if ((status = parcel->readInt32(&vulkanVersion)) != OK) return status;
56     if ((status = parcel->readInt32(&cpuVulkanVersion)) != OK) return status;
57     if ((status = parcel->readInt32(&glesVersion)) != OK) return status;
58     if ((status = parcel->readInt32(&angleLoadingCount)) != OK) return status;
59     if ((status = parcel->readInt32(&angleLoadingFailureCount)) != OK) return status;
60     return OK;
61 }
62 
toString() const63 std::string GpuStatsGlobalInfo::toString() const {
64     std::string result;
65     StringAppendF(&result, "driverPackageName = %s\n", driverPackageName.c_str());
66     StringAppendF(&result, "driverVersionName = %s\n", driverVersionName.c_str());
67     StringAppendF(&result, "driverVersionCode = %" PRIu64 "\n", driverVersionCode);
68     StringAppendF(&result, "driverBuildTime = %" PRId64 "\n", driverBuildTime);
69     StringAppendF(&result, "glLoadingCount = %d\n", glLoadingCount);
70     StringAppendF(&result, "glLoadingFailureCount = %d\n", glLoadingFailureCount);
71     StringAppendF(&result, "angleLoadingCount = %d\n", angleLoadingCount);
72     StringAppendF(&result, "angleLoadingFailureCount = %d\n", angleLoadingFailureCount);
73     StringAppendF(&result, "vkLoadingCount = %d\n", vkLoadingCount);
74     StringAppendF(&result, "vkLoadingFailureCount = %d\n", vkLoadingFailureCount);
75     StringAppendF(&result, "vulkanVersion = %d\n", vulkanVersion);
76     StringAppendF(&result, "cpuVulkanVersion = %d\n", cpuVulkanVersion);
77     StringAppendF(&result, "glesVersion = %d\n", glesVersion);
78     return result;
79 }
80 
writeToParcel(Parcel * parcel) const81 status_t GpuStatsAppInfo::writeToParcel(Parcel* parcel) const {
82     status_t status;
83     if ((status = parcel->writeUtf8AsUtf16(appPackageName)) != OK) return status;
84     if ((status = parcel->writeUint64(driverVersionCode)) != OK) return status;
85     if ((status = parcel->writeInt64Vector(glDriverLoadingTime)) != OK) return status;
86     if ((status = parcel->writeInt64Vector(vkDriverLoadingTime)) != OK) return status;
87     if ((status = parcel->writeInt64Vector(angleDriverLoadingTime)) != OK) return status;
88     if ((status = parcel->writeBool(cpuVulkanInUse)) != OK) return status;
89     return OK;
90 }
91 
readFromParcel(const Parcel * parcel)92 status_t GpuStatsAppInfo::readFromParcel(const Parcel* parcel) {
93     status_t status;
94     if ((status = parcel->readUtf8FromUtf16(&appPackageName)) != OK) return status;
95     if ((status = parcel->readUint64(&driverVersionCode)) != OK) return status;
96     if ((status = parcel->readInt64Vector(&glDriverLoadingTime)) != OK) return status;
97     if ((status = parcel->readInt64Vector(&vkDriverLoadingTime)) != OK) return status;
98     if ((status = parcel->readInt64Vector(&angleDriverLoadingTime)) != OK) return status;
99     if ((status = parcel->readBool(&cpuVulkanInUse)) != OK) return status;
100     return OK;
101 }
102 
toString() const103 std::string GpuStatsAppInfo::toString() const {
104     std::string result;
105     StringAppendF(&result, "appPackageName = %s\n", appPackageName.c_str());
106     StringAppendF(&result, "driverVersionCode = %" PRIu64 "\n", driverVersionCode);
107     StringAppendF(&result, "cpuVulkanInUse = %d\n", cpuVulkanInUse);
108     result.append("glDriverLoadingTime:");
109     for (int32_t loadingTime : glDriverLoadingTime) {
110         StringAppendF(&result, " %d", loadingTime);
111     }
112     result.append("\n");
113     result.append("angleDriverLoadingTime:");
114     for (int32_t loadingTime : angleDriverLoadingTime) {
115         StringAppendF(&result, " %d", loadingTime);
116     }
117     result.append("\n");
118     result.append("vkDriverLoadingTime:");
119     for (int32_t loadingTime : vkDriverLoadingTime) {
120         StringAppendF(&result, " %d", loadingTime);
121     }
122     result.append("\n");
123     return result;
124 }
125 
126 } // namespace android
127