Plasma Engine  2.0
Loading...
Searching...
No Matches
Profiling_Tracy.h
1#include <Foundation/Basics.h>
2#include <Foundation/Strings/HashedString.h>
3
4#if PL_ENABLED(PL_USE_PROFILING) && TRACY_ENABLE && !PL_DOCS
5
6# include <tracy/tracy/Tracy.hpp>
7
8PL_ALWAYS_INLINE plUInt32 __tracyPlStringLength(const char* szString)
9{
11}
12
13PL_ALWAYS_INLINE plUInt32 __tracyPlStringLength(plStringView sString)
14{
15 return sString.GetElementCount();
16}
17
18PL_ALWAYS_INLINE plUInt32 __tracyPlStringLength(const plString& sString)
19{
20 return sString.GetElementCount();
21}
22
23PL_ALWAYS_INLINE plUInt32 __tracyPlStringLength(const plStringBuilder& sString)
24{
25 return sString.GetElementCount();
26}
27
28PL_ALWAYS_INLINE plUInt32 __tracyPlStringLength(const plHashedString& sString)
29{
30 return sString.GetView().GetElementCount();
31}
32
33PL_ALWAYS_INLINE const char* __tracyPlStringToConstChar(const plString& sString)
34{
35 return sString.GetData();
36}
37
38PL_ALWAYS_INLINE const char* __tracyPlStringToConstChar(const plStringBuilder& sString)
39{
40 return sString.GetData();
41}
42
43PL_ALWAYS_INLINE const char* __tracyPlStringToConstChar(const plHashedString& sString)
44{
45 return sString.GetData();
46}
47
48PL_ALWAYS_INLINE const char* __tracyPlStringToConstChar(const plStringView& sString)
49{
50 // can just return the string views start pointer, because this is used together with __tracyPlStringLength
51 return sString.GetStartPointer();
52}
53
54PL_ALWAYS_INLINE const char* __tracyPlStringToConstChar(const char* szString)
55{
56 return szString;
57}
58
60# define PL_TRACY_PROFILE_SCOPE(ScopeName) \
61 ZoneScoped; \
62 ZoneName(__tracyPlStringToConstChar(ScopeName), __tracyPlStringLength(ScopeName))
63
64// Override the standard PL profiling macros and inject Tracy profiling scopes
65
66# undef PL_PROFILE_SCOPE
67# define PL_PROFILE_SCOPE(ScopeName) \
68 plProfilingScope PL_PP_CONCAT(_plProfilingScope, PL_SOURCE_LINE)(ScopeName, PL_SOURCE_FUNCTION, plTime::MakeZero()); \
69 PL_TRACY_PROFILE_SCOPE(ScopeName)
70
71# undef PL_PROFILE_SCOPE_WITH_TIMEOUT
72# define PL_PROFILE_SCOPE_WITH_TIMEOUT(ScopeName, Timeout) \
73 plProfilingScope PL_PP_CONCAT(_plProfilingScope, PL_SOURCE_LINE)(ScopeName, PL_SOURCE_FUNCTION, Timeout); \
74 PL_TRACY_PROFILE_SCOPE(ScopeName);
75
76# undef PL_PROFILE_LIST_SCOPE
77# define PL_PROFILE_LIST_SCOPE(ListName, FirstSectionName) \
78 plProfilingListScope PL_PP_CONCAT(_plProfilingScope, PL_SOURCE_LINE)(ListName, FirstSectionName, PL_SOURCE_FUNCTION); \
79 PL_TRACY_PROFILE_SCOPE(ScopeName);
80
81# undef PL_PROFILER_FRAME_MARKER
82# define PL_PROFILER_FRAME_MARKER() FrameMark
83
84#else
85
87# define PL_TRACY_PROFILE_SCOPE(ScopeName)
88
89#endif
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
PL_ALWAYS_INLINE plStringView GetView() const
Returns a string view to this string's data.
Definition HashedString.h:128
const char * GetData() const
Gives access to the actual string data, so you can do all the typical (read-only) string operations o...
Definition HashedString_inl.h:110
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
const char * GetData() const
Returns a char pointer to the internal Utf8 data.
Definition StringBuilder_inl.h:148
plUInt32 GetElementCount() const
Returns the number of bytes that this string takes up.
Definition StringBuilder_inl.h:78
static constexpr plUInt32 GetStringElementCount(const T *pString)
Returns the number of elements of type T that the string contains, until it hits an element that is z...
Definition StringUtils_inl.h:45
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
plUInt32 GetElementCount() const
Returns the number of bytes from the start position up to its end.
Definition StringView.h:93
const char * GetStartPointer() const
Returns the start of the view range.
Definition StringView.h:102
const char * GetData() const
Returns a pointer to the internal Utf8 string.
Definition String_inl.h:56
plUInt32 GetElementCount() const
Returns the amount of bytes that this string takes (excluding the '\0' terminator).
Definition String_inl.h:65