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 <display_properties.h>
33
34 #include "hwc_debugger.h"
35
36 namespace sdm {
37
38 HWCDebugHandler HWCDebugHandler::debug_handler_;
39
HWCDebugHandler()40 HWCDebugHandler::HWCDebugHandler() {
41 DebugHandler::Set(HWCDebugHandler::Get());
42 }
43
DebugAll(bool enable,int verbose_level)44 void HWCDebugHandler::DebugAll(bool enable, int verbose_level) {
45 if (enable) {
46 debug_handler_.log_mask_ = 0x7FFFFFFF;
47 if (verbose_level) {
48 // Enable verbose scalar logs only when explicitly enabled
49 debug_handler_.log_mask_[kTagScalar] = 0;
50 }
51 debug_handler_.verbose_level_ = verbose_level;
52 } else {
53 debug_handler_.log_mask_ = 0x1; // kTagNone should always be printed.
54 debug_handler_.verbose_level_ = 0;
55 }
56
57 DebugHandler::SetLogMask(debug_handler_.log_mask_);
58 }
59
DebugResources(bool enable,int verbose_level)60 void HWCDebugHandler::DebugResources(bool enable, int verbose_level) {
61 if (enable) {
62 debug_handler_.log_mask_[kTagResources] = 1;
63 debug_handler_.verbose_level_ = verbose_level;
64 } else {
65 debug_handler_.log_mask_[kTagResources] = 0;
66 debug_handler_.verbose_level_ = 0;
67 }
68
69 DebugHandler::SetLogMask(debug_handler_.log_mask_);
70 }
71
DebugStrategy(bool enable,int verbose_level)72 void HWCDebugHandler::DebugStrategy(bool enable, int verbose_level) {
73 if (enable) {
74 debug_handler_.log_mask_[kTagStrategy] = 1;
75 debug_handler_.verbose_level_ = verbose_level;
76 } else {
77 debug_handler_.log_mask_[kTagStrategy] = 0;
78 debug_handler_.verbose_level_ = 0;
79 }
80
81 DebugHandler::SetLogMask(debug_handler_.log_mask_);
82 }
83
DebugCompManager(bool enable,int verbose_level)84 void HWCDebugHandler::DebugCompManager(bool enable, int verbose_level) {
85 if (enable) {
86 debug_handler_.log_mask_[kTagCompManager] = 1;
87 debug_handler_.verbose_level_ = verbose_level;
88 } else {
89 debug_handler_.log_mask_[kTagCompManager] = 0;
90 debug_handler_.verbose_level_ = 0;
91 }
92
93 DebugHandler::SetLogMask(debug_handler_.log_mask_);
94 }
95
DebugDriverConfig(bool enable,int verbose_level)96 void HWCDebugHandler::DebugDriverConfig(bool enable, int verbose_level) {
97 if (enable) {
98 debug_handler_.log_mask_[kTagDriverConfig] = 1;
99 debug_handler_.verbose_level_ = verbose_level;
100 } else {
101 debug_handler_.log_mask_[kTagDriverConfig] = 0;
102 debug_handler_.verbose_level_ = 0;
103 }
104
105 DebugHandler::SetLogMask(debug_handler_.log_mask_);
106 }
107
DebugRotator(bool enable,int verbose_level)108 void HWCDebugHandler::DebugRotator(bool enable, int verbose_level) {
109 if (enable) {
110 debug_handler_.log_mask_[kTagRotator] = 1;
111 debug_handler_.verbose_level_ = verbose_level;
112 } else {
113 debug_handler_.log_mask_[kTagRotator] = 0;
114 debug_handler_.verbose_level_ = 0;
115 }
116
117 DebugHandler::SetLogMask(debug_handler_.log_mask_);
118 }
119
DebugScalar(bool enable,int verbose_level)120 void HWCDebugHandler::DebugScalar(bool enable, int verbose_level) {
121 if (enable) {
122 debug_handler_.log_mask_[kTagScalar] = 1;
123 debug_handler_.verbose_level_ = verbose_level;
124 } else {
125 debug_handler_.log_mask_[kTagScalar] = 0;
126 debug_handler_.verbose_level_ = 0;
127 }
128
129 DebugHandler::SetLogMask(debug_handler_.log_mask_);
130 }
131
DebugQdcm(bool enable,int verbose_level)132 void HWCDebugHandler::DebugQdcm(bool enable, int verbose_level) {
133 if (enable) {
134 debug_handler_.log_mask_[kTagQDCM] = 1;
135 debug_handler_.verbose_level_ = verbose_level;
136 } else {
137 debug_handler_.log_mask_[kTagQDCM] = 0;
138 debug_handler_.verbose_level_ = 0;
139 }
140
141 DebugHandler::SetLogMask(debug_handler_.log_mask_);
142 }
143
DebugClient(bool enable,int verbose_level)144 void HWCDebugHandler::DebugClient(bool enable, int verbose_level) {
145 if (enable) {
146 debug_handler_.log_mask_[kTagClient] = 1;
147 debug_handler_.verbose_level_ = verbose_level;
148 } else {
149 debug_handler_.log_mask_[kTagClient] = 0;
150 debug_handler_.verbose_level_ = 0;
151 }
152
153 DebugHandler::SetLogMask(debug_handler_.log_mask_);
154 }
155
DebugDisplay(bool enable,int verbose_level)156 void HWCDebugHandler::DebugDisplay(bool enable, int verbose_level) {
157 if (enable) {
158 debug_handler_.log_mask_[kTagDisplay] = 1;
159 debug_handler_.verbose_level_ = verbose_level;
160 } else {
161 debug_handler_.log_mask_[kTagDisplay] = 0;
162 debug_handler_.verbose_level_ = 0;
163 }
164
165 DebugHandler::SetLogMask(debug_handler_.log_mask_);
166 }
167
DebugQos(bool enable,int verbose_level)168 void HWCDebugHandler::DebugQos(bool enable, int verbose_level) {
169 if (enable) {
170 debug_handler_.log_mask_[kTagQOSClient] = 1;
171 // TODO(user): add qos impl log mask when logging available
172 debug_handler_.verbose_level_ = verbose_level;
173 } else {
174 debug_handler_.log_mask_[kTagQOSClient] = 0;
175 // TODO(user): add qos impl log mask when logging available
176 debug_handler_.verbose_level_ = 0;
177 }
178
179 DebugHandler::SetLogMask(debug_handler_.log_mask_);
180 }
181
Error(const char * format,...)182 void HWCDebugHandler::Error(const char *format, ...) {
183 va_list list;
184 va_start(list, format);
185 __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, list);
186 }
187
Warning(const char * format,...)188 void HWCDebugHandler::Warning(const char *format, ...) {
189 va_list list;
190 va_start(list, format);
191 __android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, format, list);
192 }
193
Info(const char * format,...)194 void HWCDebugHandler::Info(const char *format, ...) {
195 va_list list;
196 va_start(list, format);
197 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, list);
198 }
199
Debug(const char * format,...)200 void HWCDebugHandler::Debug(const char *format, ...) {
201 va_list list;
202 va_start(list, format);
203 __android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, format, list);
204 }
205
Verbose(const char * format,...)206 void HWCDebugHandler::Verbose(const char *format, ...) {
207 if (debug_handler_.verbose_level_) {
208 va_list list;
209 va_start(list, format);
210 __android_log_vprint(ANDROID_LOG_VERBOSE, LOG_TAG, format, list);
211 }
212 }
213
BeginTrace(const char * class_name,const char * function_name,const char * custom_string)214 void HWCDebugHandler::BeginTrace(const char *class_name, const char *function_name,
215 const char *custom_string) {
216 if (atrace_is_tag_enabled(ATRACE_TAG)) {
217 char name[PATH_MAX] = {0};
218 snprintf(name, sizeof(name), "%s::%s::%s", class_name, function_name, custom_string);
219 atrace_begin(ATRACE_TAG, name);
220 }
221 }
222
EndTrace()223 void HWCDebugHandler::EndTrace() {
224 atrace_end(ATRACE_TAG);
225 }
226
GetIdleTimeoutMs()227 int HWCDebugHandler::GetIdleTimeoutMs() {
228 int value = IDLE_TIMEOUT_DEFAULT_MS;
229 debug_handler_.GetProperty(IDLE_TIME_PROP, &value);
230
231 return value;
232 }
233
GetProperty(const char * property_name,int * value)234 int HWCDebugHandler::GetProperty(const char *property_name, int *value) {
235 char property[PROPERTY_VALUE_MAX];
236
237 if (property_get(property_name, property, NULL) > 0) {
238 *value = atoi(property);
239 return kErrorNone;
240 }
241
242 return kErrorNotSupported;
243 }
244
GetProperty(const char * property_name,char * value)245 int HWCDebugHandler::GetProperty(const char *property_name, char *value) {
246 if (property_get(property_name, value, NULL) > 0) {
247 return kErrorNone;
248 }
249
250 return kErrorNotSupported;
251 }
252
253 } // namespace sdm
254
255