From d3a07830771ac6ea0ce3a4d12bfb473cd9a5565d Mon Sep 17 00:00:00 2001 From: Matthew Bentham Date: Wed, 15 Jan 2020 17:21:38 +0000 Subject: Remove use of boost from Logging.hpp This helps prevent leaking of boost names into Arm NN public headers. Change-Id: I1605d2ed178965f8e502bc6a4b4ac3e627bbbbed Signed-off-by: Matthew Bentham --- Android.mk | 1 + CMakeLists.txt | 1 + include/armnn/Logging.hpp | 147 +----------------------------------------- src/armnn/Logging.cpp | 158 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 163 insertions(+), 144 deletions(-) create mode 100644 src/armnn/Logging.cpp diff --git a/Android.mk b/Android.mk index a8f96f5b8a..bfaee443a2 100644 --- a/Android.mk +++ b/Android.mk @@ -90,6 +90,7 @@ LOCAL_SRC_FILES := \ src/armnn/Layer.cpp \ src/armnn/LayerSupport.cpp \ src/armnn/LoadedNetwork.cpp \ + src/armnn/Logging.cpp \ src/armnn/Network.cpp \ src/armnn/NetworkUtils.cpp \ src/armnn/Observable.cpp \ diff --git a/CMakeLists.txt b/CMakeLists.txt index f5d416552d..8616d6dd1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -382,6 +382,7 @@ list(APPEND armnn_sources src/armnn/LayerSupport.cpp src/armnn/LoadedNetwork.cpp src/armnn/LoadedNetwork.hpp + src/armnn/Logging.cpp src/armnn/Network.cpp src/armnn/Network.hpp src/armnn/NetworkQuantizationScheme.hpp diff --git a/include/armnn/Logging.hpp b/include/armnn/Logging.hpp index af6b813c85..45f3f80217 100644 --- a/include/armnn/Logging.hpp +++ b/include/armnn/Logging.hpp @@ -5,26 +5,9 @@ #pragma once +#include #include -#include "Utils.hpp" - - -#if defined(_MSC_VER) -#ifndef NOMINMAX -#define NOMINMAX // Prevent definition of min/max macros that interfere with std::min/max -#endif -#include -#undef TIME_MS // Windows.h defines this but we don't need it and it interferes with our definition in Instrument.hpp -#endif - -#if defined(__ANDROID__) -#include -#endif - -#include -#include - namespace armnn { @@ -59,49 +42,6 @@ private: }; -class StandardOutputColourSink : public LogSink -{ -public: - StandardOutputColourSink(LogSeverity level = LogSeverity::Info) - : m_Level(level) - { - } - - void Consume(const std::string& s) override - { - std::cout << GetColour(m_Level) << s << ResetColour() << std::endl; - } - -private: - std::string ResetColour() - { - return "\033[0m"; - } - - std::string GetColour(LogSeverity level) - { - switch(level) - { - case LogSeverity::Trace: - return "\033[35m"; - case LogSeverity::Debug: - return "\033[32m"; - case LogSeverity::Info: - return "\033[0m"; - case LogSeverity::Warning: - return "\033[33m"; - case LogSeverity::Error: - return "\033[31m"; - case LogSeverity::Fatal: - return "\033[41;30m"; - - default: - return "\033[0m"; - } - } - LogSeverity m_Level; -}; - class StandardOutputSink : public LogSink { public: @@ -111,23 +51,6 @@ public: } }; -class DebugOutputSink : public LogSink -{ -public: - void Consume(const std::string& s) override - { - boost::ignore_unused(s); -#if defined(_MSC_VER) - OutputDebugString(s.c_str()); - OutputDebugString("\n"); -#elif defined(__ANDROID__) - __android_log_write(ANDROID_LOG_DEBUG, "armnn", s.c_str()); -#else - boost::ignore_unused(s); -#endif - } -}; - struct ScopedRecord { ScopedRecord(const std::vector>& sinks, LogSeverity level, bool enabled) @@ -216,73 +139,9 @@ private: bool m_Enable; }; -inline void SetLogFilter(LogSeverity level) -{ - SimpleLogger::Get().Enable(false); - SimpleLogger::Get().Enable(false); - SimpleLogger::Get().Enable(false); - SimpleLogger::Get().Enable(false); - SimpleLogger::Get().Enable(false); - SimpleLogger::Get().Enable(false); - switch (level) - { - case LogSeverity::Trace: - SimpleLogger::Get().Enable(true); - ARMNN_FALLTHROUGH; - case LogSeverity::Debug: - SimpleLogger::Get().Enable(true); - ARMNN_FALLTHROUGH; - case LogSeverity::Info: - SimpleLogger::Get().Enable(true); - ARMNN_FALLTHROUGH; - case LogSeverity::Warning: - SimpleLogger::Get().Enable(true); - ARMNN_FALLTHROUGH; - case LogSeverity::Error: - SimpleLogger::Get().Enable(true); - ARMNN_FALLTHROUGH; - case LogSeverity::Fatal: - SimpleLogger::Get().Enable(true); - break; - default: - BOOST_ASSERT(false); - } -} +void SetLogFilter(LogSeverity level); -template -inline void SetLoggingSinks(bool standardOut, bool debugOut, bool coloured) -{ - SimpleLogger::Get().RemoveAllSinks(); - - if (standardOut) - { - if (coloured) - { - SimpleLogger::Get().AddSink( - std::make_shared(Level)); - } else - { - SimpleLogger::Get().AddSink( - std::make_shared()); - } - } - - if (debugOut) - { - SimpleLogger::Get().AddSink( - std::make_shared()); - } -} - -inline void SetAllLoggingSinks(bool standardOut, bool debugOut, bool coloured) -{ - SetLoggingSinks(standardOut, debugOut, coloured); - SetLoggingSinks(standardOut, debugOut, coloured); - SetLoggingSinks(standardOut, debugOut, coloured); - SetLoggingSinks(standardOut, debugOut, coloured); - SetLoggingSinks(standardOut, debugOut, coloured); - SetLoggingSinks(standardOut, debugOut, coloured); -} +void SetAllLoggingSinks(bool standardOut, bool debugOut, bool coloured); enum class BoostLogSeverityMapping { diff --git a/src/armnn/Logging.cpp b/src/armnn/Logging.cpp new file mode 100644 index 0000000000..2c07751aae --- /dev/null +++ b/src/armnn/Logging.cpp @@ -0,0 +1,158 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +#include + + +#include + +#if defined(_MSC_VER) +#ifndef NOMINMAX +#define NOMINMAX // Prevent definition of min/max macros that interfere with std::min/max +#endif +#include +#undef TIME_MS // Windows.h defines this but we don't need it and it interferes with our definition in Instrument.hpp +#endif + +#if defined(__ANDROID__) +#include +#endif + +#include +#include +#include + +namespace armnn +{ + +void SetLogFilter(LogSeverity level) +{ + SimpleLogger::Get().Enable(false); + SimpleLogger::Get().Enable(false); + SimpleLogger::Get().Enable(false); + SimpleLogger::Get().Enable(false); + SimpleLogger::Get().Enable(false); + SimpleLogger::Get().Enable(false); + switch (level) + { + case LogSeverity::Trace: + SimpleLogger::Get().Enable(true); + ARMNN_FALLTHROUGH; + case LogSeverity::Debug: + SimpleLogger::Get().Enable(true); + ARMNN_FALLTHROUGH; + case LogSeverity::Info: + SimpleLogger::Get().Enable(true); + ARMNN_FALLTHROUGH; + case LogSeverity::Warning: + SimpleLogger::Get().Enable(true); + ARMNN_FALLTHROUGH; + case LogSeverity::Error: + SimpleLogger::Get().Enable(true); + ARMNN_FALLTHROUGH; + case LogSeverity::Fatal: + SimpleLogger::Get().Enable(true); + break; + default: + BOOST_ASSERT(false); + } +} + +class StandardOutputColourSink : public LogSink +{ +public: + StandardOutputColourSink(LogSeverity level = LogSeverity::Info) + : m_Level(level) + { + } + + void Consume(const std::string& s) override + { + std::cout << GetColour(m_Level) << s << ResetColour() << std::endl; + } + +private: + std::string ResetColour() + { + return "\033[0m"; + } + + std::string GetColour(LogSeverity level) + { + switch(level) + { + case LogSeverity::Trace: + return "\033[35m"; + case LogSeverity::Debug: + return "\033[32m"; + case LogSeverity::Info: + return "\033[0m"; + case LogSeverity::Warning: + return "\033[33m"; + case LogSeverity::Error: + return "\033[31m"; + case LogSeverity::Fatal: + return "\033[41;30m"; + + default: + return "\033[0m"; + } + } + LogSeverity m_Level; +}; + +class DebugOutputSink : public LogSink +{ +public: + void Consume(const std::string& s) override + { + boost::ignore_unused(s); +#if defined(_MSC_VER) + OutputDebugString(s.c_str()); + OutputDebugString("\n"); +#elif defined(__ANDROID__) + __android_log_write(ANDROID_LOG_DEBUG, "armnn", s.c_str()); +#else + boost::ignore_unused(s); +#endif + } +}; + +template +inline void SetLoggingSinks(bool standardOut, bool debugOut, bool coloured) +{ + SimpleLogger::Get().RemoveAllSinks(); + + if (standardOut) + { + if (coloured) + { + SimpleLogger::Get().AddSink( + std::make_shared(Level)); + } else + { + SimpleLogger::Get().AddSink( + std::make_shared()); + } + } + + if (debugOut) + { + SimpleLogger::Get().AddSink( + std::make_shared()); + } +} + +void SetAllLoggingSinks(bool standardOut, bool debugOut, bool coloured) +{ + SetLoggingSinks(standardOut, debugOut, coloured); + SetLoggingSinks(standardOut, debugOut, coloured); + SetLoggingSinks(standardOut, debugOut, coloured); + SetLoggingSinks(standardOut, debugOut, coloured); + SetLoggingSinks(standardOut, debugOut, coloured); + SetLoggingSinks(standardOut, debugOut, coloured); +} + + +} //namespace armnn -- cgit v1.2.1