1
+ #pragma once
2
+
3
+ #include "ProfilingFwd.h"
4
+
5
+ #if SPARROW_PROFILING
6
+
7
+ #define TRACY_ENABLE 1
8
+
9
+ #ifdef __cplusplus
10
+
11
+ ////////////////////////////////////////////////////////////////////////////////
12
+ // C++ profiling definitions
13
+
14
+ #include "../../../externals/tracy/Tracy.hpp"
15
+
16
+ #include "Nest/Api/StringRef.h"
17
+
18
+ #define PROFILING_ZONE () ZoneScoped
19
+ #define PROFILING_ZONE_NAMED (staticName ) ZoneScopedN(staticName)
20
+ #define PROFILING_ZONE_TEXT (text ) \
21
+ ZoneScoped; \
22
+ _Nest_Profiling_zoneSetText(___tracy_scoped_zone, text)
23
+ #define PROFILING_ZONE_NAMED_TEXT (staticName , text ) \
24
+ ZoneScopedN(staticName); \
25
+ _Nest_Profiling_zoneSetText(___tracy_scoped_zone, text)
26
+ #define PROFILING_ZONE_SETTEEXT (text ) _Nest_Profiling_zoneSetText(___tracy_scoped_zone, text)
27
+
28
+ #define PROFILING_PLOT (name , val ) tracy::Profiler::PlotData(name, val)
29
+
30
+ #define PROFILING_MESSAGE_STATIC (staticText ) tracy::Profiler::Message(staticText)
31
+ #define PROFILING_MESSAGE (text ) _Nest_Profiling_message(text)
32
+
33
+ inline void _Nest_Profiling_zoneSetText (tracy ::ScopedZone & zone , const char * text ) {
34
+ zone .Text (text , strlen (text ));
35
+ }
36
+ inline void _Nest_Profiling_zoneSetText (tracy ::ScopedZone & zone , Nest_StringRef text ) {
37
+ zone .Text (text .begin , text .end - text .begin );
38
+ }
39
+
40
+ inline void _Nest_Profiling_message (const char * text ) {
41
+ tracy ::Profiler ::Message (text , strlen (text ));
42
+ }
43
+ inline void _Nest_Profiling_message (Nest_StringRef text ) {
44
+ tracy ::Profiler ::Message (text .begin , text .end - text .begin );
45
+ }
46
+
47
+ #else // __cplusplus
48
+
49
+ ////////////////////////////////////////////////////////////////////////////////
50
+ // C-only profiling definitions
51
+
52
+ #include "../../../externals/tracy/TracyC.h"
53
+
54
+ typedef TracyCZoneCtx Nest_Profiling_ZoneCtx ;
55
+
56
+ #define PROFILING_C_ZONE_BEGIN (ctx ) \
57
+ static const struct Nest_Profiling_LocType TracyConcat(__tracy_source_location, __LINE__) = { \
58
+ NULL, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0}; \
59
+ Nest_Profiling_ZoneCtx ctx = \
60
+ ___tracy_emit_zone_begin(&TracyConcat(__tracy_source_location, __LINE__), 1);
61
+
62
+ #define PROFILING_C_ZONE_BEGIN_LOC (ctx , locPtr ) \
63
+ Nest_Profiling_ZoneCtx ctx = ___tracy_emit_zone_begin(locPtr, 1)
64
+
65
+ #define PROFILING_C_ZONE_END (ctx ) ___tracy_emit_zone_end(ctx)
66
+ #define PROFILING_C_ZONE_SETTEEXT (ctx , text ) ___tracy_emit_zone_text(ctx, text, strlen(text))
67
+
68
+ #endif // __cplusplus
69
+
70
+ ////////////////////////////////////////////////////////////////////////////////
71
+ // Both C and C++ profiling definitions
72
+
73
+ #ifdef __cplusplus
74
+ extern "C" {
75
+ #endif
76
+
77
+ //! Creates a location type for profiling
78
+ const Nest_Profiling_LocType * Nest_Profiling_createLoc (
79
+ const char * name , const char * function , const char * file , unsigned line , unsigned color );
80
+
81
+ #ifdef __cplusplus
82
+ }
83
+ #endif
84
+
85
+ #else // SPARROW_PROFILING
86
+
87
+ ////////////////////////////////////////////////////////////////////////////////
88
+ // Profiling not enabled
89
+
90
+ #define PROFILING_ZONE () /*nothing*/
91
+ #define PROFILING_ZONE_NAMED (staticName ) /*nothing*/
92
+ #define PROFILING_ZONE_TEXT (text ) /*nothing*/
93
+ #define PROFILING_ZONE_NAMED_TEXT (staticName , text ) /*nothing*/
94
+ #define PROFILING_ZONE_SETTEEXT (text ) /*nothing*/
95
+ #define PROFILING_PLOT (name , val ) /*nothing*/
96
+ #define PROFILING_MESSAGE_STATIC (staticText ) /*nothing*/
97
+ #define PROFILING_MESSAGE (text ) /*nothing*/
98
+
99
+ #define PROFILING_C_ZONE_BEGIN (ctx ) /*nothing*/
100
+ #define PROFILING_C_ZONE_BEGIN_LOC (ctx , locPtr ) /*nothing*/
101
+ #define PROFILING_C_ZONE_END (ctx ) /*nothing*/
102
+ #define PROFILING_C_ZONE_SETTEEXT (ctx , text ) /*nothing*/
103
+
104
+ #endif
0 commit comments