You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-12-05 17:15:09 +00:00
Add support for profiling GDScript with tracy.
This adds macro `GodotProfileZoneGroupedFirstScript`, and uses interning for speedy lookups. Co-authored-by: Samuel Nicholas <nicholas.samuel@gmail.com>
This commit is contained in:
@@ -30,7 +30,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/typedefs.h"
|
||||
#include "profiling.gen.h"
|
||||
|
||||
// This header provides profiling primitives (implemented as macros) for various backends.
|
||||
@@ -46,9 +45,17 @@
|
||||
#if defined(GODOT_USE_TRACY)
|
||||
// Use the tracy profiler.
|
||||
|
||||
#include "core/string/string_name.h"
|
||||
|
||||
#define TRACY_ENABLE
|
||||
|
||||
#include <tracy/Tracy.hpp>
|
||||
|
||||
namespace TracyInternal {
|
||||
const char *intern_name(const StringName &p_name);
|
||||
const tracy::SourceLocationData *intern_source_location(const void *p_function_ptr, const StringName &p_file, const StringName &p_function, uint32_t p_line);
|
||||
} //namespace TracyInternal
|
||||
|
||||
// Define tracing macros.
|
||||
#define GodotProfileFrameMark FrameMark
|
||||
#define GodotProfileZone(m_zone_name) ZoneNamedN(GD_UNIQUE_NAME(__godot_tracy_szone_), m_zone_name, true)
|
||||
@@ -65,12 +72,15 @@
|
||||
static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location, TracyLine){ m_zone_name, TracyFunction, TracyFile, (uint32_t)TracyLine, 0 }; \
|
||||
new (&__godot_tracy_zone_##m_group_name) tracy::ScopedZone(&TracyConcat(__tracy_source_location, TracyLine), TRACY_CALLSTACK, true)
|
||||
#endif
|
||||
#define GodotProfileZoneGroupedFirstScript(m_varname, m_ptr, m_file, m_function, m_line) \
|
||||
tracy::ScopedZone __godot_tracy_zone_##m_group_name(TracyInternal::intern_source_location(m_ptr, m_file, m_function, m_line))
|
||||
|
||||
// Memory allocation
|
||||
#define GodotProfileAlloc(m_ptr, m_size) TracyAlloc(m_ptr, m_size)
|
||||
#define GodotProfileFree(m_ptr) TracyFree(m_ptr)
|
||||
|
||||
void godot_init_profiler();
|
||||
void godot_cleanup_profiler();
|
||||
|
||||
#elif defined(GODOT_USE_PERFETTO)
|
||||
// Use the perfetto profiler.
|
||||
@@ -101,15 +111,19 @@ struct PerfettoGroupedEventEnder {
|
||||
#define GodotProfileZoneGrouped(m_group_name, m_zone_name) \
|
||||
__godot_perfetto_zone_##m_group_name._end_now(); \
|
||||
TRACE_EVENT_BEGIN("godot", m_zone_name);
|
||||
#define GodotProfileZoneGroupedFirstScript(m_varname, m_ptr, m_file, m_function, m_line) \\ TODO
|
||||
|
||||
#define GodotProfileAlloc(m_ptr, m_size)
|
||||
#define GodotProfileFree(m_ptr)
|
||||
|
||||
void godot_init_profiler();
|
||||
void godot_cleanup_profiler();
|
||||
|
||||
#else
|
||||
// No profiling; all macros are stubs.
|
||||
|
||||
void godot_init_profiler();
|
||||
void godot_cleanup_profiler();
|
||||
|
||||
// Tell the profiling backend that a new frame has started.
|
||||
#define GodotProfileFrameMark
|
||||
@@ -128,4 +142,11 @@ void godot_init_profiler();
|
||||
// Tell the profiling backend that an allocation was freed.
|
||||
// There must be a one to one correspondence of GodotProfileAlloc and GodotProfileFree calls.
|
||||
#define GodotProfileFree(m_ptr)
|
||||
|
||||
// Define a zone with custom source information (for scripting)
|
||||
// m_varname is equivalent to GodotProfileZoneGrouped varnames.
|
||||
// m_ptr is a pointer to the function instance, which will be used for the lookup.
|
||||
// m_file, m_function are StringNames, m_line is a uint32_t, all used for the source location.
|
||||
#define GodotProfileZoneGroupedFirstScript(m_varname, m_ptr, m_file, m_function, m_line)
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user