You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-12-30 18:30:54 +00:00
Make memory profiling optional
This commit is contained in:
@@ -215,6 +215,14 @@ opts.Add(
|
|||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
opts.Add(
|
||||||
|
BoolVariable(
|
||||||
|
"profiler_track_memory",
|
||||||
|
"Profile memory allocations, if the profiler supports it.",
|
||||||
|
False,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Advanced options
|
# Advanced options
|
||||||
opts.Add(
|
opts.Add(
|
||||||
|
|||||||
@@ -46,8 +46,10 @@ def find_tracy_path(path: pathlib.Path) -> pathlib.Path:
|
|||||||
|
|
||||||
if env["profiler"]:
|
if env["profiler"]:
|
||||||
if env["profiler"] == "instruments":
|
if env["profiler"] == "instruments":
|
||||||
# Nothing else to do for Instruments.
|
if env["profiler_sample_callstack"]:
|
||||||
pass
|
print("profiler_sample_callstack ignored. Please configure callstack sampling in Instruments instead.")
|
||||||
|
if env["profiler_track_memory"]:
|
||||||
|
print("profiler_track_memory ignored. Please configure memory tracking in Instruments instead.")
|
||||||
elif env["profiler"] == "tracy":
|
elif env["profiler"] == "tracy":
|
||||||
if not env["profiler_path"]:
|
if not env["profiler_path"]:
|
||||||
print("profiler_path must be set when using the tracy profiler. Aborting.")
|
print("profiler_path must be set when using the tracy profiler. Aborting.")
|
||||||
@@ -65,6 +67,8 @@ if env["profiler"]:
|
|||||||
|
|
||||||
# 62 is the maximum supported callstack depth reported by the tracy docs.
|
# 62 is the maximum supported callstack depth reported by the tracy docs.
|
||||||
env_tracy.Append(CPPDEFINES=[("TRACY_CALLSTACK", 62)])
|
env_tracy.Append(CPPDEFINES=[("TRACY_CALLSTACK", 62)])
|
||||||
|
if env["profiler_track_memory"]:
|
||||||
|
env_tracy.Append(CPPDEFINES=["GODOT_PROFILER_TRACK_MEMORY"])
|
||||||
env_tracy.disable_warnings()
|
env_tracy.disable_warnings()
|
||||||
env_tracy.add_source_files(env.core_sources, str((profiler_path / "TracyClient.cpp").absolute()))
|
env_tracy.add_source_files(env.core_sources, str((profiler_path / "TracyClient.cpp").absolute()))
|
||||||
elif env["profiler"] == "perfetto":
|
elif env["profiler"] == "perfetto":
|
||||||
@@ -78,6 +82,9 @@ if env["profiler"]:
|
|||||||
if env["profiler_sample_callstack"]:
|
if env["profiler_sample_callstack"]:
|
||||||
print("Perfetto does not support call stack sampling. Aborting.")
|
print("Perfetto does not support call stack sampling. Aborting.")
|
||||||
Exit(255)
|
Exit(255)
|
||||||
|
if env["profiler_track_memory"]:
|
||||||
|
print("Perfetto does not support memory tracking. Aborting.")
|
||||||
|
Exit(255)
|
||||||
env_perfetto.disable_warnings()
|
env_perfetto.disable_warnings()
|
||||||
env_perfetto.Prepend(CPPPATH=[str(profiler_path.absolute())])
|
env_perfetto.Prepend(CPPPATH=[str(profiler_path.absolute())])
|
||||||
env_perfetto.add_source_files(env.core_sources, str((profiler_path / "perfetto.cc").absolute()))
|
env_perfetto.add_source_files(env.core_sources, str((profiler_path / "perfetto.cc").absolute()))
|
||||||
@@ -85,4 +92,8 @@ elif env["profiler_path"]:
|
|||||||
print("profiler is required if profiler_path is set. Aborting.")
|
print("profiler is required if profiler_path is set. Aborting.")
|
||||||
Exit(255)
|
Exit(255)
|
||||||
|
|
||||||
env.CommandNoCache("profiling.gen.h", [env.Value(env["profiler"])], env.Run(profiling_builders.profiler_gen_builder))
|
env.CommandNoCache(
|
||||||
|
"profiling.gen.h",
|
||||||
|
[env.Value(env["profiler"]), env.Value(env["profiler_sample_callstack"]), env.Value(env["profiler_track_memory"])],
|
||||||
|
env.Run(profiling_builders.profiler_gen_builder),
|
||||||
|
)
|
||||||
|
|||||||
@@ -76,8 +76,16 @@ const tracy::SourceLocationData *intern_source_location(const void *p_function_p
|
|||||||
tracy::ScopedZone __godot_tracy_zone_##m_group_name(TracyInternal::intern_source_location(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
|
// Memory allocation
|
||||||
#define GodotProfileAlloc(m_ptr, m_size) TracyAlloc(m_ptr, m_size)
|
#ifdef GODOT_PROFILER_TRACK_MEMORY
|
||||||
|
#define GodotProfileAlloc(m_ptr, m_size) \
|
||||||
|
GODOT_GCC_WARNING_PUSH_AND_IGNORE("-Wmaybe-uninitialized") \
|
||||||
|
TracyAlloc(m_ptr, m_size); \
|
||||||
|
GODOT_GCC_WARNING_POP
|
||||||
#define GodotProfileFree(m_ptr) TracyFree(m_ptr)
|
#define GodotProfileFree(m_ptr) TracyFree(m_ptr)
|
||||||
|
#else
|
||||||
|
#define GodotProfileAlloc(m_ptr, m_size)
|
||||||
|
#define GodotProfileFree(m_ptr)
|
||||||
|
#endif
|
||||||
|
|
||||||
void godot_init_profiler();
|
void godot_init_profiler();
|
||||||
void godot_cleanup_profiler();
|
void godot_cleanup_profiler();
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ def profiler_gen_builder(target, source, env):
|
|||||||
file.write("#define GODOT_USE_TRACY\n")
|
file.write("#define GODOT_USE_TRACY\n")
|
||||||
if env["profiler_sample_callstack"]:
|
if env["profiler_sample_callstack"]:
|
||||||
file.write("#define TRACY_CALLSTACK 62\n")
|
file.write("#define TRACY_CALLSTACK 62\n")
|
||||||
|
if env["profiler_track_memory"]:
|
||||||
|
file.write("#define GODOT_PROFILER_TRACK_MEMORY\n")
|
||||||
if env["profiler"] == "perfetto":
|
if env["profiler"] == "perfetto":
|
||||||
file.write("#define GODOT_USE_PERFETTO\n")
|
file.write("#define GODOT_USE_PERFETTO\n")
|
||||||
if env["profiler"] == "instruments":
|
if env["profiler"] == "instruments":
|
||||||
|
|||||||
Reference in New Issue
Block a user