• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2023 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 <aidl/android/hardware/power/SessionMode.h>
20 #include <android-base/stringprintf.h>
21 
22 #include <string>
23 
24 #include "AdpfTypes.h"
25 
26 namespace aidl {
27 namespace google {
28 namespace hardware {
29 namespace power {
30 namespace impl {
31 namespace pixel {
32 
33 template <class T>
enum_size()34 constexpr size_t enum_size() {
35     return static_cast<size_t>(*(ndk::enum_range<T>().end() - 1)) + 1;
36 }
37 
38 // The App Hint Descriptor struct manages information necessary
39 // to calculate the next uclamp min value from the PID function
40 // and is separate so that it can be used as a pointer for
41 // easily passing to the pid function
42 struct AppDescriptorTrace {
AppDescriptorTraceAppDescriptorTrace43     AppDescriptorTrace(const std::string &idString) {
44         using ::android::base::StringPrintf;
45         trace_pid_err = StringPrintf("adpf.%s-%s", idString.c_str(), "pid.err");
46         trace_pid_integral = StringPrintf("adpf.%s-%s", idString.c_str(), "pid.integral");
47         trace_pid_derivative = StringPrintf("adpf.%s-%s", idString.c_str(), "pid.derivative");
48         trace_pid_pOut = StringPrintf("adpf.%s-%s", idString.c_str(), "pid.pOut");
49         trace_pid_iOut = StringPrintf("adpf.%s-%s", idString.c_str(), "pid.iOut");
50         trace_pid_dOut = StringPrintf("adpf.%s-%s", idString.c_str(), "pid.dOut");
51         trace_pid_output = StringPrintf("adpf.%s-%s", idString.c_str(), "pid.output");
52         trace_target = StringPrintf("adpf.%s-%s", idString.c_str(), "target");
53         trace_active = StringPrintf("adpf.%s-%s", idString.c_str(), "active");
54         trace_add_threads = StringPrintf("adpf.%s-%s", idString.c_str(), "add_threads");
55         trace_actl_last = StringPrintf("adpf.%s-%s", idString.c_str(), "act_last");
56         trace_min = StringPrintf("adpf.%s-%s", idString.c_str(), "min");
57         trace_batch_size = StringPrintf("adpf.%s-%s", idString.c_str(), "batch_size");
58         trace_hint_count = StringPrintf("adpf.%s-%s", idString.c_str(), "hint_count");
59         trace_hint_overtime = StringPrintf("adpf.%s-%s", idString.c_str(), "hint_overtime");
60         trace_is_first_frame = StringPrintf("adpf.%s-%s", idString.c_str(), "is_first_frame");
61         // traces for heuristic boost
62         trace_avg_duration = StringPrintf("adpf.%s-%s", idString.c_str(), "hboost.avgDuration");
63         trace_heuristic_boost_active =
64                 StringPrintf("adpf.%s-%s", idString.c_str(), "hboost.isActive");
65         trace_low_frame_rate =
66                 StringPrintf("adpf.%s-%s", idString.c_str(), "hboost.isLowFrameRate");
67         trace_max_duration = StringPrintf("adpf.%s-%s", idString.c_str(), "hboost.maxDuration");
68         trace_missed_cycles =
69                 StringPrintf("adpf.%s-%s", idString.c_str(), "hboost.numOfMissedCycles");
70         for (size_t i = 0; i < trace_modes.size(); ++i) {
71             trace_modes[i] = StringPrintf(
72                     "adpf.%s-%s_mode", idString.c_str(),
73                     toString(static_cast<aidl::android::hardware::power::SessionMode>(i)).c_str());
74         }
75         for (size_t i = 0; i < trace_votes.size(); ++i) {
76             trace_votes[i] = StringPrintf("adpf.%s-vote.%s", idString.c_str(),
77                                           AdpfVoteTypeToStr(static_cast<AdpfVoteType>(i)));
78         }
79         trace_cpu_duration = StringPrintf("adpf.%s-%s", idString.c_str(), "cpu_duration");
80         trace_gpu_duration = StringPrintf("adpf.%s-%s", idString.c_str(), "gpu_duration");
81         trace_gpu_capacity = StringPrintf("adpf.%s-%s", idString.c_str(), "gpu_capacity");
82     }
83 
84     // Trace values
85     std::string trace_pid_err;
86     std::string trace_pid_integral;
87     std::string trace_pid_derivative;
88     std::string trace_pid_pOut;
89     std::string trace_pid_iOut;
90     std::string trace_pid_dOut;
91     std::string trace_pid_output;
92     std::string trace_target;
93     std::string trace_active;
94     std::string trace_add_threads;
95     std::string trace_actl_last;
96     std::string trace_min;
97     std::string trace_batch_size;
98     std::string trace_hint_count;
99     std::string trace_hint_overtime;
100     std::string trace_is_first_frame;
101     // traces for heuristic boost
102     std::string trace_avg_duration;
103     std::string trace_heuristic_boost_active;
104     std::string trace_low_frame_rate;
105     std::string trace_max_duration;
106     std::string trace_missed_cycles;
107     std::array<std::string, enum_size<aidl::android::hardware::power::SessionMode>()> trace_modes;
108     std::array<std::string, static_cast<int32_t>(AdpfVoteType::VOTE_TYPE_SIZE)> trace_votes;
109     std::string trace_cpu_duration;
110     std::string trace_gpu_duration;
111     std::string trace_gpu_capacity;
112 };
113 
114 }  // namespace pixel
115 }  // namespace impl
116 }  // namespace power
117 }  // namespace hardware
118 }  // namespace google
119 }  // namespace aidl
120