mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-27 16:51:22 +08:00
#0 [Core] Rearranged include files
This commit is contained in:
parent
8509b9b01b
commit
c2de745445
@ -128,15 +128,18 @@ set(H_FILES
|
|||||||
)
|
)
|
||||||
|
|
||||||
set(INCLUDE_FILES
|
set(INCLUDE_FILES
|
||||||
|
include/easy/arbitrary_value.h
|
||||||
include/easy/easy_net.h
|
include/easy/easy_net.h
|
||||||
include/easy/easy_socket.h
|
include/easy/easy_socket.h
|
||||||
include/easy/easy_compiler_support.h
|
|
||||||
include/easy/profiler.h
|
include/easy/profiler.h
|
||||||
include/easy/profiler_aux.h
|
|
||||||
include/easy/profiler_colors.h
|
|
||||||
include/easy/reader.h
|
include/easy/reader.h
|
||||||
include/easy/serialized_block.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})
|
source_group(include FILES ${INCLUDE_FILES})
|
||||||
|
@ -43,7 +43,7 @@ The Apache License, Version 2.0 (the "License");
|
|||||||
#ifndef EASY_PROFILER_CHUNK_ALLOCATOR_H
|
#ifndef EASY_PROFILER_CHUNK_ALLOCATOR_H
|
||||||
#define EASY_PROFILER_CHUNK_ALLOCATOR_H
|
#define EASY_PROFILER_CHUNK_ALLOCATOR_H
|
||||||
|
|
||||||
#include <easy/easy_compiler_support.h>
|
#include <easy/details/easy_compiler_support.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -43,8 +43,12 @@ The Apache License, Version 2.0 (the "License");
|
|||||||
#ifndef EASY_PROFILER_ARBITRARY_VALUE_H
|
#ifndef EASY_PROFILER_ARBITRARY_VALUE_H
|
||||||
#define EASY_PROFILER_ARBITRARY_VALUE_H
|
#define EASY_PROFILER_ARBITRARY_VALUE_H
|
||||||
|
|
||||||
#include <easy/arbitrary_value_aux.h>
|
#include <easy/details/arbitrary_value_public_types.h>
|
||||||
#include <string.h>
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
# pragma clang diagnostic push
|
||||||
|
# pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USING_EASY_PROFILER
|
#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));\
|
__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__));
|
::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
|
namespace profiler
|
||||||
{
|
{
|
||||||
|
|
||||||
enum class DataType : uint8_t
|
extern "C" PROFILER_API void storeValue(const BaseBlockDescriptor* _desc, DataType _type, const void* _data,
|
||||||
{
|
size_t _size, bool _isArray, ValueId _vin);
|
||||||
Bool = 0,
|
|
||||||
Char,
|
|
||||||
Int8,
|
|
||||||
Uint8,
|
|
||||||
Int16,
|
|
||||||
Uint16,
|
|
||||||
Int32,
|
|
||||||
Uint32,
|
|
||||||
Int64,
|
|
||||||
Uint64,
|
|
||||||
Float,
|
|
||||||
Double,
|
|
||||||
String,
|
|
||||||
|
|
||||||
TypesCount
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
template <DataType dataType> struct StdType;
|
|
||||||
template <class T> struct StdToDataType;
|
|
||||||
|
|
||||||
template <> struct StdType<DataType::Bool > { using value_type = bool ; };
|
|
||||||
template <> struct StdType<DataType::Char > { using value_type = char ; };
|
|
||||||
template <> struct StdType<DataType::Int8 > { using value_type = int8_t ; };
|
|
||||||
template <> struct StdType<DataType::Uint8 > { using value_type = uint8_t ; };
|
|
||||||
template <> struct StdType<DataType::Int16 > { using value_type = int16_t ; };
|
|
||||||
template <> struct StdType<DataType::Uint16> { using value_type = uint16_t; };
|
|
||||||
template <> struct StdType<DataType::Int32 > { using value_type = int32_t ; };
|
|
||||||
template <> struct StdType<DataType::Uint32> { using value_type = uint32_t; };
|
|
||||||
template <> struct StdType<DataType::Int64 > { using value_type = int64_t ; };
|
|
||||||
template <> struct StdType<DataType::Uint64> { using value_type = uint64_t; };
|
|
||||||
template <> struct StdType<DataType::Float > { using value_type = float ; };
|
|
||||||
template <> struct StdType<DataType::Double> { using value_type = double ; };
|
|
||||||
template <> struct StdType<DataType::String> { using value_type = char ; };
|
|
||||||
|
|
||||||
template <> struct StdToDataType<bool > { EASY_STATIC_CONSTEXPR auto data_type = DataType::Bool ; };
|
|
||||||
template <> struct StdToDataType<char > { EASY_STATIC_CONSTEXPR auto data_type = DataType::Char ; };
|
|
||||||
template <> struct StdToDataType<int8_t > { EASY_STATIC_CONSTEXPR auto data_type = DataType::Int8 ; };
|
|
||||||
template <> struct StdToDataType<uint8_t > { EASY_STATIC_CONSTEXPR auto data_type = DataType::Uint8 ; };
|
|
||||||
template <> struct StdToDataType<int16_t > { EASY_STATIC_CONSTEXPR auto data_type = DataType::Int16 ; };
|
|
||||||
template <> struct StdToDataType<uint16_t > { EASY_STATIC_CONSTEXPR auto data_type = DataType::Uint16; };
|
|
||||||
template <> struct StdToDataType<int32_t > { EASY_STATIC_CONSTEXPR auto data_type = DataType::Int32 ; };
|
|
||||||
template <> struct StdToDataType<uint32_t > { EASY_STATIC_CONSTEXPR auto data_type = DataType::Uint32; };
|
|
||||||
template <> struct StdToDataType<int64_t > { EASY_STATIC_CONSTEXPR auto data_type = DataType::Int64 ; };
|
|
||||||
template <> struct StdToDataType<uint64_t > { EASY_STATIC_CONSTEXPR auto data_type = DataType::Uint64; };
|
|
||||||
template <> struct StdToDataType<float > { EASY_STATIC_CONSTEXPR auto data_type = DataType::Float ; };
|
|
||||||
template <> struct StdToDataType<double > { EASY_STATIC_CONSTEXPR auto data_type = DataType::Double; };
|
|
||||||
template <> struct StdToDataType<const char*> { EASY_STATIC_CONSTEXPR auto data_type = DataType::String; };
|
|
||||||
}
|
|
||||||
|
|
||||||
template <DataType dataType, bool isArray>
|
|
||||||
struct Value;
|
|
||||||
|
|
||||||
template <bool isArray>
|
|
||||||
struct Value<DataType::TypesCount, isArray>;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#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<timestamp_t>(_vin), _id)
|
|
||||||
, m_size(_size)
|
|
||||||
, m_type(_type)
|
|
||||||
, m_isArray(_isArray)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
const char* data() const {
|
|
||||||
return reinterpret_cast<const char*>(this) + sizeof(ArbitraryValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
vin_t value_id() const {
|
|
||||||
return static_cast<vin_t>(m_end);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <DataType dataType>
|
|
||||||
const Value<dataType, false>* convertToValue() const {
|
|
||||||
return m_type == dataType ? static_cast<const Value<dataType, false>*>(this) : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
const Value<StdToDataType<T>::data_type, false>* convertToValue() const {
|
|
||||||
return convertToValue<StdToDataType<T>::data_type>();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <DataType dataType>
|
|
||||||
const Value<dataType, true>* convertToArray() const {
|
|
||||||
return m_isArray && m_type == dataType ? static_cast<const Value<dataType, true>*>(this) : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
const Value<StdToDataType<T>::data_type, true>* convertToArray() const {
|
|
||||||
return convertToArray<StdToDataType<T>::data_type>();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <DataType dataType> struct Value<dataType, false> : public ArbitraryValue {
|
|
||||||
using value_type = typename StdType<dataType>::value_type;
|
|
||||||
value_type value() const { return *reinterpret_cast<const value_type*>(data()); }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template <DataType dataType> struct Value<dataType, true> : public ArbitraryValue {
|
|
||||||
using value_type = typename StdType<dataType>::value_type;
|
|
||||||
const value_type* value() const { return reinterpret_cast<const value_type*>(data()); }
|
|
||||||
uint16_t size() const { return m_size / sizeof(value_type); }
|
|
||||||
value_type operator [] (int i) const { return value()[i]; }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template <> struct Value<DataType::String, true> : 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 <DataType dataType>
|
|
||||||
using SingleValue = Value<dataType, false>;
|
|
||||||
|
|
||||||
|
|
||||||
template <DataType dataType>
|
|
||||||
using ArrayValue = Value<dataType, true>;
|
|
||||||
|
|
||||||
|
|
||||||
using StringValue = Value<DataType::String, true>;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline void setValue(const BaseBlockDescriptor* _desc, T _value, ValueId _vin)
|
inline void setValue(const BaseBlockDescriptor* _desc, T _value, ValueId _vin)
|
||||||
@ -237,26 +78,22 @@ namespace profiler
|
|||||||
storeValue(_desc, StdToDataType<T>::data_type, &_value, sizeof(T), false, _vin);
|
storeValue(_desc, StdToDataType<T>::data_type, &_value, sizeof(T), false, _vin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class T, size_t N>
|
template <class T, size_t N>
|
||||||
inline void setValue(const BaseBlockDescriptor* _desc, const T (&_value)[N], ValueId _vin)
|
inline void setValue(const BaseBlockDescriptor* _desc, const T (&_value)[N], ValueId _vin)
|
||||||
{
|
{
|
||||||
storeValue(_desc, StdToDataType<T>::data_type, &_value[0], sizeof(_value), true, _vin);
|
storeValue(_desc, StdToDataType<T>::data_type, &_value[0], sizeof(_value), true, _vin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void setText(const BaseBlockDescriptor* _desc, const char* _text, ValueId _vin)
|
inline void setText(const BaseBlockDescriptor* _desc, const char* _text, ValueId _vin)
|
||||||
{
|
{
|
||||||
storeValue(_desc, DataType::String, _text, strlen(_text) + 1, true, _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);
|
storeValue(_desc, DataType::String, _text.c_str(), _text.size() + 1, true, _vin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
inline void setText(const BaseBlockDescriptor* _desc, const char (&_text)[N], ValueId _vin)
|
inline void setText(const BaseBlockDescriptor* _desc, const char (&_text)[N], ValueId _vin)
|
||||||
{
|
{
|
||||||
@ -265,4 +102,36 @@ namespace profiler
|
|||||||
|
|
||||||
} // end of 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 <class T>
|
||||||
|
inline void setValue(const BaseBlockDescriptor*, T, ValueId) {}
|
||||||
|
|
||||||
|
template <class T, size_t N>
|
||||||
|
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 <size_t N>
|
||||||
|
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
|
#endif // EASY_PROFILER_ARBITRARY_VALUE_H
|
||||||
|
@ -43,7 +43,8 @@ The Apache License, Version 2.0 (the "License");
|
|||||||
#ifndef EASY_PROFILER_ARBITRARY_VALUE_AUX_H
|
#ifndef EASY_PROFILER_ARBITRARY_VALUE_AUX_H
|
||||||
#define EASY_PROFILER_ARBITRARY_VALUE_AUX_H
|
#define EASY_PROFILER_ARBITRARY_VALUE_AUX_H
|
||||||
|
|
||||||
#include <easy/profiler.h>
|
#include <easy/details/easy_compiler_support.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace profiler
|
namespace profiler
|
||||||
{
|
{
|
||||||
@ -92,7 +93,7 @@ namespace profiler
|
|||||||
template <class T, class ... TArgs>
|
template <class T, class ... TArgs>
|
||||||
static EASY_CONSTEXPR_FCN ValueId get(const T&, TArgs... _args) { return subextract_value_id(_args...); }
|
static EASY_CONSTEXPR_FCN ValueId get(const T&, TArgs... _args) { return subextract_value_id(_args...); }
|
||||||
};
|
};
|
||||||
}
|
} // end of noname namespace.
|
||||||
|
|
||||||
template <class T, class ... TArgs>
|
template <class T, class ... TArgs>
|
||||||
inline EASY_CONSTEXPR_FCN ValueId extract_value_id(const T& _first, TArgs... _args) {
|
inline EASY_CONSTEXPR_FCN ValueId extract_value_id(const T& _first, TArgs... _args) {
|
@ -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 <easy/details/arbitrary_value_aux.h>
|
||||||
|
#include <easy/details/profiler_public_types.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
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 <DataType dataType> struct StdType;
|
||||||
|
template <class T> struct StdToDataType;
|
||||||
|
|
||||||
|
# define EASY_DATATYPE_CONVERSION(DataTypeName, StdTypeName)\
|
||||||
|
template <> struct StdType<DataTypeName> { using value_type = StdTypeName; };\
|
||||||
|
template <> struct StdToDataType<StdTypeName> { 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<DataType::String> { using value_type = char; };
|
||||||
|
template <> struct StdToDataType<const char*> { EASY_STATIC_CONSTEXPR auto data_type = DataType::String; };
|
||||||
|
} // end of noname namespace.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <DataType dataType, bool isArray>
|
||||||
|
struct Value;
|
||||||
|
|
||||||
|
template <bool isArray>
|
||||||
|
struct Value<DataType::TypesCount, isArray>;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#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<timestamp_t>(_vin), _id)
|
||||||
|
, m_size(_size)
|
||||||
|
, m_type(_type)
|
||||||
|
, m_isArray(_isArray)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
const char* data() const {
|
||||||
|
return reinterpret_cast<const char*>(this) + sizeof(ArbitraryValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
vin_t value_id() const {
|
||||||
|
return static_cast<vin_t>(m_end);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <DataType dataType>
|
||||||
|
const Value<dataType, false>* convertToValue() const {
|
||||||
|
return m_type == dataType ? static_cast<const Value<dataType, false>*>(this) : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
const Value<StdToDataType<T>::data_type, false>* convertToValue() const {
|
||||||
|
return convertToValue<StdToDataType<T>::data_type>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <DataType dataType>
|
||||||
|
const Value<dataType, true>* convertToArray() const {
|
||||||
|
return m_isArray && m_type == dataType ? static_cast<const Value<dataType, true>*>(this) : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
const Value<StdToDataType<T>::data_type, true>* convertToArray() const {
|
||||||
|
return convertToArray<StdToDataType<T>::data_type>();
|
||||||
|
}
|
||||||
|
}; // end of class ArbitraryValue.
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <DataType dataType>
|
||||||
|
struct Value<dataType, false> EASY_FINAL : public ArbitraryValue {
|
||||||
|
using value_type = typename StdType<dataType>::value_type;
|
||||||
|
value_type value() const { return *reinterpret_cast<const value_type*>(data()); }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <DataType dataType>
|
||||||
|
struct Value<dataType, true> EASY_FINAL : public ArbitraryValue {
|
||||||
|
using value_type = typename StdType<dataType>::value_type;
|
||||||
|
const value_type* value() const { return reinterpret_cast<const value_type*>(data()); }
|
||||||
|
uint16_t size() const { return m_size / sizeof(value_type); }
|
||||||
|
value_type operator [] (int i) const { return value()[i]; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Value<DataType::String, true> 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 <DataType dataType>
|
||||||
|
using SingleValue = Value<dataType, false>;
|
||||||
|
|
||||||
|
template <DataType dataType>
|
||||||
|
using ArrayValue = Value<dataType, true>;
|
||||||
|
|
||||||
|
using StringValue = Value<DataType::String, true>;
|
||||||
|
|
||||||
|
} // end of namespace profiler.
|
||||||
|
|
||||||
|
#endif //EASY_PROFILER_ARBITRARY_VALUE_PUBLIC_TYPES_H
|
@ -57,8 +57,8 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <easy/easy_compiler_support.h>
|
#include <easy/details/easy_compiler_support.h>
|
||||||
#include <easy/profiler_colors.h>
|
#include <easy/details/profiler_colors.h>
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -43,7 +43,7 @@ The Apache License, Version 2.0 (the "License");
|
|||||||
#ifndef EASY_PROFILER_PUBLIC_TYPES_H
|
#ifndef EASY_PROFILER_PUBLIC_TYPES_H
|
||||||
#define EASY_PROFILER_PUBLIC_TYPES_H
|
#define EASY_PROFILER_PUBLIC_TYPES_H
|
||||||
|
|
||||||
#include <easy/profiler_aux.h>
|
#include <easy/details/profiler_aux.h>
|
||||||
|
|
||||||
class NonscopedBlock;
|
class NonscopedBlock;
|
||||||
class ProfileManager;
|
class ProfileManager;
|
@ -43,7 +43,7 @@ The Apache License, Version 2.0 (the "License");
|
|||||||
#ifndef EASY_PROFILER_H
|
#ifndef EASY_PROFILER_H
|
||||||
#define EASY_PROFILER_H
|
#define EASY_PROFILER_H
|
||||||
|
|
||||||
#include <easy/profiler_public_types.h>
|
#include <easy/details/profiler_public_types.h>
|
||||||
|
|
||||||
#if defined ( __clang__ )
|
#if defined ( __clang__ )
|
||||||
# pragma clang diagnostic push
|
# pragma clang diagnostic push
|
||||||
|
Loading…
x
Reference in New Issue
Block a user