From 07b78ea92f7e46cfababe7773fd42a2628c9adee Mon Sep 17 00:00:00 2001 From: Victor Zarubkin Date: Wed, 16 Nov 2016 22:17:39 +0300 Subject: [PATCH] Moved version definition to CMakeLists.txt, added functions for getting profiler version --- include/easy/profiler.h | 37 ++++++++++++++---- include/easy/profiler_aux.h | 1 + profiler_gui/easy_graphics_scrollbar.cpp | 18 +++++++-- src/CMakeLists.txt | 8 ++++ src/profile_manager.cpp | 49 +++++++++++++++++++++++- src/reader.cpp | 11 ++---- 6 files changed, 105 insertions(+), 19 deletions(-) diff --git a/include/easy/profiler.h b/include/easy/profiler.h index ad3d1a1..9f5dffa 100644 --- a/include/easy/profiler.h +++ b/include/easy/profiler.h @@ -40,13 +40,6 @@ along with this program.If not, see . # pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" #endif -namespace profiler { - const uint8_t EASY_VERSION_MAJOR = 1; - const uint8_t EASY_VERSION_MINOR = 0; - const uint16_t EASY_VERSION_REV = 0; - const uint32_t EASY_FULL_VERSION = ((uint32_t)EASY_VERSION_MAJOR << 24) | ((uint32_t)EASY_VERSION_MINOR << 16) | (uint32_t)EASY_VERSION_REV; -} - #ifdef BUILD_WITH_EASY_PROFILER /** @@ -542,6 +535,36 @@ namespace profiler { PROFILER_API void startListenSignalToCapture(); PROFILER_API void stopListenSignalToCapture(); + /** Returns current major version. + + \ingroup profiler + */ + PROFILER_API uint8_t versionMajor(); + + /** Returns current minor version. + + \ingroup profiler + */ + PROFILER_API uint8_t versionMinor(); + + /** Returns current version revision. + + \ingroup profiler + */ + PROFILER_API uint16_t versionRev(); + + /** Returns current version in 32-bit integer format. + + \ingroup profiler + */ + PROFILER_API uint32_t version(); + + /** Returns current version in 32-bit integer format. + + \ingroup profiler + */ + PROFILER_API const char* versionName(); + } ////////////////////////////////////////////////////////////////////// diff --git a/include/easy/profiler_aux.h b/include/easy/profiler_aux.h index a59f8ff..510bab6 100644 --- a/include/easy/profiler_aux.h +++ b/include/easy/profiler_aux.h @@ -61,6 +61,7 @@ namespace profiler { #include #include +# define EASY_VERSION_INT(v_major, v_minor, v_rev) ((static_cast(v_major) << 24) | (static_cast(v_minor) << 16) | static_cast(v_rev)) # define EASY_STRINGIFY(a) #a # define EASY_STRINGIFICATION(a) EASY_STRINGIFY(a) # define EASY_TOKEN_JOIN(x, y) x ## y diff --git a/profiler_gui/easy_graphics_scrollbar.cpp b/profiler_gui/easy_graphics_scrollbar.cpp index 763d8da..8e20317 100644 --- a/profiler_gui/easy_graphics_scrollbar.cpp +++ b/profiler_gui/easy_graphics_scrollbar.cpp @@ -70,6 +70,16 @@ inline qreal sqr(qreal _value) return _value * _value; } +inline qreal calculate_color1(qreal h, qreal k) +{ + return ::std::min(h * k, 0.9999999); +} + +inline qreal calculate_color2(qreal h, qreal k) +{ + return ::std::min(sqr(sqr(h)) * k, 0.9999999); +} + ////////////////////////////////////////////////////////////////////////// EasyGraphicsSliderItem::EasyGraphicsSliderItem(bool _main) : Parent(), m_halfwidth(0), m_bMain(_main) @@ -224,8 +234,9 @@ void EasyMinimapItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem* //_painter->setBrush(brush); _painter->setTransform(QTransform::fromScale(1.0 / currentScale, 1), true); + const bool gotFrame = EASY_GLOBALS.frame_time > 1e-6f; qreal frameCoeff = 1; - if (EASY_GLOBALS.frame_time > 1e-6f) + if (gotFrame) { if (EASY_GLOBALS.frame_time <= m_minDuration) frameCoeff = 0; @@ -233,7 +244,8 @@ void EasyMinimapItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem* frameCoeff = 0.9 * (m_maxDuration - m_minDuration) / (EASY_GLOBALS.frame_time - m_minDuration); } - const auto k = sqr(sqr(heightRevert * frameCoeff)); + auto const calculate_color = gotFrame ? calculate_color2 : calculate_color1; + auto const k = gotFrame ? sqr(sqr(heightRevert * frameCoeff)) : heightRevert; auto& items = *m_pSource; for (const auto& item : items) @@ -241,7 +253,7 @@ void EasyMinimapItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem* // Draw rectangle const auto h = ::std::max((item.width() - m_minDuration) * coeff, 2.0); - const auto col = ::std::min(sqr(sqr(h)) * k, 0.9999999); + const auto col = calculate_color(h, k); const auto color = 0x00ffffff & QColor::fromHsvF((1.0 - col) * 0.375, 0.85, 0.85).rgb(); if (previousColor != color) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9980f62..8445d16 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,13 @@ project(easy_profiler) +# EasyProfiler version +add_definitions( + -DEASY_VERSION_MAJOR=1 + -DEASY_VERSION_MINOR=0 + -DEASY_VERSION_REV=0 +) +# EasyProfiler version + set(CPP_FILES block.cpp profile_manager.cpp diff --git a/src/profile_manager.cpp b/src/profile_manager.cpp index 2ad81c3..0f18f33 100644 --- a/src/profile_manager.cpp +++ b/src/profile_manager.cpp @@ -52,7 +52,24 @@ using namespace profiler; +#if !defined(EASY_VERSION_MAJOR) || !defined(EASY_VERSION_MINOR) || !defined(EASY_VERSION_REV) +# ifdef _WIN32 +# error EASY_VERSION_MAJOR and EASY_VERSION_MINOR and EASY_VERSION_REV macros must be defined +# else +# error "EASY_VERSION_MAJOR and EASY_VERSION_MINOR and EASY_VERSION_REV macros must be defined" +# endif +#endif + const uint32_t PROFILER_SIGNATURE = ('E' << 24) | ('a' << 16) | ('s' << 8) | 'y'; +const uint32_t EASY_CURRENT_VERSION = EASY_VERSION_INT(EASY_VERSION_MAJOR, EASY_VERSION_MINOR, EASY_VERSION_REV); +const std::string EASY_VERSION_NAME = ([](){ + std::ostringstream s; + s << EASY_VERSION_MAJOR << '.' << EASY_VERSION_MINOR << '.' << EASY_VERSION_REV; + //char strbuffer[32] = {}; + //sprintf(strbuffer, "%u.%u.%u", EASY_VERSION_MAJOR, EASY_VERSION_MINOR, EASY_VERSION_REV); + return s.str(); +})(); + const uint8_t FORCE_ON_FLAG = profiler::FORCE_ON & ~profiler::ON; //auto& MANAGER = ProfileManager::instance(); @@ -151,6 +168,34 @@ extern "C" { return MANAGER.stopListenSignalToCapture(); } + PROFILER_API uint8_t versionMajor() + { + static_assert(EASY_VERSION_MAJOR >= 0 && EASY_VERSION_MAJOR < 256, "EASY_VERSION_MAJOR must be defined in range [0, 255]"); + return EASY_VERSION_MAJOR; + } + + PROFILER_API uint8_t versionMinor() + { + static_assert(EASY_VERSION_MINOR >= 0 && EASY_VERSION_MINOR < 256, "EASY_VERSION_MINOR must be defined in range [0, 255]"); + return EASY_VERSION_MINOR; + } + + PROFILER_API uint16_t versionRev() + { + static_assert(EASY_VERSION_REV >= 0 && EASY_VERSION_REV < 65536, "EASY_VERSION_REV must be defined in range [0, 65535]"); + return EASY_VERSION_REV; + } + + PROFILER_API uint32_t version() + { + return EASY_CURRENT_VERSION; + } + + PROFILER_API const char* versionName() + { + return EASY_VERSION_NAME.c_str(); + } + } SerializedBlock::SerializedBlock(const Block& block, uint16_t name_length) @@ -630,7 +675,7 @@ uint32_t ProfileManager::dumpBlocksToStream(profiler::OStream& _outputStream) // Write profiler signature and version _outputStream.write(PROFILER_SIGNATURE); - _outputStream.write(profiler::EASY_FULL_VERSION); + _outputStream.write(EASY_CURRENT_VERSION); // Write CPU frequency to let GUI calculate real time value from CPU clocks #ifdef _WIN32 @@ -927,7 +972,7 @@ void ProfileManager::listen() // Write profiler signature and version os.write(PROFILER_SIGNATURE); - os.write(profiler::EASY_FULL_VERSION); + os.write(EASY_CURRENT_VERSION); // Write block descriptors m_storedSpin.lock(); diff --git a/src/reader.cpp b/src/reader.cpp index 60d7fd6..85d1ae5 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -67,16 +67,13 @@ ////////////////////////////////////////////////////////////////////////// -#define EASY_FULL_VER(Major, Minor, Rev) (((uint32_t)(Major) << 24) | ((uint32_t)(Minor) << 16) | (uint32_t)(Rev)) - +const uint32_t EASY_CURRENT_VERSION = EASY_VERSION_INT(EASY_VERSION_MAJOR, EASY_VERSION_MINOR, EASY_VERSION_REV); const uint32_t COMPATIBLE_VERSIONS[] = { - ::profiler::EASY_FULL_VERSION, - EASY_FULL_VER(0, 1, 0) + EASY_CURRENT_VERSION, + EASY_VERSION_INT(0, 1, 0) }; const uint16_t COMPATIBLE_VERSIONS_NUM = sizeof(COMPATIBLE_VERSIONS) / sizeof(uint32_t); -#undef EASY_FULL_VER - const int64_t TIME_FACTOR = 1000000000LL; const uint32_t PROFILER_SIGNATURE = ('E' << 24) | ('a' << 16) | ('s' << 8) | 'y'; @@ -84,7 +81,7 @@ const uint32_t PROFILER_SIGNATURE = ('E' << 24) | ('a' << 16) | ('s' << 8) | 'y' bool isCompatibleVersion(uint32_t _version) { - if (_version == ::profiler::EASY_FULL_VERSION) + if (_version == EASY_CURRENT_VERSION) return true; return COMPATIBLE_VERSIONS_NUM > 1 && ::std::binary_search(COMPATIBLE_VERSIONS + 1, COMPATIBLE_VERSIONS + COMPATIBLE_VERSIONS_NUM, _version); }