Skip to content

Commit

Permalink
new tracy telemetry header and hxcpp zone macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidan63 committed Sep 12, 2024
1 parent 56aaf05 commit 7b74420
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 26 deletions.
9 changes: 0 additions & 9 deletions include/hx/Telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 35 additions & 0 deletions include/hx/TelemetryTracy.h
Original file line number Diff line number Diff line change
@@ -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 <hxcpp.h>
#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
36 changes: 19 additions & 17 deletions src/hx/TelemetryTracy.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
#include <hxcpp.h>
#include <hx/TelemetryTracy.h>
#include <hx/Thread.h>

#define TRACY_ENABLE
#include "../../project/thirdparty/tracy-0.11.1/tracy/TracyC.h"
#include "../../project/thirdparty/tracy-0.11.1/tracy/Tracy.hpp"
#include <vector>

#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;
Expand Down Expand Up @@ -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);
}

0 comments on commit 7b74420

Please sign in to comment.