From 7b74420ace898995726fb09be4fb30a65ad61aba Mon Sep 17 00:00:00 2001 From: Aidan Lee Date: Thu, 12 Sep 2024 19:48:48 +0100 Subject: [PATCH] new tracy telemetry header and hxcpp zone macro --- include/hx/Telemetry.h | 9 --------- include/hx/TelemetryTracy.h | 35 +++++++++++++++++++++++++++++++++++ src/hx/TelemetryTracy.cpp | 36 +++++++++++++++++++----------------- 3 files changed, 54 insertions(+), 26 deletions(-) create mode 100644 include/hx/TelemetryTracy.h diff --git a/include/hx/Telemetry.h b/include/hx/Telemetry.h index 092bd22cc..cf8657785 100644 --- a/include/hx/Telemetry.h +++ b/include/hx/Telemetry.h @@ -32,13 +32,4 @@ void __hxcpp_hxt_ignore_allocs(int delta); int __hxcpp_gc_reserved_bytes(); int __hxcpp_gc_used_bytes(); -#ifdef HXCPP_TRACY - void __hxcpp_tracy_framemark(); - void __hxcpp_tracy_plot(String name, float val); - void __hxcpp_tracy_plot_config(String name, uint8_t format, bool step, bool fill, int color); - void __hxcpp_tracy_message(String msg, int color); - void __hxcpp_tracy_message_app_info(String info); - void __hxcpp_tracy_set_thread_name_and_group(String name, int groupHint); -#endif - #endif diff --git a/include/hx/TelemetryTracy.h b/include/hx/TelemetryTracy.h new file mode 100644 index 000000000..7a2fd6ef5 --- /dev/null +++ b/include/hx/TelemetryTracy.h @@ -0,0 +1,35 @@ +#ifndef HX_TELEMETRY_TRACY_H +#define HX_TELEMETRY_TRACY_H + +#ifndef HXCPP_TRACY + #error "Error: HXCPP_TRACY must be defined." +#endif + +#define TRACY_ENABLE +#include +#include "../../project/thirdparty/tracy-0.11.1/tracy/TracyC.h" +#include "../../project/thirdparty/tracy-0.11.1/tracy/Tracy.hpp" + +#ifdef HXCPP_TRACY_MEMORY + #ifdef HXCPP_GC_MOVING + #error "Error: HXCPP_TRACY_MEMORY is not supported when HXCPP_GC_MOVING is active." + #endif + #ifdef HXCPP_GC_GENERATIONAL + #error "Error: HXCPP_TRACY_MEMORY is not supported when HXCPP_GC_GENERATIONAL is active." + #endif +#endif + +#define HXCPP_TRACY_ZONE(name) \ + ::hx::strbuf TracyConcat(_hx_tracy_str_buffer, TracyLine); \ + int TracyConcat(_hx_tracy_str_length, TracyLine); \ + ::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)); + +void __hxcpp_tracy_framemark(); +void __hxcpp_tracy_plot(::String name, float val); +void __hxcpp_tracy_plot_config(::String name, uint8_t format, bool step, bool fill, int color); +void __hxcpp_tracy_message(::String msg, int color); +void __hxcpp_tracy_message_app_info(::String info); +void __hxcpp_tracy_set_thread_name_and_group(String name, int groupHint); +void __hxcpp_tracy_test_zone(); + +#endif \ No newline at end of file diff --git a/src/hx/TelemetryTracy.cpp b/src/hx/TelemetryTracy.cpp index e39775076..0867d699b 100644 --- a/src/hx/TelemetryTracy.cpp +++ b/src/hx/TelemetryTracy.cpp @@ -1,20 +1,9 @@ #include +#include #include -#define TRACY_ENABLE -#include "../../project/thirdparty/tracy-0.11.1/tracy/TracyC.h" -#include "../../project/thirdparty/tracy-0.11.1/tracy/Tracy.hpp" #include -#ifdef HXCPP_TRACY_MEMORY - #ifdef HXCPP_GC_MOVING - #error "Error: HXCPP_TRACY_MEMORY is not supported when HXCPP_GC_MOVING is active." - #endif - #ifdef HXCPP_GC_GENERATIONAL - #error "Error: HXCPP_TRACY_MEMORY is not supported when HXCPP_GC_GENERATIONAL is active." - #endif -#endif - namespace { TracyCZoneCtx gcZone; @@ -239,25 +228,38 @@ void __hxcpp_tracy_framemark() void __hxcpp_tracy_plot(String name, float val) { - ::tracy::Profiler::PlotData(name.c_str(), val); + hx::strbuf buffer; + ::tracy::Profiler::PlotData(name.utf8_str(&buffer), val); } void __hxcpp_tracy_plot_config(String name, uint8_t format, bool step, bool fill, int color) { - ::tracy::Profiler::ConfigurePlot(name.c_str(),::tracy::PlotFormatType(format), step, fill, color); + hx::strbuf buffer; + ::tracy::Profiler::ConfigurePlot(name.utf8_str(&buffer),::tracy::PlotFormatType(format), step, fill, color); } void __hxcpp_tracy_message(String msg, int color) { - ::tracy::Profiler::MessageColor(msg.c_str(), msg.length, color, 0); + hx::strbuf buffer; + ::tracy::Profiler::MessageColor(msg.utf8_str(&buffer), msg.length, color, 0); } void __hxcpp_tracy_message_app_info(String info) { - ::tracy::Profiler::MessageAppInfo(info.c_str(), info.length); + hx::strbuf buffer; + ::tracy::Profiler::MessageAppInfo(info.utf8_str(&buffer), info.length); } void __hxcpp_tracy_set_thread_name_and_group(String name, int groupHint) { - ::tracy::SetThreadNameWithHint(name.c_str(), groupHint); + hx::strbuf buffer; + ::tracy::SetThreadNameWithHint(name.utf8_str(&buffer), groupHint); } + +void __hxcpp_tracy_test_zone() +{ + ::hx::StackFrame _hx_stackframe(nullptr); + ::String name("test"); + + HXCPP_TRACY_ZONE(name); +} \ No newline at end of file