2016-09-11 16:57:35 +03:00
|
|
|
/************************************************************************
|
|
|
|
* file name : profiler_aux.h
|
|
|
|
* ----------------- :
|
|
|
|
* creation time : 2016/06/11
|
|
|
|
* author : Victor Zarubkin
|
|
|
|
* email : v.s.zarubkin@gmail.com
|
|
|
|
* ----------------- :
|
|
|
|
* description : This file contains auxiliary profiler macros and funcitons.
|
|
|
|
* ----------------- :
|
|
|
|
* change log : * 2016/06/11 Victor Zarubkin: Moved sources from profiler.h
|
|
|
|
* :
|
|
|
|
* : *
|
|
|
|
* ----------------- :
|
|
|
|
* license : Lightweight profiler library for c++
|
|
|
|
* : Copyright(C) 2016 Sergey Yagovtsev, Victor Zarubkin
|
|
|
|
* :
|
|
|
|
* : This program is free software : you can redistribute it and / or modify
|
|
|
|
* : it under the terms of the GNU General Public License as published by
|
|
|
|
* : the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* : (at your option) any later version.
|
|
|
|
* :
|
|
|
|
* : This program is distributed in the hope that it will be useful,
|
|
|
|
* : but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
|
|
* : GNU General Public License for more details.
|
|
|
|
* :
|
|
|
|
* : You should have received a copy of the GNU General Public License
|
|
|
|
* : along with this program.If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#ifndef EASY_PROFILER__AUX__H_______
|
|
|
|
#define EASY_PROFILER__AUX__H_______
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2016-09-29 23:29:57 +03:00
|
|
|
#include "easy/easy_compiler_support.h"
|
|
|
|
#include "easy/profiler_colors.h"
|
2016-09-11 16:57:35 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace profiler {
|
|
|
|
|
2016-09-20 22:57:34 +03:00
|
|
|
enum EasyBlockStatus : uint8_t {
|
|
|
|
OFF = 0, ///< The block is OFF
|
|
|
|
ON = 1, ///< The block is ON (but if it's parent block is off recursively then this block will be off too)
|
|
|
|
FORCE_ON = ON | 2, ///< The block is ALWAYS ON (even if it's parent has turned off all children)
|
|
|
|
OFF_RECURSIVE = 4, ///< The block is OFF and all of it's children by call-stack are also OFF.
|
|
|
|
ON_WITHOUT_CHILDREN = ON | OFF_RECURSIVE, ///< The block is ON but all of it's children are OFF.
|
|
|
|
FORCE_ON_WITHOUT_CHILDREN = FORCE_ON | OFF_RECURSIVE, ///< The block is ALWAYS ON but all of it's children are OFF.
|
2016-09-11 16:57:35 +03:00
|
|
|
};
|
|
|
|
|
2016-09-29 23:08:20 +03:00
|
|
|
struct passthrough_hash EASY_FINAL {
|
|
|
|
template <class T> inline size_t operator () (T _value) const {
|
|
|
|
return static_cast<size_t>(_value);
|
|
|
|
}
|
2016-09-13 23:03:01 +03:00
|
|
|
};
|
|
|
|
|
2016-09-11 16:57:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <type_traits>
|
2016-09-29 23:29:57 +03:00
|
|
|
#include <string>
|
2016-09-11 16:57:35 +03:00
|
|
|
|
2016-11-16 22:17:39 +03:00
|
|
|
# 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))
|
2016-09-11 16:57:35 +03:00
|
|
|
# define EASY_STRINGIFY(a) #a
|
2016-09-13 23:03:01 +03:00
|
|
|
# define EASY_STRINGIFICATION(a) EASY_STRINGIFY(a)
|
2016-09-11 16:57:35 +03:00
|
|
|
# define EASY_TOKEN_JOIN(x, y) x ## y
|
|
|
|
# define EASY_TOKEN_CONCATENATE(x, y) EASY_TOKEN_JOIN(x, y)
|
|
|
|
# define EASY_UNIQUE_BLOCK(x) EASY_TOKEN_CONCATENATE(unique_profiler_mark_name_, x)
|
|
|
|
# define EASY_UNIQUE_DESC(x) EASY_TOKEN_CONCATENATE(unique_profiler_descriptor_, x)
|
|
|
|
|
2016-09-29 23:08:20 +03:00
|
|
|
#ifdef BUILD_WITH_EASY_PROFILER
|
|
|
|
|
2016-09-11 16:57:35 +03:00
|
|
|
namespace profiler {
|
|
|
|
|
2016-09-22 23:06:43 +03:00
|
|
|
template <const bool IS_REF> struct NameSwitch EASY_FINAL {
|
2016-09-11 16:57:35 +03:00
|
|
|
static const char* runtime_name(const char* name) { return name; }
|
2016-09-29 23:29:57 +03:00
|
|
|
static const char* runtime_name(const std::string& name) { return name.c_str(); }
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
static const char* compiletime_name(const T&, const char* autoGeneratedName) { return autoGeneratedName; }
|
2016-09-11 16:57:35 +03:00
|
|
|
static const char* compiletime_name(const char*, const char* autoGeneratedName) { return autoGeneratedName; }
|
|
|
|
};
|
|
|
|
|
2016-09-22 23:06:43 +03:00
|
|
|
template <> struct NameSwitch<true> EASY_FINAL {
|
2016-09-11 16:57:35 +03:00
|
|
|
static const char* runtime_name(const char*) { return ""; }
|
2016-09-29 23:29:57 +03:00
|
|
|
static const char* runtime_name(const std::string& name) { return name.c_str(); }
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
static const char* compiletime_name(const T&, const char* autoGeneratedName) { return autoGeneratedName; }
|
2016-09-11 16:57:35 +03:00
|
|
|
static const char* compiletime_name(const char* name, const char*) { return name; }
|
|
|
|
};
|
|
|
|
|
|
|
|
//***********************************************
|
|
|
|
|
|
|
|
inline color_t extract_color() {
|
|
|
|
return ::profiler::colors::Default;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ... TArgs>
|
2016-09-20 22:57:34 +03:00
|
|
|
inline color_t extract_color(::profiler::EasyBlockStatus, TArgs...) {
|
2016-09-11 16:57:35 +03:00
|
|
|
return ::profiler::colors::Default;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ... TArgs>
|
|
|
|
inline color_t extract_color(color_t _color, TArgs...) {
|
|
|
|
return _color;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class ... TArgs>
|
|
|
|
inline color_t extract_color(T, color_t _color, TArgs...) {
|
|
|
|
return _color;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ... TArgs>
|
|
|
|
inline color_t extract_color(TArgs...) {
|
2016-09-11 19:34:01 +03:00
|
|
|
static_assert(sizeof...(TArgs) < 2, "No profiler::color_t in arguments list for EASY_BLOCK(name, ...)!");
|
2016-09-11 16:57:35 +03:00
|
|
|
return ::profiler::colors::Default;
|
|
|
|
}
|
|
|
|
|
|
|
|
//***********************************************
|
|
|
|
|
2016-09-20 22:57:34 +03:00
|
|
|
inline EasyBlockStatus extract_enable_flag() {
|
|
|
|
return ::profiler::ON;
|
2016-09-11 16:57:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class ... TArgs>
|
2016-09-20 22:57:34 +03:00
|
|
|
inline EasyBlockStatus extract_enable_flag(T, ::profiler::EasyBlockStatus _flag, TArgs...) {
|
|
|
|
return _flag;
|
2016-09-11 16:57:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ... TArgs>
|
2016-09-20 22:57:34 +03:00
|
|
|
inline EasyBlockStatus extract_enable_flag(::profiler::EasyBlockStatus _flag, TArgs...) {
|
|
|
|
return _flag;
|
2016-09-11 16:57:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ... TArgs>
|
2016-09-20 22:57:34 +03:00
|
|
|
inline EasyBlockStatus extract_enable_flag(TArgs...) {
|
|
|
|
static_assert(sizeof...(TArgs) < 2, "No EasyBlockStatus in arguments list for EASY_BLOCK(name, ...)!");
|
|
|
|
return ::profiler::ON;
|
2016-09-11 16:57:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//***********************************************
|
|
|
|
|
|
|
|
} // END of namespace profiler.
|
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
# define EASY_UNIQUE_LINE_ID __FILE__ ":" EASY_STRINGIFICATION(__LINE__)
|
2016-09-11 16:57:35 +03:00
|
|
|
# define EASY_COMPILETIME_NAME(name) ::profiler::NameSwitch<::std::is_reference<decltype(name)>::value>::compiletime_name(name, EASY_UNIQUE_LINE_ID)
|
|
|
|
# define EASY_RUNTIME_NAME(name) ::profiler::NameSwitch<::std::is_reference<decltype(name)>::value>::runtime_name(name)
|
|
|
|
|
2016-09-29 23:08:20 +03:00
|
|
|
#endif // BUILD_WITH_EASY_PROFILER
|
2016-09-11 16:57:35 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#endif // EASY_PROFILER__AUX__H_______
|