From 0bd1c5d9f93f887c66deef760fcd133b37d74a70 Mon Sep 17 00:00:00 2001 From: Dileep Marchya Date: Fri, 9 Mar 2018 16:40:35 +0530 Subject: libdebug: Add common debug utility. - Add sdm and drm independent debug utility. CRs-Fixed: 2211061 Change-Id: I48f9d8080ce05cff0ac0982f8e7123fec969e695 --- Android.bp | 1 + Android.mk | 2 +- include/Android.mk | 1 + libdebug/Android.mk | 16 +++++++ libdebug/debug_handler.cpp | 60 +++++++++++++++++++++++++++ libdebug/debug_handler.h | 101 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 libdebug/Android.mk create mode 100644 libdebug/debug_handler.cpp create mode 100644 libdebug/debug_handler.h diff --git a/Android.bp b/Android.bp index 7a6b5b61..1eae1b0c 100644 --- a/Android.bp +++ b/Android.bp @@ -28,6 +28,7 @@ cc_library_headers { "gpu_tonemapper", "sdm/include", "gralloc", + "libdebug", ], header_libs: ["libhardware_headers"], export_header_lib_headers: ["libhardware_headers"], diff --git a/Android.mk b/Android.mk index 00c1baa1..707acf1f 100644 --- a/Android.mk +++ b/Android.mk @@ -1,6 +1,6 @@ ifneq ($(TARGET_DISABLE_DISPLAY),true) sdm-libs := sdm/libs -display-hals := include $(sdm-libs)/utils $(sdm-libs)/core +display-hals := include libdebug $(sdm-libs)/utils $(sdm-libs)/core ifneq ($(TARGET_IS_HEADLESS), true) display-hals += libcopybit liblight libmemtrack hdmi_cec \ diff --git a/include/Android.mk b/include/Android.mk index 74c37afe..58653c16 100644 --- a/include/Android.mk +++ b/include/Android.mk @@ -12,6 +12,7 @@ LOCAL_COPY_HEADERS := color_metadata.h \ ../libqdutils/qd_utils.h \ ../libqdutils/qdMetaData.h \ ../libqdutils/display_config.h \ + ../libdebug/debug_handler.h \ ../libqservice/QServiceUtils.h \ ../libqservice/IQService.h \ ../libqservice/IQHDMIClient.h \ diff --git a/libdebug/Android.mk b/libdebug/Android.mk new file mode 100644 index 00000000..3e7ce25d --- /dev/null +++ b/libdebug/Android.mk @@ -0,0 +1,16 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE := libdisplaydebug +LOCAL_VENDOR_MODULE := true +LOCAL_MODULE_TAGS := optional +LOCAL_C_INCLUDES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include +LOCAL_SHARED_LIBRARIES := libdl +LOCAL_CFLAGS := -DLOG_TAG=\"SDM\" -Wall -std=c++11 -Werror -fno-operator-names +LOCAL_CLANG := true +LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr +LOCAL_SRC_FILES := debug_handler.cpp +LOCAL_COPY_HEADERS_TO := qcom/display +LOCAL_COPY_HEADERS := debug_handler.h + +include $(BUILD_SHARED_LIBRARY) diff --git a/libdebug/debug_handler.cpp b/libdebug/debug_handler.cpp new file mode 100644 index 00000000..00c3ec9f --- /dev/null +++ b/libdebug/debug_handler.cpp @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2018, The Linux Foundation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are +* met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided +* with the distribution. +* * Neither the name of The Linux Foundation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "debug_handler.h" + +namespace display { + +// By default, drop any log messages/traces. It need to be overridden by client. +class DefaultDebugHandler : public DebugHandler { + public: + virtual void Error(const char *, ...) { } + virtual void Warning(const char *, ...) { } + virtual void Info(const char *, ...) { } + virtual void Debug(const char *, ...) { } + virtual void Verbose(const char *, ...) { } + virtual void BeginTrace(const char *, const char *, const char *) { } + virtual void EndTrace() { } + virtual int GetProperty(const char *, int *) { return -1; } + virtual int GetProperty(const char *, char *) { return -1; } +}; + +DefaultDebugHandler g_default_debug_handler; +DebugHandler * DebugHandler::debug_handler_ = &g_default_debug_handler; +std::bitset<32> DebugHandler::log_mask_ = 0x1; // Always print logs tagged with value 0 + +void DebugHandler::Set(DebugHandler *debug_handler) { + if (debug_handler) { + debug_handler_ = debug_handler; + } else { + debug_handler_ = &g_default_debug_handler; + } +} + +} // namespace display diff --git a/libdebug/debug_handler.h b/libdebug/debug_handler.h new file mode 100644 index 00000000..0ae5c284 --- /dev/null +++ b/libdebug/debug_handler.h @@ -0,0 +1,101 @@ +/* +* Copyright (c) 2018, The Linux Foundation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are +* met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided +* with the distribution. +* * Neither the name of The Linux Foundation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef __DEBUG_HANDLER_H__ +#define __DEBUG_HANDLER_H__ + +#include + +#define DLOG(method, format, ...) \ + display::DebugHandler::Get()->method(__CLASS__ "::%s: " format, __FUNCTION__, ##__VA_ARGS__) + +#define DLOG_IF(tag, method, format, ...) \ + if (display::DebugHandler::GetLogMask()[tag]) { \ + DLOG(method, format, ##__VA_ARGS__); \ + } + +#define DLOGE_IF(tag, format, ...) DLOG_IF(tag, Error, format, ##__VA_ARGS__) +#define DLOGW_IF(tag, format, ...) DLOG_IF(tag, Warning, format, ##__VA_ARGS__) +#define DLOGI_IF(tag, format, ...) DLOG_IF(tag, Info, format, ##__VA_ARGS__) +#define DLOGD_IF(tag, format, ...) DLOG_IF(tag, Debug, format, ##__VA_ARGS__) +#define DLOGV_IF(tag, format, ...) DLOG_IF(tag, Verbose, format, ##__VA_ARGS__) + +#define DLOGE(format, ...) DLOG(Error, format, ##__VA_ARGS__) +#define DLOGD(format, ...) DLOG(Warning, format, ##__VA_ARGS__) +#define DLOGW(format, ...) DLOG(Info, format, ##__VA_ARGS__) +#define DLOGI(format, ...) DLOG(Debug, format, ##__VA_ARGS__) +#define DLOGV(format, ...) DLOG(Verbose, format, ##__VA_ARGS__) + +#define DTRACE_BEGIN(custom_string) display::DebugHandler::Get()->BeginTrace( \ + __CLASS__, __FUNCTION__, custom_string) +#define DTRACE_END() display::DebugHandler::Get()->EndTrace() +#define DTRACE_SCOPED() display::ScopeTracer \ + scope_tracer(__CLASS__, __FUNCTION__) + +namespace display { + +class DebugHandler { + public: + virtual void Error(const char *format, ...) = 0; + virtual void Warning(const char *format, ...) = 0; + virtual void Info(const char *format, ...) = 0; + virtual void Debug(const char *format, ...) = 0; + virtual void Verbose(const char *format, ...) = 0; + virtual void BeginTrace(const char *class_name, const char *function_name, + const char *custom_string) = 0; + virtual void EndTrace() = 0; + virtual int GetProperty(const char *property_name, int *value) = 0; + virtual int GetProperty(const char *property_name, char *value) = 0; + + static inline DebugHandler *Get() { return debug_handler_; } + static void Set(DebugHandler *debug_handler); + static inline std::bitset<32> & GetLogMask() { return log_mask_; } + static void SetLogMask(const std::bitset<32> &log_mask) { log_mask_ = log_mask; } + + protected: + virtual ~DebugHandler() { } + + private: + static DebugHandler *debug_handler_; + static std::bitset<32> log_mask_; +}; + +template +class ScopeTracer { + public: + ScopeTracer(const char *class_name, const char *function_name) { + T::Get()->BeginTrace(class_name, function_name, ""); + } + + ~ScopeTracer() { T::Get()->EndTrace(); } +}; + +} // namespace display + +#endif // __DEBUG_HANDLER_H__ -- cgit v1.2.3