Skip to content

Commit 393daf6

Browse files
committed
Make memory profiling optional
1 parent 757bba1 commit 393daf6

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

SConstruct

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,14 @@ opts.Add(
215215
False,
216216
)
217217
)
218+
opts.Add(
219+
BoolVariable(
220+
"profiler_track_memory",
221+
"Profile memory allocations, if the profiler supports it.",
222+
False,
223+
)
224+
)
225+
218226

219227
# Advanced options
220228
opts.Add(

core/profiling/SCsub

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ def find_tracy_path(path: pathlib.Path) -> pathlib.Path:
4646

4747
if env["profiler"]:
4848
if env["profiler"] == "instruments":
49-
# Nothing else to do for Instruments.
50-
pass
49+
if env["profiler_sample_callstack"]:
50+
print("profiler_sample_callstack ignored. Please configure callstack sampling in Instruments instead.")
51+
if env["profiler_track_memory"]:
52+
print("profiler_track_memory ignored. Please configure memory tracking in Instruments instead.")
5153
elif env["profiler"] == "tracy":
5254
if not env["profiler_path"]:
5355
print("profiler_path must be set when using the tracy profiler. Aborting.")
@@ -65,6 +67,8 @@ if env["profiler"]:
6567

6668
# 62 is the maximum supported callstack depth reported by the tracy docs.
6769
env_tracy.Append(CPPDEFINES=[("TRACY_CALLSTACK", 62)])
70+
if env["profiler_track_memory"]:
71+
env_tracy.Append(CPPDEFINES=["GODOT_PROFILER_TRACK_MEMORY"])
6872
env_tracy.disable_warnings()
6973
env_tracy.add_source_files(env.core_sources, str((profiler_path / "TracyClient.cpp").absolute()))
7074
elif env["profiler"] == "perfetto":
@@ -78,11 +82,18 @@ if env["profiler"]:
7882
if env["profiler_sample_callstack"]:
7983
print("Perfetto does not support call stack sampling. Aborting.")
8084
Exit(255)
85+
if env["profiler_track_memory"]:
86+
print("Perfetto does not support memory tracking. Aborting.")
87+
Exit(255)
8188
env_perfetto.disable_warnings()
8289
env_perfetto.Prepend(CPPPATH=[str(profiler_path.absolute())])
8390
env_perfetto.add_source_files(env.core_sources, str((profiler_path / "perfetto.cc").absolute()))
8491
elif env["profiler_path"]:
8592
print("profiler is required if profiler_path is set. Aborting.")
8693
Exit(255)
8794

88-
env.CommandNoCache("profiling.gen.h", [env.Value(env["profiler"])], env.Run(profiling_builders.profiler_gen_builder))
95+
env.CommandNoCache(
96+
"profiling.gen.h",
97+
[env.Value(env["profiler"]), env.Value(env["profiler_sample_callstack"]), env.Value(env["profiler_track_memory"])],
98+
env.Run(profiling_builders.profiler_gen_builder),
99+
)

core/profiling/profiling.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@ const tracy::SourceLocationData *intern_source_location(const void *p_function_p
7676
tracy::ScopedZone __godot_tracy_zone_##m_group_name(TracyInternal::intern_source_location(m_ptr, m_file, m_function, m_line))
7777

7878
// Memory allocation
79+
#ifdef GODOT_PROFILER_TRACK_MEMORY
7980
#define GodotProfileAlloc(m_ptr, m_size) TracyAlloc(m_ptr, m_size)
8081
#define GodotProfileFree(m_ptr) TracyFree(m_ptr)
82+
#else
83+
#define GodotProfileAlloc(m_ptr, m_size)
84+
#define GodotProfileFree(m_ptr)
85+
#endif
8186

8287
void godot_init_profiler();
8388
void godot_cleanup_profiler();

core/profiling/profiling_builders.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ def profiler_gen_builder(target, source, env):
99
file.write("#define GODOT_USE_TRACY\n")
1010
if env["profiler_sample_callstack"]:
1111
file.write("#define TRACY_CALLSTACK 62\n")
12+
if env["profiler_track_memory"]:
13+
file.write("#define GODOT_PROFILER_TRACK_MEMORY\n")
1214
if env["profiler"] == "perfetto":
1315
file.write("#define GODOT_USE_PERFETTO\n")
1416
if env["profiler"] == "instruments":

0 commit comments

Comments
 (0)