• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2014 - 2017, 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 std::bitset<32> 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     debug_flags_[kTagResources] = 1;
54     verbose_level_ = verbose_level;
55   } else {
56     debug_flags_[kTagResources] = 0;
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     debug_flags_[kTagStrategy] = 1;
64     verbose_level_ = verbose_level;
65   } else {
66     debug_flags_[kTagStrategy] = 0;
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     debug_flags_[kTagCompManager] = 1;
74     verbose_level_ = verbose_level;
75   } else {
76     debug_flags_[kTagCompManager] = 0;
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     debug_flags_[kTagDriverConfig] = 1;
84     verbose_level_ = verbose_level;
85   } else {
86     debug_flags_[kTagDriverConfig] = 0;
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     debug_flags_[kTagRotator] = 1;
94     verbose_level_ = verbose_level;
95   } else {
96     debug_flags_[kTagRotator] = 0;
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     debug_flags_[kTagQDCM] = 1;
104     verbose_level_ = verbose_level;
105   } else {
106     debug_flags_[kTagQDCM] = 0;
107     verbose_level_ = 0;
108   }
109 }
110 
Error(DebugTag tag,const char * format,...)111 void HWCDebugHandler::Error(DebugTag tag, const char *format, ...) {
112   if (debug_flags_[tag]) {
113     va_list list;
114     va_start(list, format);
115     __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, list);
116   }
117 }
118 
Warning(DebugTag tag,const char * format,...)119 void HWCDebugHandler::Warning(DebugTag tag, const char *format, ...) {
120   if (debug_flags_[tag]) {
121     va_list list;
122     va_start(list, format);
123     __android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, format, list);
124   }
125 }
126 
Info(DebugTag tag,const char * format,...)127 void HWCDebugHandler::Info(DebugTag tag, const char *format, ...) {
128   if (debug_flags_[tag]) {
129     va_list list;
130     va_start(list, format);
131     __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, list);
132   }
133 }
134 
Debug(DebugTag tag,const char * format,...)135 void HWCDebugHandler::Debug(DebugTag tag, const char *format, ...) {
136   if (debug_flags_[tag]) {
137     va_list list;
138     va_start(list, format);
139     __android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, format, list);
140   }
141 }
142 
Verbose(DebugTag tag,const char * format,...)143 void HWCDebugHandler::Verbose(DebugTag tag, const char *format, ...) {
144   if (debug_flags_[tag] && verbose_level_) {
145     va_list list;
146     va_start(list, format);
147     __android_log_vprint(ANDROID_LOG_VERBOSE, LOG_TAG, format, list);
148   }
149 }
150 
BeginTrace(const char * class_name,const char * function_name,const char * custom_string)151 void HWCDebugHandler::BeginTrace(const char *class_name, const char *function_name,
152                                  const char *custom_string) {
153   if (atrace_is_tag_enabled(ATRACE_TAG)) {
154     char name[PATH_MAX] = {0};
155     snprintf(name, sizeof(name), "%s::%s::%s", class_name, function_name, custom_string);
156     atrace_begin(ATRACE_TAG, name);
157   }
158 }
159 
EndTrace()160 void HWCDebugHandler::EndTrace() {
161   atrace_end(ATRACE_TAG);
162 }
163 
GetIdleTimeoutMs()164 int  HWCDebugHandler::GetIdleTimeoutMs() {
165   int value = IDLE_TIMEOUT_DEFAULT_MS;
166   debug_handler_.GetProperty("sdm.idle_time", &value);
167 
168   return value;
169 }
170 
GetProperty(const char * property_name,int * value)171 DisplayError HWCDebugHandler::GetProperty(const char *property_name, int *value) {
172   char property[PROPERTY_VALUE_MAX];
173 
174   if (property_get(property_name, property, NULL) > 0) {
175     *value = atoi(property);
176     return kErrorNone;
177   }
178 
179   return kErrorNotSupported;
180 }
181 
GetProperty(const char * property_name,char * value)182 DisplayError HWCDebugHandler::GetProperty(const char *property_name, char *value) {
183   if (property_get(property_name, value, NULL) > 0) {
184     return kErrorNone;
185   }
186 
187   return kErrorNotSupported;
188 }
189 
SetProperty(const char * property_name,const char * value)190 DisplayError HWCDebugHandler::SetProperty(const char *property_name, const char *value) {
191   if (property_set(property_name, value) == 0) {
192     return kErrorNone;
193   }
194 
195   return kErrorNotSupported;
196 }
197 
198 }  // namespace sdm
199 
200