0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-26 16:11:02 +08:00

Added possibility to build easy_profiler with empty API implementation to avoid whole solution rebuild if you want to build without profiler;

* resources.rc changes: proper macro names + copyright sign;
This commit is contained in:
Victor Zarubkin 2016-11-20 13:42:05 +03:00
parent 097723848f
commit 752f0c08a8
9 changed files with 164 additions and 53 deletions

View File

@ -22,9 +22,9 @@ message(STATUS "PROGRAM_VERSION_PATCH: ${PROGRAM_VERSION_PATCH}")
# EasyProfiler version
add_definitions(
-DEASY_VERSION_MAJOR=${PROGRAM_VERSION_MAJOR}
-DEASY_VERSION_MINOR=${PROGRAM_VERSION_MINOR}
-DEASY_VERSION_REV=${PROGRAM_VERSION_PATCH}
-DEASY_PROFILER_VERSION_MAJOR=${PROGRAM_VERSION_MAJOR}
-DEASY_PROFILER_VERSION_MINOR=${PROGRAM_VERSION_MINOR}
-DEASY_PROFILER_VERSION_PATCH=${PROGRAM_VERSION_PATCH}
-DEASY_PROFILER_PRODUCT_VERSION=\"v${PRODUCT_VERSION_STRING}\"
)
# EasyProfiler version

View File

@ -279,7 +279,7 @@ Otherwise, no log messages will be printed.
\ingroup profiler
*/
# define EASY_LOG_ENABLED 1
# define EASY_LOG_ENABLED 0
#else // #ifdef BUILD_WITH_EASY_PROFILER
@ -442,6 +442,7 @@ namespace profiler {
// Core API
// Note: it is better to use macros defined above than a direct calls to API.
#ifdef BUILD_WITH_EASY_PROFILER
extern "C" {
/** Registers static description of a block.
@ -547,11 +548,11 @@ namespace profiler {
*/
PROFILER_API uint8_t versionMinor();
/** Returns current version revision.
/** Returns current version patch.
\ingroup profiler
*/
PROFILER_API uint16_t versionRev();
PROFILER_API uint16_t versionPatch();
/** Returns current version in 32-bit integer format.
@ -566,6 +567,27 @@ namespace profiler {
PROFILER_API const char* versionName();
}
#else
inline const BaseBlockDescriptor* registerDescription(EasyBlockStatus, const char*, const char*, const char*, int, block_type_t, color_t)
{ return reinterpret_cast<const BaseBlockDescriptor*>(0xbad); }
inline void endBlock() { }
inline void setEnabled(bool) { }
inline void storeEvent(const BaseBlockDescriptor*, const char*) { }
inline void beginBlock(Block&) { }
inline uint32_t dumpBlocksToFile(const char*) { return 0; }
inline const char* registerThread(const char*, ThreadGuard&) { return ""; }
inline void setEventTracingEnabled(bool) { }
inline void setLowPriorityEventTracing(bool) { }
inline void setContextSwitchLogFilename(const char*) { }
inline const char* getContextSwitchLogFilename() { return ""; }
inline void startListenSignalToCapture() { }
inline void stopListenSignalToCapture() { }
inline uint8_t versionMajor() { return 0; }
inline uint8_t versionMinor() { return 0; }
inline uint16_t versionPatch() { return 0; }
inline uint32_t version() { return 0; }
inline const char* versionName() { return "v0.0.0_disabled"; }
#endif
//////////////////////////////////////////////////////////////////////

View File

@ -75,7 +75,6 @@ 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

View File

@ -1,16 +1,16 @@
IDI_ICON1 ICON DISCARDABLE "icons/logo.ico"
1 VERSIONINFO
FILEVERSION EASY_VERSION_MAJOR, EASY_VERSION_MINOR, EASY_VERSION_REV
PRODUCTVERSION EASY_VERSION_MAJOR, EASY_VERSION_MINOR, EASY_VERSION_REV
FILEVERSION EASY_PROFILER_VERSION_MAJOR, EASY_PROFILER_VERSION_MINOR, EASY_PROFILER_VERSION_PATCH
PRODUCTVERSION EASY_PROFILER_VERSION_MAJOR, EASY_PROFILER_VERSION_MINOR, EASY_PROFILER_VERSION_PATCH
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904b0"
BEGIN
VALUE "CompanyName", "EasyProfiler Team"
VALUE "FileDescription", "Gui application for reading easy_profiler capturings"
VALUE "FileDescription", "EasyProfiler"
VALUE "InternalName", "profiler_gui"
VALUE "LegalCopyright", "Copyright 2016 Victor Zarubkin, Sergey Yagovtsev"
VALUE "LegalCopyright", "Copyright (C) 2016 Victor Zarubkin, Sergey Yagovtsev"
VALUE "LegalTrademarks1", "All Rights Reserved"
VALUE "LegalTrademarks2", "All Rights Reserved"
VALUE "OriginalFilename", "profiler_gui.exe"

View File

@ -26,6 +26,7 @@ set(SOURCES
add_definitions(
-D_BUILD_PROFILER
-DBUILD_WITH_EASY_PROFILER
#-DEASY_PROFILER_API_DISABLED # uncomment this to disable profiler api only (you will have to rebuild only easy_profiler)
)
if(WIN32)

View File

@ -43,6 +43,7 @@
using namespace profiler;
#ifndef EASY_PROFILER_API_DISABLED
BaseBlockData::BaseBlockData(timestamp_t _begin_time, block_id_t _descriptor_id)
: m_begin(_begin_time)
, m_end(0)
@ -59,14 +60,6 @@ Block::Block(Block&& that)
m_end = that.m_end;
}
Block::Block(const BaseBlockDescriptor* _descriptor, const char* _runtimeName)
: BaseBlockData(1ULL, _descriptor->id())
, m_name(_runtimeName)
, m_status(_descriptor->status())
{
}
Block::Block(timestamp_t _begin_time, block_id_t _descriptor_id, const char* _runtimeName)
: BaseBlockData(_begin_time, _descriptor_id)
, m_name(_runtimeName)
@ -75,6 +68,14 @@ Block::Block(timestamp_t _begin_time, block_id_t _descriptor_id, const char* _ru
}
Block::Block(const BaseBlockDescriptor* _descriptor, const char* _runtimeName)
: BaseBlockData(1ULL, _descriptor->id())
, m_name(_runtimeName)
, m_status(_descriptor->status())
{
}
void Block::start()
{
m_begin = getCurrentTime();
@ -100,3 +101,55 @@ Block::~Block()
if (!finished())
::profiler::endBlock();
}
#else
BaseBlockData::BaseBlockData(timestamp_t, block_id_t)
: m_begin(0)
, m_end(0)
, m_id(~0U)
{
}
Block::Block(Block&&)
: BaseBlockData(0, ~0U)
, m_name("")
, m_status(::profiler::OFF)
{
}
Block::Block(timestamp_t, block_id_t, const char*)
: BaseBlockData(0, ~0U)
, m_name("")
, m_status(::profiler::OFF)
{
}
Block::Block(const BaseBlockDescriptor*, const char*)
: BaseBlockData(0, ~0U)
, m_name("")
, m_status(::profiler::OFF)
{
}
void Block::start()
{
}
void Block::start(timestamp_t)
{
}
void Block::finish()
{
}
void Block::finish(timestamp_t)
{
}
Block::~Block()
{
}
#endif

View File

@ -52,51 +52,59 @@
using namespace profiler;
#if !defined(EASY_VERSION_MAJOR) || !defined(EASY_VERSION_MINOR) || !defined(EASY_VERSION_REV)
//////////////////////////////////////////////////////////////////////////
#if !defined(EASY_PROFILER_VERSION_MAJOR) || !defined(EASY_PROFILER_VERSION_MINOR) || !defined(EASY_PROFILER_VERSION_PATCH)
# ifdef _WIN32
# error EASY_VERSION_MAJOR and EASY_VERSION_MINOR and EASY_VERSION_REV macros must be defined
# error EASY_PROFILER_VERSION_MAJOR and EASY_PROFILER_VERSION_MINOR and EASY_PROFILER_VERSION_PATCH macros must be defined
# else
# error "EASY_VERSION_MAJOR and EASY_VERSION_MINOR and EASY_VERSION_REV macros must be defined"
# error "EASY_PROFILER_VERSION_MAJOR and EASY_PROFILER_VERSION_MINOR and EASY_PROFILER_VERSION_PATCH 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;
return s.str();
})();
# define EASY_VERSION_INT(v_major, v_minor, v_patch) ((static_cast<uint32_t>(v_major) << 24) | (static_cast<uint32_t>(v_minor) << 16) | static_cast<uint32_t>(v_patch))
extern const uint32_t PROFILER_SIGNATURE = ('E' << 24) | ('a' << 16) | ('s' << 8) | 'y';
extern const uint32_t EASY_CURRENT_VERSION = EASY_VERSION_INT(EASY_PROFILER_VERSION_MAJOR, EASY_PROFILER_VERSION_MINOR, EASY_PROFILER_VERSION_PATCH);
# undef EASY_VERSION_INT
const uint8_t FORCE_ON_FLAG = profiler::FORCE_ON & ~profiler::ON;
//////////////////////////////////////////////////////////////////////////
//auto& MANAGER = ProfileManager::instance();
#define MANAGER ProfileManager::instance()
EASY_THREAD_LOCAL static ::ThreadStorage* THREAD_STORAGE = nullptr;
# define MANAGER ProfileManager::instance()
const uint8_t FORCE_ON_FLAG = profiler::FORCE_ON & ~profiler::ON;
#ifdef _WIN32
decltype(LARGE_INTEGER::QuadPart) CPU_FREQUENCY = ([](){ LARGE_INTEGER freq; QueryPerformanceFrequency(&freq); return freq.QuadPart; })();
decltype(LARGE_INTEGER::QuadPart) const CPU_FREQUENCY = ([](){ LARGE_INTEGER freq; QueryPerformanceFrequency(&freq); return freq.QuadPart; })();
#endif
//////////////////////////////////////////////////////////////////////////
#define EASY_FORCE_EVENT(timestamp, name, ...)\
EASY_THREAD_LOCAL static ::ThreadStorage* THREAD_STORAGE = nullptr;
//////////////////////////////////////////////////////////////////////////
#ifdef BUILD_WITH_EASY_PROFILER
# define EASY_FORCE_EVENT(timestamp, name, ...)\
EASY_LOCAL_STATIC_PTR(const ::profiler::BaseBlockDescriptor*, EASY_UNIQUE_DESC(__LINE__), addBlockDescriptor(\
::profiler::extract_enable_flag(__VA_ARGS__), EASY_UNIQUE_LINE_ID, EASY_COMPILETIME_NAME(name),\
__FILE__, __LINE__, ::profiler::BLOCK_TYPE_EVENT, ::profiler::extract_color(__VA_ARGS__)));\
storeBlockForce(EASY_UNIQUE_DESC(__LINE__), EASY_RUNTIME_NAME(name), timestamp);
#define EASY_FORCE_EVENT2(timestamp, name, ...)\
# define EASY_FORCE_EVENT2(timestamp, name, ...)\
EASY_LOCAL_STATIC_PTR(const ::profiler::BaseBlockDescriptor*, EASY_UNIQUE_DESC(__LINE__), addBlockDescriptor(\
::profiler::extract_enable_flag(__VA_ARGS__), EASY_UNIQUE_LINE_ID, EASY_COMPILETIME_NAME(name),\
__FILE__, __LINE__, ::profiler::BLOCK_TYPE_EVENT, ::profiler::extract_color(__VA_ARGS__)));\
storeBlockForce2(EASY_UNIQUE_DESC(__LINE__), EASY_RUNTIME_NAME(name), timestamp);
#else
# define EASY_FORCE_EVENT(timestamp, name, ...)
# define EASY_FORCE_EVENT2(timestamp, name, ...)
#endif
//////////////////////////////////////////////////////////////////////////
extern "C" {
#if !defined(EASY_PROFILER_API_DISABLED)
PROFILER_API const BaseBlockDescriptor* registerDescription(EasyBlockStatus _status, const char* _autogenUniqueId, const char* _name, const char* _filename, int _line, block_type_t _block_type, color_t _color)
{
return MANAGER.addBlockDescriptor(_status, _autogenUniqueId, _name, _filename, _line, _block_type, _color);
@ -137,14 +145,14 @@ extern "C" {
MANAGER.setEventTracingEnabled(_isEnable);
}
#ifdef _WIN32
# ifdef _WIN32
PROFILER_API void setLowPriorityEventTracing(bool _isLowPriority)
{
EasyEventTracer::instance().setLowPriority(_isLowPriority);
}
#else
# else
PROFILER_API void setLowPriorityEventTracing(bool) { }
#endif
# endif
PROFILER_API void setContextSwitchLogFilename(const char* name)
{
@ -165,23 +173,38 @@ extern "C" {
{
return MANAGER.stopListenSignalToCapture();
}
#else
PROFILER_API const BaseBlockDescriptor* registerDescription(EasyBlockStatus, const char*, const char*, const char*, int, block_type_t, color_t) { return reinterpret_cast<const BaseBlockDescriptor*>(0xbad); }
PROFILER_API void endBlock() { }
PROFILER_API void setEnabled(bool) { }
PROFILER_API void storeEvent(const BaseBlockDescriptor*, const char*) { }
PROFILER_API void beginBlock(Block&) { }
PROFILER_API uint32_t dumpBlocksToFile(const char*) { return 0; }
PROFILER_API const char* registerThread(const char*, ThreadGuard&) { return ""; }
PROFILER_API void setEventTracingEnabled(bool) { }
PROFILER_API void setLowPriorityEventTracing(bool) { }
PROFILER_API void setContextSwitchLogFilename(const char*) { }
PROFILER_API const char* getContextSwitchLogFilename() { return ""; }
PROFILER_API void startListenSignalToCapture() { }
PROFILER_API void stopListenSignalToCapture() { }
#endif
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;
static_assert(0 <= EASY_PROFILER_VERSION_MAJOR && EASY_PROFILER_VERSION_MAJOR <= 255, "EASY_PROFILER_VERSION_MAJOR must be defined in range [0, 255]");
return EASY_PROFILER_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;
static_assert(0 <= EASY_PROFILER_VERSION_MINOR && EASY_PROFILER_VERSION_MINOR <= 255, "EASY_PROFILER_VERSION_MINOR must be defined in range [0, 255]");
return EASY_PROFILER_VERSION_MINOR;
}
PROFILER_API uint16_t versionRev()
PROFILER_API uint16_t versionPatch()
{
static_assert(EASY_VERSION_REV >= 0 && EASY_VERSION_REV < 65536, "EASY_VERSION_REV must be defined in range [0, 65535]");
return EASY_VERSION_REV;
static_assert(0 <= EASY_PROFILER_VERSION_PATCH && EASY_PROFILER_VERSION_PATCH <= 65535, "EASY_PROFILER_VERSION_PATCH must be defined in range [0, 65535]");
return EASY_PROFILER_VERSION_PATCH;
}
PROFILER_API uint32_t version()
@ -191,11 +214,17 @@ extern "C" {
PROFILER_API const char* versionName()
{
return EASY_VERSION_NAME.c_str();
return EASY_PROFILER_PRODUCT_VERSION
#ifdef EASY_PROFILER_API_DISABLED
"_disabled"
#endif
;
}
}
//////////////////////////////////////////////////////////////////////////
SerializedBlock::SerializedBlock(const Block& block, uint16_t name_length)
: BaseBlockData(block)
{
@ -331,12 +360,14 @@ void ThreadStorage::clearClosed()
ThreadGuard::~ThreadGuard()
{
#ifndef EASY_PROFILER_API_DISABLED
if (m_id != 0 && THREAD_STORAGE != nullptr && THREAD_STORAGE->id == m_id)
{
EASY_EVENT("ThreadFinished", profiler::colors::Dark);
THREAD_STORAGE->expired.store(true, std::memory_order_release);
THREAD_STORAGE = nullptr;
}
#endif
}
//////////////////////////////////////////////////////////////////////////
@ -350,7 +381,9 @@ ProfileManager::ProfileManager()
ProfileManager::~ProfileManager()
{
#ifndef EASY_PROFILER_API_DISABLED
stopListenSignalToCapture();
#endif
for (auto desc : m_descriptors)
{

View File

@ -67,15 +67,18 @@
//////////////////////////////////////////////////////////////////////////
const uint32_t EASY_CURRENT_VERSION = EASY_VERSION_INT(EASY_VERSION_MAJOR, EASY_VERSION_MINOR, EASY_VERSION_REV);
extern const uint32_t PROFILER_SIGNATURE;
extern const uint32_t EASY_CURRENT_VERSION;
# define EASY_VERSION_INT(v_major, v_minor, v_patch) ((static_cast<uint32_t>(v_major) << 24) | (static_cast<uint32_t>(v_minor) << 16) | static_cast<uint32_t>(v_patch))
const uint32_t COMPATIBLE_VERSIONS[] = {
EASY_CURRENT_VERSION,
EASY_VERSION_INT(0, 1, 0)
};
const uint16_t COMPATIBLE_VERSIONS_NUM = sizeof(COMPATIBLE_VERSIONS) / sizeof(uint32_t);
# undef EASY_VERSION_INT
const int64_t TIME_FACTOR = 1000000000LL;
const uint32_t PROFILER_SIGNATURE = ('E' << 24) | ('a' << 16) | ('s' << 8) | 'y';
//////////////////////////////////////////////////////////////////////////
@ -766,7 +769,7 @@ extern "C" {
inFile.read((char*)&signature, sizeof(uint32_t));
if (signature != PROFILER_SIGNATURE)
{
_log << "Wrong signature " << signature << "\nThis is not EasyProfiler file/stream.";
_log << "Wrong file signature.\nThis is not EasyProfiler file/stream.";
return false;
}

View File

@ -1,6 +1,6 @@
1 VERSIONINFO
FILEVERSION EASY_VERSION_MAJOR, EASY_VERSION_MINOR, EASY_VERSION_REV
PRODUCTVERSION EASY_VERSION_MAJOR, EASY_VERSION_MINOR, EASY_VERSION_REV
FILEVERSION EASY_PROFILER_VERSION_MAJOR, EASY_PROFILER_VERSION_MINOR, EASY_PROFILER_VERSION_PATCH
PRODUCTVERSION EASY_PROFILER_VERSION_MAJOR, EASY_PROFILER_VERSION_MINOR, EASY_PROFILER_VERSION_PATCH
BEGIN
BLOCK "StringFileInfo"
BEGIN
@ -8,7 +8,7 @@ BEGIN
BEGIN
VALUE "CompanyName", "EasyProfiler Team"
VALUE "FileDescription", "Lightweight profiler library for c++"
VALUE "LegalCopyright", "Copyright 2016 Victor Zarubkin, Sergey Yagovtsev"
VALUE "LegalCopyright", "Copyright (C) 2016 Victor Zarubkin, Sergey Yagovtsev"
VALUE "LegalTrademarks1", "All Rights Reserved"
VALUE "LegalTrademarks2", "All Rights Reserved"
VALUE "ProductName", "easy_profiler lib"