From c2de745445c4273c5243fa41c70aa78f411ddc5a Mon Sep 17 00:00:00 2001 From: Victor Zarubkin Date: Thu, 9 Nov 2017 22:01:32 +0300 Subject: [PATCH] #0 [Core] Rearranged include files --- easy_profiler_core/CMakeLists.txt | 11 +- easy_profiler_core/chunk_allocator.h | 2 +- .../include/easy/arbitrary_value.h | 213 ++++-------------- .../easy/{ => details}/arbitrary_value_aux.h | 5 +- .../details/arbitrary_value_public_types.h | 198 ++++++++++++++++ .../{ => details}/easy_compiler_support.h | 0 .../include/easy/{ => details}/profiler_aux.h | 4 +- .../easy/{ => details}/profiler_colors.h | 0 .../{ => details}/profiler_public_types.h | 2 +- easy_profiler_core/include/easy/profiler.h | 2 +- 10 files changed, 254 insertions(+), 183 deletions(-) rename easy_profiler_core/include/easy/{ => details}/arbitrary_value_aux.h (97%) create mode 100644 easy_profiler_core/include/easy/details/arbitrary_value_public_types.h rename easy_profiler_core/include/easy/{ => details}/easy_compiler_support.h (100%) rename easy_profiler_core/include/easy/{ => details}/profiler_aux.h (99%) rename easy_profiler_core/include/easy/{ => details}/profiler_colors.h (100%) rename easy_profiler_core/include/easy/{ => details}/profiler_public_types.h (99%) diff --git a/easy_profiler_core/CMakeLists.txt b/easy_profiler_core/CMakeLists.txt index 4b87e79..4c0d00c 100644 --- a/easy_profiler_core/CMakeLists.txt +++ b/easy_profiler_core/CMakeLists.txt @@ -128,15 +128,18 @@ set(H_FILES ) set(INCLUDE_FILES + include/easy/arbitrary_value.h include/easy/easy_net.h include/easy/easy_socket.h - include/easy/easy_compiler_support.h include/easy/profiler.h - include/easy/profiler_aux.h - include/easy/profiler_colors.h include/easy/reader.h include/easy/serialized_block.h - include/easy/profiler_public_types.h + include/easy/details/arbitrary_value_aux.h + include/easy/details/arbitrary_value_public_types.h + include/easy/details/easy_compiler_support.h + include/easy/details/profiler_aux.h + include/easy/details/profiler_colors.h + include/easy/details/profiler_public_types.h ) source_group(include FILES ${INCLUDE_FILES}) diff --git a/easy_profiler_core/chunk_allocator.h b/easy_profiler_core/chunk_allocator.h index b475620..c189cf3 100644 --- a/easy_profiler_core/chunk_allocator.h +++ b/easy_profiler_core/chunk_allocator.h @@ -43,7 +43,7 @@ The Apache License, Version 2.0 (the "License"); #ifndef EASY_PROFILER_CHUNK_ALLOCATOR_H #define EASY_PROFILER_CHUNK_ALLOCATOR_H -#include +#include #include #include #include diff --git a/easy_profiler_core/include/easy/arbitrary_value.h b/easy_profiler_core/include/easy/arbitrary_value.h index d967e9a..105c0c9 100644 --- a/easy_profiler_core/include/easy/arbitrary_value.h +++ b/easy_profiler_core/include/easy/arbitrary_value.h @@ -43,8 +43,12 @@ The Apache License, Version 2.0 (the "License"); #ifndef EASY_PROFILER_ARBITRARY_VALUE_H #define EASY_PROFILER_ARBITRARY_VALUE_H -#include -#include +#include + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" +#endif #ifdef USING_EASY_PROFILER @@ -62,174 +66,11 @@ The Apache License, Version 2.0 (the "License"); __FILE__, __LINE__, ::profiler::BLOCK_TYPE_VALUE, ::profiler::extract_color(__VA_ARGS__), false));\ ::profiler::setValue(EASY_UNIQUE_DESC(__LINE__), text, ::profiler::extract_value_id(text , ## __VA_ARGS__)); -#else - -# define EASY_VIN(member) -# define EASY_VALUE(...) -# define EASY_TEXT(...) - -#endif - namespace profiler { - enum class DataType : uint8_t - { - Bool = 0, - Char, - Int8, - Uint8, - Int16, - Uint16, - Int32, - Uint32, - Int64, - Uint64, - Float, - Double, - String, - - TypesCount - }; - - namespace { - template struct StdType; - template struct StdToDataType; - - template <> struct StdType { using value_type = bool ; }; - template <> struct StdType { using value_type = char ; }; - template <> struct StdType { using value_type = int8_t ; }; - template <> struct StdType { using value_type = uint8_t ; }; - template <> struct StdType { using value_type = int16_t ; }; - template <> struct StdType { using value_type = uint16_t; }; - template <> struct StdType { using value_type = int32_t ; }; - template <> struct StdType { using value_type = uint32_t; }; - template <> struct StdType { using value_type = int64_t ; }; - template <> struct StdType { using value_type = uint64_t; }; - template <> struct StdType { using value_type = float ; }; - template <> struct StdType { using value_type = double ; }; - template <> struct StdType { using value_type = char ; }; - - template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataType::Bool ; }; - template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataType::Char ; }; - template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataType::Int8 ; }; - template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataType::Uint8 ; }; - template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataType::Int16 ; }; - template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataType::Uint16; }; - template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataType::Int32 ; }; - template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataType::Uint32; }; - template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataType::Int64 ; }; - template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataType::Uint64; }; - template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataType::Float ; }; - template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataType::Double; }; - template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataType::String; }; - } - - template - struct Value; - - template - struct Value; - - - -#pragma pack(push, 1) - class PROFILER_API ArbitraryValue : protected BaseBlockData - { - friend ::ThreadStorage; - - protected: - - uint16_t m_size; - DataType m_type; - bool m_isArray; - - ArbitraryValue(vin_t _vin, block_id_t _id, uint16_t _size, DataType _type, bool _isArray) - : BaseBlockData(0, static_cast(_vin), _id) - , m_size(_size) - , m_type(_type) - , m_isArray(_isArray) - { - } - - public: - - const char* data() const { - return reinterpret_cast(this) + sizeof(ArbitraryValue); - } - - vin_t value_id() const { - return static_cast(m_end); - } - - template - const Value* convertToValue() const { - return m_type == dataType ? static_cast*>(this) : nullptr; - } - - template - const Value::data_type, false>* convertToValue() const { - return convertToValue::data_type>(); - } - - template - const Value* convertToArray() const { - return m_isArray && m_type == dataType ? static_cast*>(this) : nullptr; - } - - template - const Value::data_type, true>* convertToArray() const { - return convertToArray::data_type>(); - } - }; -#pragma pack(pop) - - - - template struct Value : public ArbitraryValue { - using value_type = typename StdType::value_type; - value_type value() const { return *reinterpret_cast(data()); } - }; - - - template struct Value : public ArbitraryValue { - using value_type = typename StdType::value_type; - const value_type* value() const { return reinterpret_cast(data()); } - uint16_t size() const { return m_size / sizeof(value_type); } - value_type operator [] (int i) const { return value()[i]; } - }; - - - template <> struct Value : public ArbitraryValue { - using value_type = char; - const char* value() const { return data(); } - uint16_t size() const { return m_size; } - char operator [] (int i) const { return data()[i]; } - const char* c_str() const { return data(); } - }; - - - template - using SingleValue = Value; - - - template - using ArrayValue = Value; - - - using StringValue = Value; - - - -#ifdef USING_EASY_PROFILER - extern "C" { - PROFILER_API void storeValue(const BaseBlockDescriptor* _desc, DataType _type, const void* _data, size_t _size, bool _isArray, ValueId _vin); - } -#else - inline void storeValue(const BaseBlockDescriptor*, DataType, const void*, size_t, bool, ValueId) {} -#endif - - + extern "C" PROFILER_API void storeValue(const BaseBlockDescriptor* _desc, DataType _type, const void* _data, + size_t _size, bool _isArray, ValueId _vin); template inline void setValue(const BaseBlockDescriptor* _desc, T _value, ValueId _vin) @@ -237,26 +78,22 @@ namespace profiler storeValue(_desc, StdToDataType::data_type, &_value, sizeof(T), false, _vin); } - template inline void setValue(const BaseBlockDescriptor* _desc, const T (&_value)[N], ValueId _vin) { storeValue(_desc, StdToDataType::data_type, &_value[0], sizeof(_value), true, _vin); } - inline void setText(const BaseBlockDescriptor* _desc, const char* _text, ValueId _vin) { storeValue(_desc, DataType::String, _text, strlen(_text) + 1, true, _vin); } - - inline void setText(const BaseBlockDescriptor* _desc, const std::string& _text, ValueId _vin) + inline void setText(const BaseBlockDescriptor* _desc, const ::std::string& _text, ValueId _vin) { storeValue(_desc, DataType::String, _text.c_str(), _text.size() + 1, true, _vin); } - template inline void setText(const BaseBlockDescriptor* _desc, const char (&_text)[N], ValueId _vin) { @@ -265,4 +102,36 @@ namespace profiler } // end of namespace profiler. +#else + +# define EASY_VIN(member) +# define EASY_VALUE(...) +# define EASY_TEXT(...) + +namespace profiler +{ + + inline void storeValue(const BaseBlockDescriptor*, DataType, const void*, size_t, bool, ValueId) {} + + template + inline void setValue(const BaseBlockDescriptor*, T, ValueId) {} + + template + inline void setValue(const BaseBlockDescriptor*, const T (&)[N], ValueId) {} + + inline void setText(const BaseBlockDescriptor*, const char*, ValueId) {} + + inline void setText(const BaseBlockDescriptor*, const ::std::string&, ValueId) {} + + template + inline void setText(const BaseBlockDescriptor*, const char (&)[N], ValueId) {} + +} // end of namespace profiler. + +#endif // USING_EASY_PROFILER + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + #endif // EASY_PROFILER_ARBITRARY_VALUE_H diff --git a/easy_profiler_core/include/easy/arbitrary_value_aux.h b/easy_profiler_core/include/easy/details/arbitrary_value_aux.h similarity index 97% rename from easy_profiler_core/include/easy/arbitrary_value_aux.h rename to easy_profiler_core/include/easy/details/arbitrary_value_aux.h index 35d8ef4..1123fc5 100644 --- a/easy_profiler_core/include/easy/arbitrary_value_aux.h +++ b/easy_profiler_core/include/easy/details/arbitrary_value_aux.h @@ -43,7 +43,8 @@ The Apache License, Version 2.0 (the "License"); #ifndef EASY_PROFILER_ARBITRARY_VALUE_AUX_H #define EASY_PROFILER_ARBITRARY_VALUE_AUX_H -#include +#include +#include namespace profiler { @@ -92,7 +93,7 @@ namespace profiler template static EASY_CONSTEXPR_FCN ValueId get(const T&, TArgs... _args) { return subextract_value_id(_args...); } }; - } + } // end of noname namespace. template inline EASY_CONSTEXPR_FCN ValueId extract_value_id(const T& _first, TArgs... _args) { diff --git a/easy_profiler_core/include/easy/details/arbitrary_value_public_types.h b/easy_profiler_core/include/easy/details/arbitrary_value_public_types.h new file mode 100644 index 0000000..fccdffe --- /dev/null +++ b/easy_profiler_core/include/easy/details/arbitrary_value_public_types.h @@ -0,0 +1,198 @@ +/** +Lightweight profiler library for c++ +Copyright(C) 2016-2017 Sergey Yagovtsev, Victor Zarubkin + +Licensed under either of + * MIT license (LICENSE.MIT or http://opensource.org/licenses/MIT) + * Apache License, Version 2.0, (LICENSE.APACHE or http://www.apache.org/licenses/LICENSE-2.0) +at your option. + +The MIT License + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished + to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. + + +The Apache License, Version 2.0 (the "License"); + You may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +**/ + +#ifndef EASY_PROFILER_ARBITRARY_VALUE_PUBLIC_TYPES_H +#define EASY_PROFILER_ARBITRARY_VALUE_PUBLIC_TYPES_H + +#include +#include +#include + +namespace profiler +{ + + enum class DataType : uint8_t + { + Bool = 0, + Char, + Int8, + Uint8, + Int16, + Uint16, + Int32, + Uint32, + Int64, + Uint64, + Float, + Double, + String, + + TypesCount + }; // end of enum class DataType. + + namespace { + template struct StdType; + template struct StdToDataType; + +# define EASY_DATATYPE_CONVERSION(DataTypeName, StdTypeName)\ + template <> struct StdType { using value_type = StdTypeName; };\ + template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataTypeName; } + + EASY_DATATYPE_CONVERSION(DataType::Bool , bool ); + EASY_DATATYPE_CONVERSION(DataType::Char , char ); + EASY_DATATYPE_CONVERSION(DataType::Int8 , int8_t ); + EASY_DATATYPE_CONVERSION(DataType::Uint8 , uint8_t ); + EASY_DATATYPE_CONVERSION(DataType::Int16 , int16_t ); + EASY_DATATYPE_CONVERSION(DataType::Uint16, uint16_t); + EASY_DATATYPE_CONVERSION(DataType::Int32 , int32_t ); + EASY_DATATYPE_CONVERSION(DataType::Uint32, uint32_t); + EASY_DATATYPE_CONVERSION(DataType::Int64 , int64_t ); + EASY_DATATYPE_CONVERSION(DataType::Uint64, uint64_t); + EASY_DATATYPE_CONVERSION(DataType::Float , float ); + EASY_DATATYPE_CONVERSION(DataType::Double, double ); + +# undef EASY_DATATYPE_CONVERSION + + template <> struct StdType { using value_type = char; }; + template <> struct StdToDataType { EASY_STATIC_CONSTEXPR auto data_type = DataType::String; }; + } // end of noname namespace. + + + + template + struct Value; + + template + struct Value; + + + +#pragma pack(push, 1) + class PROFILER_API ArbitraryValue : protected BaseBlockData + { + friend ::ThreadStorage; + + protected: + + uint16_t m_size; + DataType m_type; + bool m_isArray; + + ArbitraryValue(vin_t _vin, block_id_t _id, uint16_t _size, DataType _type, bool _isArray) + : BaseBlockData(0, static_cast(_vin), _id) + , m_size(_size) + , m_type(_type) + , m_isArray(_isArray) + { + } + + public: + + const char* data() const { + return reinterpret_cast(this) + sizeof(ArbitraryValue); + } + + vin_t value_id() const { + return static_cast(m_end); + } + + template + const Value* convertToValue() const { + return m_type == dataType ? static_cast*>(this) : nullptr; + } + + template + const Value::data_type, false>* convertToValue() const { + return convertToValue::data_type>(); + } + + template + const Value* convertToArray() const { + return m_isArray && m_type == dataType ? static_cast*>(this) : nullptr; + } + + template + const Value::data_type, true>* convertToArray() const { + return convertToArray::data_type>(); + } + }; // end of class ArbitraryValue. +#pragma pack(pop) + + + + template + struct Value EASY_FINAL : public ArbitraryValue { + using value_type = typename StdType::value_type; + value_type value() const { return *reinterpret_cast(data()); } + }; + + + template + struct Value EASY_FINAL : public ArbitraryValue { + using value_type = typename StdType::value_type; + const value_type* value() const { return reinterpret_cast(data()); } + uint16_t size() const { return m_size / sizeof(value_type); } + value_type operator [] (int i) const { return value()[i]; } + }; + + + template <> + struct Value EASY_FINAL : public ArbitraryValue { + using value_type = char; + const char* value() const { return data(); } + uint16_t size() const { return m_size; } + char operator [] (int i) const { return data()[i]; } + const char* c_str() const { return data(); } + }; + + + template + using SingleValue = Value; + + template + using ArrayValue = Value; + + using StringValue = Value; + +} // end of namespace profiler. + +#endif //EASY_PROFILER_ARBITRARY_VALUE_PUBLIC_TYPES_H diff --git a/easy_profiler_core/include/easy/easy_compiler_support.h b/easy_profiler_core/include/easy/details/easy_compiler_support.h similarity index 100% rename from easy_profiler_core/include/easy/easy_compiler_support.h rename to easy_profiler_core/include/easy/details/easy_compiler_support.h diff --git a/easy_profiler_core/include/easy/profiler_aux.h b/easy_profiler_core/include/easy/details/profiler_aux.h similarity index 99% rename from easy_profiler_core/include/easy/profiler_aux.h rename to easy_profiler_core/include/easy/details/profiler_aux.h index d8b496a..5de76b2 100644 --- a/easy_profiler_core/include/easy/profiler_aux.h +++ b/easy_profiler_core/include/easy/details/profiler_aux.h @@ -57,8 +57,8 @@ #include -#include -#include +#include +#include ////////////////////////////////////////////////////////////////////////// diff --git a/easy_profiler_core/include/easy/profiler_colors.h b/easy_profiler_core/include/easy/details/profiler_colors.h similarity index 100% rename from easy_profiler_core/include/easy/profiler_colors.h rename to easy_profiler_core/include/easy/details/profiler_colors.h diff --git a/easy_profiler_core/include/easy/profiler_public_types.h b/easy_profiler_core/include/easy/details/profiler_public_types.h similarity index 99% rename from easy_profiler_core/include/easy/profiler_public_types.h rename to easy_profiler_core/include/easy/details/profiler_public_types.h index f176540..f6543d2 100644 --- a/easy_profiler_core/include/easy/profiler_public_types.h +++ b/easy_profiler_core/include/easy/details/profiler_public_types.h @@ -43,7 +43,7 @@ The Apache License, Version 2.0 (the "License"); #ifndef EASY_PROFILER_PUBLIC_TYPES_H #define EASY_PROFILER_PUBLIC_TYPES_H -#include +#include class NonscopedBlock; class ProfileManager; diff --git a/easy_profiler_core/include/easy/profiler.h b/easy_profiler_core/include/easy/profiler.h index edf0742..901f638 100644 --- a/easy_profiler_core/include/easy/profiler.h +++ b/easy_profiler_core/include/easy/profiler.h @@ -43,7 +43,7 @@ The Apache License, Version 2.0 (the "License"); #ifndef EASY_PROFILER_H #define EASY_PROFILER_H -#include +#include #if defined ( __clang__ ) # pragma clang diagnostic push