Skip to content

Commit 2882965

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

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
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+
True,
223+
)
224+
)
225+
218226

219227
# Advanced options
220228
opts.Add(

core/profiling/SCsub

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ if env["profiler"]:
6565

6666
# 62 is the maximum supported callstack depth reported by the tracy docs.
6767
env_tracy.Append(CPPDEFINES=[("TRACY_CALLSTACK", 62)])
68+
if env["profiler_track_memory"]:
69+
env_tracy.Append(CPPDEFINES=["GODOT_PROFILER_TRACK_MEMORY"])
6870
env_tracy.disable_warnings()
6971
env_tracy.add_source_files(env.core_sources, str((profiler_path / "TracyClient.cpp").absolute()))
7072
elif env["profiler"] == "perfetto":
@@ -85,4 +87,8 @@ elif env["profiler_path"]:
8587
print("profiler is required if profiler_path is set. Aborting.")
8688
Exit(255)
8789

88-
env.CommandNoCache("profiling.gen.h", [env.Value(env["profiler"])], env.Run(profiling_builders.profiler_gen_builder))
90+
env.CommandNoCache(
91+
"profiling.gen.h",
92+
[env.Value(env["profiler"]), env.Value(env["profiler_sample_callstack"]), env.Value(env["profiler_track_memory"])],
93+
env.Run(profiling_builders.profiler_gen_builder),
94+
)

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)