Skip to content

Commit 7b74420

Browse files
committed
new tracy telemetry header and hxcpp zone macro
1 parent 56aaf05 commit 7b74420

File tree

3 files changed

+54
-26
lines changed

3 files changed

+54
-26
lines changed

include/hx/Telemetry.h

-9
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,4 @@ void __hxcpp_hxt_ignore_allocs(int delta);
3232
int __hxcpp_gc_reserved_bytes();
3333
int __hxcpp_gc_used_bytes();
3434

35-
#ifdef HXCPP_TRACY
36-
void __hxcpp_tracy_framemark();
37-
void __hxcpp_tracy_plot(String name, float val);
38-
void __hxcpp_tracy_plot_config(String name, uint8_t format, bool step, bool fill, int color);
39-
void __hxcpp_tracy_message(String msg, int color);
40-
void __hxcpp_tracy_message_app_info(String info);
41-
void __hxcpp_tracy_set_thread_name_and_group(String name, int groupHint);
42-
#endif
43-
4435
#endif

include/hx/TelemetryTracy.h

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#ifndef HX_TELEMETRY_TRACY_H
2+
#define HX_TELEMETRY_TRACY_H
3+
4+
#ifndef HXCPP_TRACY
5+
#error "Error: HXCPP_TRACY must be defined."
6+
#endif
7+
8+
#define TRACY_ENABLE
9+
#include <hxcpp.h>
10+
#include "../../project/thirdparty/tracy-0.11.1/tracy/TracyC.h"
11+
#include "../../project/thirdparty/tracy-0.11.1/tracy/Tracy.hpp"
12+
13+
#ifdef HXCPP_TRACY_MEMORY
14+
#ifdef HXCPP_GC_MOVING
15+
#error "Error: HXCPP_TRACY_MEMORY is not supported when HXCPP_GC_MOVING is active."
16+
#endif
17+
#ifdef HXCPP_GC_GENERATIONAL
18+
#error "Error: HXCPP_TRACY_MEMORY is not supported when HXCPP_GC_GENERATIONAL is active."
19+
#endif
20+
#endif
21+
22+
#define HXCPP_TRACY_ZONE(name) \
23+
::hx::strbuf TracyConcat(_hx_tracy_str_buffer, TracyLine); \
24+
int TracyConcat(_hx_tracy_str_length, TracyLine); \
25+
::tracy::ScopedZone ___tracy_scoped_zone(_hx_stackframe.lineNumber, _hx_stackframe.position->fullName, strlen(_hx_stackframe.position->fullName), _hx_stackframe.position->functionName, strlen(_hx_stackframe.position->functionName), name.utf8_str(&TracyConcat(_hx_tracy_str_buffer, TracyLine), &TracyConcat(_hx_tracy_str_length, TracyLine)), TracyConcat(_hx_tracy_str_length, TracyLine));
26+
27+
void __hxcpp_tracy_framemark();
28+
void __hxcpp_tracy_plot(::String name, float val);
29+
void __hxcpp_tracy_plot_config(::String name, uint8_t format, bool step, bool fill, int color);
30+
void __hxcpp_tracy_message(::String msg, int color);
31+
void __hxcpp_tracy_message_app_info(::String info);
32+
void __hxcpp_tracy_set_thread_name_and_group(String name, int groupHint);
33+
void __hxcpp_tracy_test_zone();
34+
35+
#endif

src/hx/TelemetryTracy.cpp

+19-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
#include <hxcpp.h>
2+
#include <hx/TelemetryTracy.h>
23
#include <hx/Thread.h>
34

4-
#define TRACY_ENABLE
5-
#include "../../project/thirdparty/tracy-0.11.1/tracy/TracyC.h"
6-
#include "../../project/thirdparty/tracy-0.11.1/tracy/Tracy.hpp"
75
#include <vector>
86

9-
#ifdef HXCPP_TRACY_MEMORY
10-
#ifdef HXCPP_GC_MOVING
11-
#error "Error: HXCPP_TRACY_MEMORY is not supported when HXCPP_GC_MOVING is active."
12-
#endif
13-
#ifdef HXCPP_GC_GENERATIONAL
14-
#error "Error: HXCPP_TRACY_MEMORY is not supported when HXCPP_GC_GENERATIONAL is active."
15-
#endif
16-
#endif
17-
187
namespace
198
{
209
TracyCZoneCtx gcZone;
@@ -239,25 +228,38 @@ void __hxcpp_tracy_framemark()
239228

240229
void __hxcpp_tracy_plot(String name, float val)
241230
{
242-
::tracy::Profiler::PlotData(name.c_str(), val);
231+
hx::strbuf buffer;
232+
::tracy::Profiler::PlotData(name.utf8_str(&buffer), val);
243233
}
244234

245235
void __hxcpp_tracy_plot_config(String name, uint8_t format, bool step, bool fill, int color)
246236
{
247-
::tracy::Profiler::ConfigurePlot(name.c_str(),::tracy::PlotFormatType(format), step, fill, color);
237+
hx::strbuf buffer;
238+
::tracy::Profiler::ConfigurePlot(name.utf8_str(&buffer),::tracy::PlotFormatType(format), step, fill, color);
248239
}
249240

250241
void __hxcpp_tracy_message(String msg, int color)
251242
{
252-
::tracy::Profiler::MessageColor(msg.c_str(), msg.length, color, 0);
243+
hx::strbuf buffer;
244+
::tracy::Profiler::MessageColor(msg.utf8_str(&buffer), msg.length, color, 0);
253245
}
254246

255247
void __hxcpp_tracy_message_app_info(String info)
256248
{
257-
::tracy::Profiler::MessageAppInfo(info.c_str(), info.length);
249+
hx::strbuf buffer;
250+
::tracy::Profiler::MessageAppInfo(info.utf8_str(&buffer), info.length);
258251
}
259252

260253
void __hxcpp_tracy_set_thread_name_and_group(String name, int groupHint)
261254
{
262-
::tracy::SetThreadNameWithHint(name.c_str(), groupHint);
255+
hx::strbuf buffer;
256+
::tracy::SetThreadNameWithHint(name.utf8_str(&buffer), groupHint);
263257
}
258+
259+
void __hxcpp_tracy_test_zone()
260+
{
261+
::hx::StackFrame _hx_stackframe(nullptr);
262+
::String name("test");
263+
264+
HXCPP_TRACY_ZONE(name);
265+
}

0 commit comments

Comments
 (0)