From 1ba602ee2e63de158c5e01e73014b712fd1ba09f Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=95=9C=EC=A2=85/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84?= =?utf8?q?=EC=9E=90?= Date: Thu, 5 Apr 2018 13:25:06 +0900 Subject: [PATCH] Support Enable/Disable VLOG (#451) Introduce environment variable VLOG for Enable/Disable VLOG outputs. `VLOG` is disabled by default. Example usage ``` VLOG=1 ./tests/framework/run_test.sh # Enable VLOG ``` --- .../ref/nn/depend/android-base/CMakeLists.txt | 9 ++++++ .../android-base/include/android-base/logging.h | 30 ++++++++++++++++++- src/runtime/ref/nn/depend/android-base/logging.cpp | 35 ++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/runtime/ref/nn/depend/android-base/logging.cpp diff --git a/src/runtime/ref/nn/depend/android-base/CMakeLists.txt b/src/runtime/ref/nn/depend/android-base/CMakeLists.txt index 5fb89a9..a77cdbf 100644 --- a/src/runtime/ref/nn/depend/android-base/CMakeLists.txt +++ b/src/runtime/ref/nn/depend/android-base/CMakeLists.txt @@ -8,3 +8,12 @@ SET(INC_DIRS PARENT_SCOPE ) +SET(CUR_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/logging.cpp +) + +SET(SRCS + ${SRCS} + ${CUR_SRCS} + PARENT_SCOPE +) diff --git a/src/runtime/ref/nn/depend/android-base/include/android-base/logging.h b/src/runtime/ref/nn/depend/android-base/include/android-base/logging.h index 8f386fa..26369a5 100644 --- a/src/runtime/ref/nn/depend/android-base/include/android-base/logging.h +++ b/src/runtime/ref/nn/depend/android-base/include/android-base/logging.h @@ -6,8 +6,36 @@ namespace android { namespace base { +// TODO-NNRT Move this to proper place +class BoolConfig +{ +public: + BoolConfig(const std::string &tag, bool default_value); + +public: + bool value(void) const { return _value; } + +private: + bool _value; +}; + +class VLogging +{ +public: + static VLogging& access(void); + bool enabled() const { return _enabled; } + std::ostream& stream(void); + +private: + VLogging(); + +private: + bool _enabled; +}; + #define LOG(...) std::cout << std::endl -#define VLOG(...) LOG(...) +#define VLOG(...) if (::android::base::VLogging::access().enabled()) \ + (::android::base::VLogging::access().stream() << std::endl) #define PLOG(...) LOG(...) } // namespace base diff --git a/src/runtime/ref/nn/depend/android-base/logging.cpp b/src/runtime/ref/nn/depend/android-base/logging.cpp new file mode 100644 index 0000000..6286b71 --- /dev/null +++ b/src/runtime/ref/nn/depend/android-base/logging.cpp @@ -0,0 +1,35 @@ +#include "android-base/logging.h" + +namespace android { +namespace base { + +BoolConfig::BoolConfig(const std::string &tag, bool default_value) : _value(default_value) +{ + const char *str = getenv(tag.c_str()); + + if (str != nullptr) + { + std::string s = std::string(str); + _value = ((s != "0") && (s != "false") && (s != "FALSE")); + } +} + +VLogging::VLogging() +{ + BoolConfig vlog_enabled("VLOG", false); + _enabled = vlog_enabled.value(); +} + +VLogging& VLogging::access() +{ + static VLogging instance; + return instance; +} + +std::ostream& VLogging::stream() +{ + return std::cout; +} + +} // namespace base +} // namespace android -- 2.7.4