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 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 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 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 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 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 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 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 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 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 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 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 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 151 void HWCDebugHandler::BeginTrace(const char *class_name, const char *function_name, 152 const char *custom_string) { 153 char name[PATH_MAX] = {0}; 154 snprintf(name, sizeof(name), "%s::%s::%s", class_name, function_name, custom_string); 155 atrace_begin(ATRACE_TAG, name); 156 } 157 158 void HWCDebugHandler::EndTrace() { 159 atrace_end(ATRACE_TAG); 160 } 161 162 int HWCDebugHandler::GetIdleTimeoutMs() { 163 int value = IDLE_TIMEOUT_DEFAULT_MS; 164 debug_handler_.GetProperty("sdm.idle_time", &value); 165 166 return value; 167 } 168 169 DisplayError HWCDebugHandler::GetProperty(const char *property_name, int *value) { 170 char property[PROPERTY_VALUE_MAX]; 171 172 if (property_get(property_name, property, NULL) > 0) { 173 *value = atoi(property); 174 return kErrorNone; 175 } 176 177 return kErrorNotSupported; 178 } 179 180 DisplayError HWCDebugHandler::GetProperty(const char *property_name, char *value) { 181 if (property_get(property_name, value, NULL) > 0) { 182 return kErrorNone; 183 } 184 185 return kErrorNotSupported; 186 } 187 188 DisplayError HWCDebugHandler::SetProperty(const char *property_name, const char *value) { 189 if (property_set(property_name, value) == 0) { 190 return kErrorNone; 191 } 192 193 return kErrorNotSupported; 194 } 195 196 } // namespace sdm 197 198