1 /*
2 * Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <utils/constants.h>
31 #include <cutils/properties.h>
32 #include <utils/debug.h>
33
34 #include "hwc_debugger.h"
35
36 namespace sdm {
37
38 HWCDebugHandler HWCDebugHandler::debug_handler_;
39 std::bitset<32> HWCDebugHandler::debug_flags_ = 0x1;
40 int32_t HWCDebugHandler::verbose_level_ = 0x0;
41
DebugAll(bool enable,int verbose_level)42 void HWCDebugHandler::DebugAll(bool enable, int verbose_level) {
43 if (enable) {
44 debug_flags_ = 0x7FFFFFFF;
45 if (verbose_level) {
46 // Enable verbose scalar logs only when explicitely enabled
47 debug_flags_[kTagScalar] = 0;
48 }
49 verbose_level_ = verbose_level;
50 } else {
51 debug_flags_ = 0x1; // kTagNone should always be printed.
52 verbose_level_ = 0;
53 }
54 }
55
DebugResources(bool enable,int verbose_level)56 void HWCDebugHandler::DebugResources(bool enable, int verbose_level) {
57 if (enable) {
58 debug_flags_[kTagResources] = 1;
59 verbose_level_ = verbose_level;
60 } else {
61 debug_flags_[kTagResources] = 0;
62 verbose_level_ = 0;
63 }
64 }
65
DebugStrategy(bool enable,int verbose_level)66 void HWCDebugHandler::DebugStrategy(bool enable, int verbose_level) {
67 if (enable) {
68 debug_flags_[kTagStrategy] = 1;
69 verbose_level_ = verbose_level;
70 } else {
71 debug_flags_[kTagStrategy] = 0;
72 verbose_level_ = 0;
73 }
74 }
75
DebugCompManager(bool enable,int verbose_level)76 void HWCDebugHandler::DebugCompManager(bool enable, int verbose_level) {
77 if (enable) {
78 debug_flags_[kTagCompManager] = 1;
79 verbose_level_ = verbose_level;
80 } else {
81 debug_flags_[kTagCompManager] = 0;
82 verbose_level_ = 0;
83 }
84 }
85
DebugDriverConfig(bool enable,int verbose_level)86 void HWCDebugHandler::DebugDriverConfig(bool enable, int verbose_level) {
87 if (enable) {
88 debug_flags_[kTagDriverConfig] = 1;
89 verbose_level_ = verbose_level;
90 } else {
91 debug_flags_[kTagDriverConfig] = 0;
92 verbose_level_ = 0;
93 }
94 }
95
DebugRotator(bool enable,int verbose_level)96 void HWCDebugHandler::DebugRotator(bool enable, int verbose_level) {
97 if (enable) {
98 debug_flags_[kTagRotator] = 1;
99 verbose_level_ = verbose_level;
100 } else {
101 debug_flags_[kTagRotator] = 0;
102 verbose_level_ = 0;
103 }
104 }
105
DebugScalar(bool enable,int verbose_level)106 void HWCDebugHandler::DebugScalar(bool enable, int verbose_level) {
107 if (enable) {
108 debug_flags_[kTagScalar] = 1;
109 verbose_level_ = verbose_level;
110 } else {
111 debug_flags_[kTagScalar] = 0;
112 verbose_level_ = 0;
113 }
114 }
115
DebugQdcm(bool enable,int verbose_level)116 void HWCDebugHandler::DebugQdcm(bool enable, int verbose_level) {
117 if (enable) {
118 debug_flags_[kTagQDCM] = 1;
119 verbose_level_ = verbose_level;
120 } else {
121 debug_flags_[kTagQDCM] = 0;
122 verbose_level_ = 0;
123 }
124 }
125
DebugClient(bool enable,int verbose_level)126 void HWCDebugHandler::DebugClient(bool enable, int verbose_level) {
127 if (enable) {
128 debug_flags_[kTagClient] = 1;
129 verbose_level_ = verbose_level;
130 } else {
131 debug_flags_[kTagClient] = 0;
132 verbose_level_ = 0;
133 }
134 }
135
DebugDisplay(bool enable,int verbose_level)136 void HWCDebugHandler::DebugDisplay(bool enable, int verbose_level) {
137 if (enable) {
138 debug_flags_[kTagDisplay] = 1;
139 verbose_level_ = verbose_level;
140 } else {
141 debug_flags_[kTagDisplay] = 0;
142 verbose_level_ = 0;
143 }
144 }
145
Error(DebugTag tag,const char * format,...)146 void HWCDebugHandler::Error(DebugTag tag, const char *format, ...) {
147 if (debug_flags_[tag]) {
148 va_list list;
149 va_start(list, format);
150 __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, list);
151 }
152 }
153
Warning(DebugTag tag,const char * format,...)154 void HWCDebugHandler::Warning(DebugTag tag, const char *format, ...) {
155 if (debug_flags_[tag]) {
156 va_list list;
157 va_start(list, format);
158 __android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, format, list);
159 }
160 }
161
Info(DebugTag tag,const char * format,...)162 void HWCDebugHandler::Info(DebugTag tag, const char *format, ...) {
163 if (debug_flags_[tag]) {
164 va_list list;
165 va_start(list, format);
166 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, list);
167 }
168 }
169
Debug(DebugTag tag,const char * format,...)170 void HWCDebugHandler::Debug(DebugTag tag, const char *format, ...) {
171 if (debug_flags_[tag]) {
172 va_list list;
173 va_start(list, format);
174 __android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, format, list);
175 }
176 }
177
Verbose(DebugTag tag,const char * format,...)178 void HWCDebugHandler::Verbose(DebugTag tag, const char *format, ...) {
179 if (debug_flags_[tag] && verbose_level_) {
180 va_list list;
181 va_start(list, format);
182 __android_log_vprint(ANDROID_LOG_VERBOSE, LOG_TAG, format, list);
183 }
184 }
185
BeginTrace(const char * class_name,const char * function_name,const char * custom_string)186 void HWCDebugHandler::BeginTrace(const char *class_name, const char *function_name,
187 const char *custom_string) {
188 char name[PATH_MAX] = {0};
189 snprintf(name, sizeof(name), "%s::%s::%s", class_name, function_name, custom_string);
190 atrace_begin(ATRACE_TAG, name);
191 }
192
EndTrace()193 void HWCDebugHandler::EndTrace() {
194 atrace_end(ATRACE_TAG);
195 }
196
GetIdleTimeoutMs()197 int HWCDebugHandler::GetIdleTimeoutMs() {
198 int value = IDLE_TIMEOUT_DEFAULT_MS;
199 debug_handler_.GetProperty(IDLE_TIME_PROP, &value);
200
201 return value;
202 }
203
GetProperty(const char * property_name,int * value)204 DisplayError HWCDebugHandler::GetProperty(const char *property_name, int *value) {
205 char property[PROPERTY_VALUE_MAX];
206
207 if (property_get(property_name, property, NULL) > 0) {
208 *value = atoi(property);
209 return kErrorNone;
210 }
211
212 return kErrorNotSupported;
213 }
214
GetProperty(const char * property_name,char * value)215 DisplayError HWCDebugHandler::GetProperty(const char *property_name, char *value) {
216 if (property_get(property_name, value, NULL) > 0) {
217 return kErrorNone;
218 }
219
220 return kErrorNotSupported;
221 }
222
SetProperty(const char * property_name,const char * value)223 DisplayError HWCDebugHandler::SetProperty(const char *property_name, const char *value) {
224 if (property_set(property_name, value) == 0) {
225 return kErrorNone;
226 }
227
228 return kErrorNotSupported;
229 }
230
231 } // namespace sdm
232
233