From 227a23c266fc72f0708d2228c4f19e90a0934583 Mon Sep 17 00:00:00 2001 From: Victor Zarubkin Date: Wed, 8 Feb 2017 22:35:46 +0300 Subject: [PATCH] Added possibility to disable predefined colors palette to reduce binary size when user want to use own colors palette --- easy_profiler_core/CMakeLists.txt | 19 ++++++++++++++----- easy_profiler_core/event_trace_win.cpp | 3 ++- .../include/easy/profiler_colors.h | 5 ++++- easy_profiler_core/profile_manager.cpp | 17 +++++++++++------ 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/easy_profiler_core/CMakeLists.txt b/easy_profiler_core/CMakeLists.txt index 8a286cc..a1050af 100644 --- a/easy_profiler_core/CMakeLists.txt +++ b/easy_profiler_core/CMakeLists.txt @@ -34,11 +34,13 @@ message(STATUS "") # EasyProfiler options:---------------------------------------------- -set(EASY_DEFAULT_PORT 28077) # default listening port -set(EASY_OPTION_LISTEN OFF) # enable automatic startListen on startup -set(EASY_OPTION_PROFILE_SELF OFF) # enable self profiling (measure time for internal storage expand) -set(EASY_OPTION_PROFILE_SELF_BLOCKS_ON OFF) # storage expand default status (profiler::ON or profiler::OFF) -set(EASY_OPTION_LOG OFF) # print errors to stderr +set(EASY_DEFAULT_PORT 28077) # Default listening port +set(EASY_OPTION_LISTEN OFF) # Enable automatic startListen on startup +set(EASY_OPTION_PROFILE_SELF OFF) # Enable self profiling (measure time for internal storage expand) +set(EASY_OPTION_PROFILE_SELF_BLOCKS_ON OFF) # Storage expand default status (profiler::ON or profiler::OFF) +set(EASY_OPTION_LOG OFF) # Print errors to stderr +set(EASY_OPTION_PREDEFINED_COLORS ON) # Use predefined set of colors (see profiler_colors.h) + # If you want to use your own colors palette you can turn this option OFF if(WIN32) set(EASY_OPTION_EVENT_TRACING ON) # Enable event tracing by default @@ -59,6 +61,7 @@ if(WIN32) endif(EASY_OPTION_LOW_PRIORITY_EVENT_TRACING) endif(WIN32) MESSAGE(STATUS " Print errors to stderr = ${EASY_OPTION_LOG}") +MESSAGE(STATUS " Use EasyProfiler colors palette = ${EASY_OPTION_PREDEFINED_COLORS}") MESSAGE(STATUS "END EASY_PROFILER OPTIONS.----------") MESSAGE(STATUS "") # END EasyProfiler options.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -101,6 +104,12 @@ else() add_definitions(-DEASY_OPTION_LOG_ENABLED=0) endif(EASY_OPTION_LOG) +if(EASY_OPTION_PREDEFINED_COLORS) + add_definitions(-DEASY_OPTION_BUILTIN_COLORS=1) +else() + add_definitions(-DEASY_OPTION_BUILTIN_COLORS=0) +endif(EASY_OPTION_PREDEFINED_COLORS) + set(CPP_FILES block.cpp profile_manager.cpp diff --git a/easy_profiler_core/event_trace_win.cpp b/easy_profiler_core/event_trace_win.cpp index 81187f4..2da4805 100644 --- a/easy_profiler_core/event_trace_win.cpp +++ b/easy_profiler_core/event_trace_win.cpp @@ -70,6 +70,7 @@ //extern ProfileManager& MANAGER; #define MANAGER ProfileManager::instance() +extern const ::profiler::color_t EASY_COLOR_INTERNAL_EVENT; ::std::atomic_uint64_t TRACING_END_TIME = ATOMIC_VAR_INIT(~0ULL); namespace profiler { @@ -125,7 +126,7 @@ namespace profiler { if (sizeof(CSwitch) != _traceEvent->UserDataLength) return; - EASY_FUNCTION(::profiler::colors::White, ::profiler::OFF); + EASY_FUNCTION(EASY_COLOR_INTERNAL_EVENT, ::profiler::OFF); auto _contextSwitchEvent = reinterpret_cast(_traceEvent->UserData); const auto time = static_cast<::profiler::timestamp_t>(_traceEvent->EventHeader.TimeStamp.QuadPart); diff --git a/easy_profiler_core/include/easy/profiler_colors.h b/easy_profiler_core/include/easy/profiler_colors.h index 72df90b..b417f21 100644 --- a/easy_profiler_core/include/easy/profiler_colors.h +++ b/easy_profiler_core/include/easy/profiler_colors.h @@ -59,7 +59,7 @@ namespace profiler { return (static_cast(_alpha) << 24) | (static_cast(_red) << 16) | (static_cast(_green) << 8) | static_cast(_blue); } - +#if !defined(EASY_OPTION_BUILTIN_COLORS) || EASY_OPTION_BUILTIN_COLORS != 0 // Google Material Design colors // See https://material.google.com/style/color.html @@ -388,6 +388,9 @@ namespace profiler { const color_t BlueGrey = BlueGrey500; const color_t Default = Wheat; +#else + const color_t Default = 0xffffecb3; +#endif // #if !defined(EASY_OPTION_BUILTIN_COLORS) || EASY_OPTION_BUILTIN_COLORS == 0 } // END of namespace colors. diff --git a/easy_profiler_core/profile_manager.cpp b/easy_profiler_core/profile_manager.cpp index d965eda..9f4ff1b 100644 --- a/easy_profiler_core/profile_manager.cpp +++ b/easy_profiler_core/profile_manager.cpp @@ -91,6 +91,11 @@ const uint8_t FORCE_ON_FLAG = profiler::FORCE_ON & ~profiler::ON; decltype(LARGE_INTEGER::QuadPart) const CPU_FREQUENCY = ([](){ LARGE_INTEGER freq; QueryPerformanceFrequency(&freq); return freq.QuadPart; })(); #endif +extern const profiler::color_t EASY_COLOR_INTERNAL_EVENT = 0xffffffff; // profiler::colors::White +const profiler::color_t EASY_COLOR_THREAD_END = 0xff212121; // profiler::colors::Dark +const profiler::color_t EASY_COLOR_START = 0xff4caf50; // profiler::colors::Green +const profiler::color_t EASY_COLOR_END = 0xfff44336; // profiler::colors::Red + ////////////////////////////////////////////////////////////////////////// EASY_THREAD_LOCAL static ::ThreadStorage* THREAD_STORAGE = nullptr; @@ -347,7 +352,7 @@ void ThreadStorage::storeBlock(const profiler::Block& block) #if EASY_OPTION_MEASURE_STORAGE_EXPAND != 0 EASY_LOCAL_STATIC_PTR(const BaseBlockDescriptor*, desc,\ MANAGER.addBlockDescriptor(EASY_OPTION_STORAGE_EXPAND_BLOCKS_ON ? profiler::ON : profiler::OFF, EASY_UNIQUE_LINE_ID, "EasyProfiler.ExpandStorage",\ - __FILE__, __LINE__, profiler::BLOCK_TYPE_BLOCK, profiler::colors::White)); + __FILE__, __LINE__, profiler::BLOCK_TYPE_BLOCK, EASY_COLOR_INTERNAL_EVENT)); EASY_THREAD_LOCAL static profiler::timestamp_t beginTime = 0ULL; EASY_THREAD_LOCAL static profiler::timestamp_t endTime = 0ULL; @@ -407,7 +412,7 @@ ThreadGuard::~ThreadGuard() if (m_id != 0 && THREAD_STORAGE != nullptr && THREAD_STORAGE->id == m_id) { bool isMarked = false; - EASY_EVENT_RES(isMarked, "ThreadFinished", profiler::colors::Dark, ::profiler::FORCE_ON); + EASY_EVENT_RES(isMarked, "ThreadFinished", EASY_COLOR_THREAD_END, ::profiler::FORCE_ON); THREAD_STORAGE->frame.store(false, std::memory_order_release); THREAD_STORAGE->expired.store(isMarked ? 2 : 1, std::memory_order_release); THREAD_STORAGE = nullptr; @@ -895,7 +900,7 @@ uint32_t ProfileManager::dumpBlocksToStream(profiler::OStream& _outputStream, bo } if (expired == 1) { - EASY_FORCE_EVENT3(t, endtime, "ThreadExpired", profiler::colors::Dark); + EASY_FORCE_EVENT3(t, endtime, "ThreadExpired", EASY_COLOR_THREAD_END); ++num; } @@ -1109,7 +1114,7 @@ void ProfileManager::listen(uint16_t _port) socket.listen(); socket.accept(); - EASY_EVENT("ClientConnected", profiler::colors::White, profiler::OFF); + EASY_EVENT("ClientConnected", EASY_COLOR_INTERNAL_EVENT, profiler::OFF); hasConnect = true; #ifdef EASY_DEBUG_NET_PRINT @@ -1161,7 +1166,7 @@ void ProfileManager::listen(uint16_t _port) printf("receive REQUEST_START_CAPTURE\n"); #endif ::profiler::timestamp_t t = 0; - EASY_FORCE_EVENT(t, "StartCapture", profiler::colors::Green, profiler::OFF); + EASY_FORCE_EVENT(t, "StartCapture", EASY_COLOR_START, profiler::OFF); m_dumpSpin.lock(); const auto prev = m_profilerStatus.exchange(EASY_PROF_ENABLED, std::memory_order_release); @@ -1190,7 +1195,7 @@ void ProfileManager::listen(uint16_t _port) disableEventTracer(); m_endTime = time; } - EASY_FORCE_EVENT2(m_endTime, "StopCapture", profiler::colors::Red, profiler::OFF); + EASY_FORCE_EVENT2(m_endTime, "StopCapture", EASY_COLOR_END, profiler::OFF); //TODO //if connection aborted - ignore this part