Yiwei Zhang | f40fb10 | 2019-02-27 21:05:06 -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 | #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 | |
| 27 | 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 | return OK; |
| 38 | } |
| 39 | |
| 40 | status_t GpuStatsGlobalInfo::readFromParcel(const Parcel* parcel) { |
| 41 | status_t status; |
| 42 | if ((status = parcel->readUtf8FromUtf16(&driverPackageName)) != OK) return status; |
| 43 | if ((status = parcel->readUtf8FromUtf16(&driverVersionName)) != OK) return status; |
| 44 | if ((status = parcel->readUint64(&driverVersionCode)) != OK) return status; |
| 45 | if ((status = parcel->readInt64(&driverBuildTime)) != OK) return status; |
| 46 | if ((status = parcel->readInt32(&glLoadingCount)) != OK) return status; |
| 47 | if ((status = parcel->readInt32(&glLoadingFailureCount)) != OK) return status; |
| 48 | if ((status = parcel->readInt32(&vkLoadingCount)) != OK) return status; |
| 49 | if ((status = parcel->readInt32(&vkLoadingFailureCount)) != OK) return status; |
| 50 | return OK; |
| 51 | } |
| 52 | |
| 53 | std::string GpuStatsGlobalInfo::toString() const { |
| 54 | std::string result; |
| 55 | StringAppendF(&result, "driverPackageName = %s\n", driverPackageName.c_str()); |
| 56 | StringAppendF(&result, "driverVersionName = %s\n", driverVersionName.c_str()); |
| 57 | StringAppendF(&result, "driverVersionCode = %" PRIu64 "\n", driverVersionCode); |
| 58 | StringAppendF(&result, "driverBuildTime = %" PRId64 "\n", driverBuildTime); |
| 59 | StringAppendF(&result, "glLoadingCount = %d\n", glLoadingCount); |
| 60 | StringAppendF(&result, "glLoadingFailureCount = %d\n", glLoadingFailureCount); |
| 61 | StringAppendF(&result, "vkLoadingCount = %d\n", vkLoadingCount); |
| 62 | StringAppendF(&result, "vkLoadingFailureCount = %d\n", vkLoadingFailureCount); |
| 63 | return result; |
| 64 | } |
| 65 | |
| 66 | status_t GpuStatsAppInfo::writeToParcel(Parcel* parcel) const { |
| 67 | status_t status; |
| 68 | if ((status = parcel->writeUtf8AsUtf16(appPackageName)) != OK) return status; |
| 69 | if ((status = parcel->writeUint64(driverVersionCode)) != OK) return status; |
| 70 | if ((status = parcel->writeInt64Vector(glDriverLoadingTime)) != OK) return status; |
| 71 | if ((status = parcel->writeInt64Vector(vkDriverLoadingTime)) != OK) return status; |
| 72 | return OK; |
| 73 | } |
| 74 | |
| 75 | status_t GpuStatsAppInfo::readFromParcel(const Parcel* parcel) { |
| 76 | status_t status; |
| 77 | if ((status = parcel->readUtf8FromUtf16(&appPackageName)) != OK) return status; |
| 78 | if ((status = parcel->readUint64(&driverVersionCode)) != OK) return status; |
| 79 | if ((status = parcel->readInt64Vector(&glDriverLoadingTime)) != OK) return status; |
| 80 | if ((status = parcel->readInt64Vector(&vkDriverLoadingTime)) != OK) return status; |
| 81 | return OK; |
| 82 | } |
| 83 | |
| 84 | std::string GpuStatsAppInfo::toString() const { |
| 85 | std::string result; |
| 86 | StringAppendF(&result, "appPackageName = %s\n", appPackageName.c_str()); |
| 87 | StringAppendF(&result, "driverVersionCode = %" PRIu64 "\n", driverVersionCode); |
| 88 | result.append("glDriverLoadingTime:"); |
| 89 | for (int32_t loadingTime : glDriverLoadingTime) { |
| 90 | StringAppendF(&result, " %d", loadingTime); |
| 91 | } |
| 92 | result.append("\n"); |
| 93 | result.append("vkDriverLoadingTime:"); |
| 94 | for (int32_t loadingTime : vkDriverLoadingTime) { |
| 95 | StringAppendF(&result, " %d", loadingTime); |
| 96 | } |
| 97 | result.append("\n"); |
| 98 | return result; |
| 99 | } |
| 100 | |
| 101 | } // namespace android |