#pragma once
#include "IUnityInterface.h"
#include <stdint.h>
typedef uint32_t UnityProfilerMarkerId;
enum UnityBuiltinProfilerCategory_
{
kUnityProfilerCategoryRender = 0,
kUnityProfilerCategoryScripts = 1,
kUnityProfilerCategoryManagedJobs = 2,
kUnityProfilerCategoryBurstJobs = 3,
kUnityProfilerCategoryGUI = 4,
kUnityProfilerCategoryPhysics = 5,
kUnityProfilerCategoryAnimation = 6,
kUnityProfilerCategoryAI = 7,
kUnityProfilerCategoryAudio = 8,
kUnityProfilerCategoryAudioJob = 9,
kUnityProfilerCategoryAudioUpdateJob = 10,
kUnityProfilerCategoryVideo = 11,
kUnityProfilerCategoryParticles = 12,
kUnityProfilerCategoryGi = 13,
kUnityProfilerCategoryNetwork = 14,
kUnityProfilerCategoryLoading = 15,
kUnityProfilerCategoryOther = 16,
kUnityProfilerCategoryGC = 17,
kUnityProfilerCategoryVSync = 18,
kUnityProfilerCategoryOverhead = 19,
kUnityProfilerCategoryPlayerLoop = 20,
kUnityProfilerCategoryDirector = 21,
kUnityProfilerCategoryVR = 22,
kUnityProfilerCategoryAllocation = 23, kUnityProfilerCategoryMemory = 23,
kUnityProfilerCategoryInternal = 24,
kUnityProfilerCategoryFileIO = 25,
kUnityProfilerCategoryUISystemLayout = 26,
kUnityProfilerCategoryUISystemRender = 27,
kUnityProfilerCategoryVFX = 28,
kUnityProfilerCategoryBuildInterface = 29,
kUnityProfilerCategoryInput = 30,
kUnityProfilerCategoryVirtualTexturing = 31,
kUnityProfilerCategoryGPU = 32,
kUnityProfilerCategoryPhysics2D = 33,
kUnityProfilerCategoryNetworkOperations = 34,
kUnityProfilerCategoryUIDetails = 35,
kUnityProfilerCategoryDebug = 36,
kUnityProfilerCategoryJobs = 37,
};
typedef uint16_t UnityProfilerCategoryId;
typedef struct UnityProfilerCategoryDesc
{
UnityProfilerCategoryId id;
uint16_t reserved0;
uint32_t rgbaColor;
const char* name;
} UnityProfilerCategoryDesc;
enum UnityProfilerMarkerFlag_
{
kUnityProfilerMarkerFlagDefault = 0,
kUnityProfilerMarkerFlagScriptUser = 1 << 1, kUnityProfilerMarkerFlagScriptInvoke = 1 << 5, kUnityProfilerMarkerFlagScriptEnterLeave = 1 << 6,
kUnityProfilerMarkerFlagAvailabilityEditor = 1 << 2, kUnityProfilerMarkerFlagAvailabilityNonDev = 1 << 3,
kUnityProfilerMarkerFlagWarning = 1 << 4,
kUnityProfilerMarkerFlagCounter = 1 << 7,
kUnityProfilerMarkerFlagVerbosityDebug = 1 << 10, kUnityProfilerMarkerFlagVerbosityInternal = 1 << 11, kUnityProfilerMarkerFlagVerbosityAdvanced = 1 << 12 };
typedef uint16_t UnityProfilerMarkerFlags;
enum UnityProfilerMarkerEventType_
{
kUnityProfilerMarkerEventTypeBegin = 0,
kUnityProfilerMarkerEventTypeEnd = 1,
kUnityProfilerMarkerEventTypeSingle = 2
};
typedef uint16_t UnityProfilerMarkerEventType;
typedef struct UnityProfilerMarkerDesc
{
const void* callback;
UnityProfilerMarkerId id;
UnityProfilerMarkerFlags flags;
UnityProfilerCategoryId categoryId;
const char* name;
const void* metaDataDesc;
} UnityProfilerMarkerDesc;
enum UnityProfilerMarkerDataType_
{
kUnityProfilerMarkerDataTypeNone = 0,
kUnityProfilerMarkerDataTypeInstanceId = 1,
kUnityProfilerMarkerDataTypeInt32 = 2,
kUnityProfilerMarkerDataTypeUInt32 = 3,
kUnityProfilerMarkerDataTypeInt64 = 4,
kUnityProfilerMarkerDataTypeUInt64 = 5,
kUnityProfilerMarkerDataTypeFloat = 6,
kUnityProfilerMarkerDataTypeDouble = 7,
kUnityProfilerMarkerDataTypeString = 8,
kUnityProfilerMarkerDataTypeString16 = 9,
kUnityProfilerMarkerDataTypeBlob8 = 11,
kUnityProfilerMarkerDataTypeGfxResourceId = 12,
kUnityProfilerMarkerDataTypeCount };
typedef uint8_t UnityProfilerMarkerDataType;
enum UnityProfilerMarkerDataUnit_
{
kUnityProfilerMarkerDataUnitUndefined = 0,
kUnityProfilerMarkerDataUnitTimeNanoseconds = 1,
kUnityProfilerMarkerDataUnitBytes = 2,
kUnityProfilerMarkerDataUnitCount = 3,
kUnityProfilerMarkerDataUnitPercent = 4,
kUnityProfilerMarkerDataUnitFrequencyHz = 5,
};
typedef uint8_t UnityProfilerMarkerDataUnit;
typedef struct UnityProfilerMarkerData
{
UnityProfilerMarkerDataType type;
uint8_t reserved0;
uint16_t reserved1;
uint32_t size;
const void* ptr;
} UnityProfilerMarkerData;
enum UnityProfilerFlowEventType_
{
kUnityProfilerFlowEventTypeBegin = 0,
kUnityProfilerFlowEventTypeParallelNext = 1,
kUnityProfilerFlowEventTypeEnd = 2,
kUnityProfilerFlowEventTypeNext = 3,
};
typedef uint8_t UnityProfilerFlowEventType;
enum UnityProfilerCounterFlags_
{
kUnityProfilerCounterFlagNone = 0,
kUnityProfilerCounterFlushOnEndOfFrame = 1 << 1,
kUnityProfilerCounterFlagResetToZeroOnFlush = 1 << 2,
kUnityProfilerCounterFlagAtomic = 1 << 3,
kUnityProfilerCounterFlagGetter = 1 << 4
};
typedef uint16_t UnityProfilerCounterFlags;
typedef uint64_t UnityProfilerThreadId;
typedef void (*UnityProfilerCounterStatePtrCallback)(void* userData);
#ifdef __cplusplus
template<typename T> struct UnityProfilerDataUnitHelper;
template<> struct UnityProfilerDataUnitHelper<int32_t> { static const UnityProfilerMarkerDataType GetProfilerType() { return kUnityProfilerMarkerDataTypeInt32; } };
template<> struct UnityProfilerDataUnitHelper<uint32_t> { static const UnityProfilerMarkerDataType GetProfilerType() { return kUnityProfilerMarkerDataTypeUInt32; } };
template<> struct UnityProfilerDataUnitHelper<int64_t> { static const UnityProfilerMarkerDataType GetProfilerType() { return kUnityProfilerMarkerDataTypeInt64; } };
template<> struct UnityProfilerDataUnitHelper<uint64_t> { static const UnityProfilerMarkerDataType GetProfilerType() { return kUnityProfilerMarkerDataTypeUInt64; } };
template<> struct UnityProfilerDataUnitHelper<float> { static const UnityProfilerMarkerDataType GetProfilerType() { return kUnityProfilerMarkerDataTypeFloat; } };
template<> struct UnityProfilerDataUnitHelper<double> { static const UnityProfilerMarkerDataType GetProfilerType() { return kUnityProfilerMarkerDataTypeDouble; } };
template<typename T> struct UnityProfilerCounter;
#endif
UNITY_DECLARE_INTERFACE(IUnityProfilerV2)
{
void BeginSample(const UnityProfilerMarkerDesc * markerDesc)
{
(this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeBegin, 0, NULL);
}
void BeginSample(const UnityProfilerMarkerDesc * markerDesc, uint16_t eventDataCount, const UnityProfilerMarkerData * eventData)
{
(this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeBegin, eventDataCount, eventData);
}
void EndSample(const UnityProfilerMarkerDesc * markerDesc)
{
(this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeEnd, 0, NULL);
}
void(UNITY_INTERFACE_API * EmitEvent)(const UnityProfilerMarkerDesc * markerDesc, UnityProfilerMarkerEventType eventType, uint16_t eventDataCount, const UnityProfilerMarkerData * eventData);
int(UNITY_INTERFACE_API * IsEnabled)();
int(UNITY_INTERFACE_API * IsAvailable)();
int(UNITY_INTERFACE_API * CreateMarker)(const UnityProfilerMarkerDesc * *desc, const char* name, UnityProfilerCategoryId category, UnityProfilerMarkerFlags flags, int eventDataCount);
int(UNITY_INTERFACE_API * SetMarkerMetadataName)(const UnityProfilerMarkerDesc * desc, int index, const char* metadataName, UnityProfilerMarkerDataType metadataType, UnityProfilerMarkerDataUnit metadataUnit);
int(UNITY_INTERFACE_API * CreateCategory)(UnityProfilerCategoryId *category, const char* name, uint32_t unused);
int(UNITY_INTERFACE_API * RegisterThread)(UnityProfilerThreadId * threadId, const char* groupName, const char* name);
int(UNITY_INTERFACE_API * UnregisterThread)(UnityProfilerThreadId threadId);
#ifdef __cplusplus
template<typename T>
UnityProfilerCounter<T> CreateCounter(UnityProfilerCategoryId category, const char* name, UnityProfilerMarkerDataUnit dataUnit,
UnityProfilerCounterStatePtrCallback activateFunc = nullptr, UnityProfilerCounterStatePtrCallback deactivateFunc = nullptr, void* userData = nullptr)
{
return UnityProfilerCounter<T>(
this,
this->CreateCounterValue(
category,
name,
kUnityProfilerMarkerFlagCounter,
UnityProfilerDataUnitHelper<T>::GetProfilerType(),
dataUnit,
sizeof(T),
kUnityProfilerCounterFlagNone,
activateFunc,
deactivateFunc,
userData
)
);
}
#endif
void* (UNITY_INTERFACE_API* CreateCounterValue)(
UnityProfilerCategoryId category,
const char* name,
UnityProfilerMarkerFlags flags,
UnityProfilerMarkerDataType valueType,
UnityProfilerMarkerDataUnit valueUnit,
size_t valueSize,
UnityProfilerCounterFlags counterFlags,
UnityProfilerCounterStatePtrCallback activateFunc,
UnityProfilerCounterStatePtrCallback deactivateFunc,
void* userData
);
void(UNITY_INTERFACE_API * FlushCounterValue)(void* counter);
};
UNITY_REGISTER_INTERFACE_GUID(0xB957E0189CB6A30BULL, 0x83CE589AE85B9068ULL, IUnityProfilerV2)
#ifdef __cplusplus
struct UnityProfilerCounterValue
{
UnityProfilerCounterValue()
: m_Profiler(nullptr)
, m_Value(nullptr)
{
}
UnityProfilerCounterValue(IUnityProfilerV2* profiler, void* value)
: m_Profiler(profiler)
, m_Value(value)
{
}
template<typename T>
inline T& Value() { return *static_cast<T*>(m_Value); }
template<typename T>
inline const T& Value() const { return *static_cast<T*>(m_Value); }
inline void Flush()
{
m_Profiler->FlushCounterValue(m_Value);
}
private:
void* m_Value;
IUnityProfilerV2* m_Profiler;
};
template<typename T>
struct UnityProfilerCounter : public UnityProfilerCounterValue
{
UnityProfilerCounter() {}
UnityProfilerCounter(IUnityProfilerV2* profiler, void* value) : UnityProfilerCounterValue(profiler, value) {}
T& operator*() { return Value<T>(); }
const T& operator*() const { return Value<T>(); }
operator T&() { return Value<T>(); }
operator T() const { return Value<T>(); }
T& operator=(const T& s)
{
Value<T>() = s;
return Value<T>();
}
T operator++(int)
{
T copy(Value<T>());
++(Value<T>());
return copy;
}
UnityProfilerCounter<T>& operator++()
{
++(Value<T>());
return *this;
}
T operator--(int)
{
T copy(Value<T>());
--(Value<T>());
return copy;
}
UnityProfilerCounter& operator--()
{
--(Value<T>());
return *this;
}
UnityProfilerCounter& operator-=(T& s)
{
(Value<T>()) -= s;
return *this;
}
UnityProfilerCounter& operator+=(T& s)
{
(Value<T>()) += s;
return *this;
}
};
#endif
UNITY_DECLARE_INTERFACE(IUnityProfiler)
{
void BeginSample(const UnityProfilerMarkerDesc* markerDesc)
{
(this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeBegin, 0, NULL);
}
void BeginSample(const UnityProfilerMarkerDesc* markerDesc, uint16_t eventDataCount, const UnityProfilerMarkerData* eventData)
{
(this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeBegin, eventDataCount, eventData);
}
void EndSample(const UnityProfilerMarkerDesc* markerDesc)
{
(this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeEnd, 0, NULL);
}
void(UNITY_INTERFACE_API * EmitEvent)(const UnityProfilerMarkerDesc* markerDesc, UnityProfilerMarkerEventType eventType, uint16_t eventDataCount, const UnityProfilerMarkerData* eventData);
int(UNITY_INTERFACE_API * IsEnabled)();
int(UNITY_INTERFACE_API * IsAvailable)();
int(UNITY_INTERFACE_API * CreateMarker)(const UnityProfilerMarkerDesc** desc, const char* name, UnityProfilerCategoryId category, UnityProfilerMarkerFlags flags, int eventDataCount);
int(UNITY_INTERFACE_API * SetMarkerMetadataName)(const UnityProfilerMarkerDesc* desc, int index, const char* metadataName, UnityProfilerMarkerDataType metadataType, UnityProfilerMarkerDataUnit metadataUnit);
int(UNITY_INTERFACE_API * RegisterThread)(UnityProfilerThreadId* threadId, const char* groupName, const char* name);
int(UNITY_INTERFACE_API * UnregisterThread)(UnityProfilerThreadId threadId);
};
UNITY_REGISTER_INTERFACE_GUID(0x2CE79ED8316A4833ULL, 0x87076B2013E1571FULL, IUnityProfiler)