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
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
Error(const char * format,...)168 void HWCDebugHandler::Error(const char *format, ...) {
169 va_list list;
170 va_start(list, format);
171 __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, list);
172 }
173
Warning(const char * format,...)174 void HWCDebugHandler::Warning(const char *format, ...) {
175 va_list list;
176 va_start(list, format);
177 __android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, format, list);
178 }
179
Info(const char * format,...)180 void HWCDebugHandler::Info(const char *format, ...) {
181 va_list list;
182 va_start(list, format);
183 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, list);
184 }
185
Debug(const char * format,...)186 void HWCDebugHandler::Debug(const char *format, ...) {
187 va_list list;
188 va_start(list, format);
189 __android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, format, list);
190 }
191
Verbose(const char * format,...)192 void HWCDebugHandler::Verbose(const char *format, ...) {
193 if (debug_handler_.verbose_level_) {
194 va_list list;
195 va_start(list, format);
196 __android_log_vprint(ANDROID_LOG_VERBOSE, LOG_TAG, format, list);
197 }
198 }
199
BeginTrace(const char * class_name,const char * function_name,const char * custom_string)200 void HWCDebugHandler::BeginTrace(const char *class_name, const char *function_name,
201 const char *custom_string) {
202 if (atrace_is_tag_enabled(ATRACE_TAG)) {
203 char name[PATH_MAX] = {0};
204 snprintf(name, sizeof(name), "%s::%s::%s", class_name, function_name, custom_string);
205 atrace_begin(ATRACE_TAG, name);
206 }
207 }
208
EndTrace()209 void HWCDebugHandler::EndTrace() {
210 atrace_end(ATRACE_TAG);
211 }
212
GetIdleTimeoutMs()213 int HWCDebugHandler::GetIdleTimeoutMs() {
214 int value = IDLE_TIMEOUT_DEFAULT_MS;
215 debug_handler_.GetProperty(IDLE_TIME_PROP, &value);
216
217 return value;
218 }
219
GetProperty(const char * property_name,int * value)220 int HWCDebugHandler::GetProperty(const char *property_name, int *value) {
221 char property[PROPERTY_VALUE_MAX];
222
223 if (property_get(property_name, property, NULL) > 0) {
224 *value = atoi(property);
225 return kErrorNone;
226 }
227
228 return kErrorNotSupported;
229 }
230
GetProperty(const char * property_name,char * value)231 int HWCDebugHandler::GetProperty(const char *property_name, char *value) {
232 if (property_get(property_name, value, NULL) > 0) {
233 return kErrorNone;
234 }
235
236 return kErrorNotSupported;
237 }
238
239 } // namespace sdm
240
241