1 /*
2 * Copyright (c) 2014 - 2016, 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 
33 #include "hwc_debugger.h"
34 
35 namespace sdm {
36 
37 HWCDebugHandler HWCDebugHandler::debug_handler_;
38 int32_t HWCDebugHandler::debug_flags_ = 0x1;
39 int32_t HWCDebugHandler::verbose_level_ = 0x0;
40 
DebugAll(bool enable,int verbose_level)41 void HWCDebugHandler::DebugAll(bool enable, int verbose_level) {
42   if (enable) {
43     debug_flags_ = 0x7FFFFFFF;
44     verbose_level_ = verbose_level;
45   } else {
46     debug_flags_ = 0x1;   // kTagNone should always be printed.
47     verbose_level_ = 0;
48   }
49 }
50 
DebugResources(bool enable,int verbose_level)51 void HWCDebugHandler::DebugResources(bool enable, int verbose_level) {
52   if (enable) {
53     SET_BIT(debug_flags_, kTagResources);
54     verbose_level_ = verbose_level;
55   } else {
56     CLEAR_BIT(debug_flags_, kTagResources);
57     verbose_level_ = 0;
58   }
59 }
60 
DebugStrategy(bool enable,int verbose_level)61 void HWCDebugHandler::DebugStrategy(bool enable, int verbose_level) {
62   if (enable) {
63     SET_BIT(debug_flags_, kTagStrategy);
64     verbose_level_ = verbose_level;
65   } else {
66     CLEAR_BIT(debug_flags_, kTagStrategy);
67     verbose_level_ = 0;
68   }
69 }
70 
DebugCompManager(bool enable,int verbose_level)71 void HWCDebugHandler::DebugCompManager(bool enable, int verbose_level) {
72   if (enable) {
73     SET_BIT(debug_flags_, kTagCompManager);
74     verbose_level_ = verbose_level;
75   } else {
76     CLEAR_BIT(debug_flags_, kTagCompManager);
77     verbose_level_ = 0;
78   }
79 }
80 
DebugDriverConfig(bool enable,int verbose_level)81 void HWCDebugHandler::DebugDriverConfig(bool enable, int verbose_level) {
82   if (enable) {
83     SET_BIT(debug_flags_, kTagDriverConfig);
84     verbose_level_ = verbose_level;
85   } else {
86     CLEAR_BIT(debug_flags_, kTagDriverConfig);
87     verbose_level_ = 0;
88   }
89 }
90 
DebugRotator(bool enable,int verbose_level)91 void HWCDebugHandler::DebugRotator(bool enable, int verbose_level) {
92   if (enable) {
93     SET_BIT(debug_flags_, kTagRotator);
94     verbose_level_ = verbose_level;
95   } else {
96     CLEAR_BIT(debug_flags_, kTagRotator);
97     verbose_level_ = 0;
98   }
99 }
100 
DebugQdcm(bool enable,int verbose_level)101 void HWCDebugHandler::DebugQdcm(bool enable, int verbose_level) {
102   if (enable) {
103     SET_BIT(debug_flags_, kTagQDCM);
104     verbose_level_ = verbose_level;
105   } else {
106     CLEAR_BIT(debug_flags_, kTagQDCM);
107     verbose_level_ = 0;
108   }
109 }
110 
Error(DebugTag,const char * format,...)111 void HWCDebugHandler::Error(DebugTag /*tag*/, const char *format, ...) {
112   va_list list;
113   va_start(list, format);
114   __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, list);
115 }
116 
Warning(DebugTag,const char * format,...)117 void HWCDebugHandler::Warning(DebugTag /*tag*/, const char *format, ...) {
118   va_list list;
119   va_start(list, format);
120   __android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, format, list);
121 }
122 
Info(DebugTag tag,const char * format,...)123 void HWCDebugHandler::Info(DebugTag tag, const char *format, ...) {
124   if (IS_BIT_SET(debug_flags_, tag)) {
125     va_list list;
126     va_start(list, format);
127     __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, list);
128   }
129 }
130 
Debug(DebugTag tag,const char * format,...)131 void HWCDebugHandler::Debug(DebugTag tag, const char *format, ...) {
132   if (IS_BIT_SET(debug_flags_, tag)) {
133     va_list list;
134     va_start(list, format);
135     __android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, format, list);
136   }
137 }
138 
Verbose(DebugTag tag,const char * format,...)139 void HWCDebugHandler::Verbose(DebugTag tag, const char *format, ...) {
140   if (IS_BIT_SET(debug_flags_, tag)  && verbose_level_) {
141     va_list list;
142     va_start(list, format);
143     __android_log_vprint(ANDROID_LOG_VERBOSE, LOG_TAG, format, list);
144   }
145 }
146 
BeginTrace(const char * class_name,const char * function_name,const char * custom_string)147 void HWCDebugHandler::BeginTrace(const char *class_name, const char *function_name,
148                                  const char *custom_string) {
149   char name[PATH_MAX] = {0};
150   snprintf(name, sizeof(name), "%s::%s::%s", class_name, function_name, custom_string);
151   atrace_begin(ATRACE_TAG, name);
152 }
153 
EndTrace()154 void HWCDebugHandler::EndTrace() {
155   atrace_end(ATRACE_TAG);
156 }
157 
GetIdleTimeoutMs()158 int  HWCDebugHandler::GetIdleTimeoutMs() {
159   int value = IDLE_TIMEOUT_DEFAULT_MS;
160   debug_handler_.GetProperty("sdm.idle_time", &value);
161 
162   return value;
163 }
164 
GetProperty(const char * property_name,int * value)165 DisplayError HWCDebugHandler::GetProperty(const char *property_name, int *value) {
166   char property[PROPERTY_VALUE_MAX];
167 
168   if (property_get(property_name, property, NULL) > 0) {
169     *value = atoi(property);
170     return kErrorNone;
171   }
172 
173   return kErrorNotSupported;
174 }
175 
GetProperty(const char * property_name,char * value)176 DisplayError HWCDebugHandler::GetProperty(const char *property_name, char *value) {
177   if (property_get(property_name, value, NULL) > 0) {
178     return kErrorNone;
179   }
180 
181   return kErrorNotSupported;
182 }
183 
184 }  // namespace sdm
185 
186