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 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 va_list list; 113 va_start(list, format); 114 __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, list); 115 } 116 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 123 void HWCDebugHandler::Info(DebugTag tag, const char *format, ...) { 124 if (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 131 void HWCDebugHandler::Debug(DebugTag tag, const char *format, ...) { 132 if (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 139 void HWCDebugHandler::Verbose(DebugTag tag, const char *format, ...) { 140 if (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 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 154 void HWCDebugHandler::EndTrace() { 155 atrace_end(ATRACE_TAG); 156 } 157 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 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 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 DisplayError HWCDebugHandler::SetProperty(const char *property_name, const char *value) { 185 if (property_set(property_name, value) == 0) { 186 return kErrorNone; 187 } 188 189 return kErrorNotSupported; 190 } 191 192 } // namespace sdm 193 194