mirror of
https://github.com/yse/easy_profiler.git
synced 2025-01-14 00:27:55 +08:00
Moved version definition to CMakeLists.txt, added functions for getting profiler version
This commit is contained in:
parent
776039f543
commit
07b78ea92f
@ -40,13 +40,6 @@ along with this program.If not, see <http://www.gnu.org/licenses/>.
|
||||
# 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();
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -61,6 +61,7 @@ namespace profiler {
|
||||
#include <type_traits>
|
||||
#include <string>
|
||||
|
||||
# define EASY_VERSION_INT(v_major, v_minor, v_rev) ((static_cast<uint32_t>(v_major) << 24) | (static_cast<uint32_t>(v_minor) << 16) | static_cast<uint32_t>(v_rev))
|
||||
# define EASY_STRINGIFY(a) #a
|
||||
# define EASY_STRINGIFICATION(a) EASY_STRINGIFY(a)
|
||||
# define EASY_TOKEN_JOIN(x, y) x ## y
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user