Debian Codegraph @

core/profiling/SCsub

raw symbols SCIP
1 #!/usr/bin/env python
2 from __future__ import annotations
3
4 from misc.utility.scons_hints import *
5
6 import pathlib
7
8 import profiling_builders
9
10 Import("env")
11
12 env.add_source_files(env.core_sources, "*.cpp")
13
14
15 def find_perfetto_path(path: pathlib.Path) -> pathlib.Path:
16 if not path.is_dir():
17 print("profiler_path must be empty or point to a directory.")
18 Exit(255)
19
20 if (path / "sdk" / "perfetto.cc").is_file():
21 # perfetto root directory.
22 return path / "sdk"
23 if (path / "perfetto.cc").is_file():
24 # perfetto sdk directory.
25 return path
26
27 print("Invalid profiler_path. Unable to find perfetto.cc.")
28 Exit(255)
29
30
31 def find_tracy_path(path: pathlib.Path) -> pathlib.Path:
32 if not path.is_dir():
33 print("profiler_path must point to a directory.")
34 Exit(255)
35
36 if (path / "public" / "TracyClient.cpp").is_file():
37 # tracy root directory
38 return path / "public"
39 if (path / "TracyClient.cpp").is_file():
40 # tracy public directory
41 return path
42
43 print("Invalid profiler_path. Unable to find TracyClient.cpp.")
44 Exit(255)
45
46
47 if env["profiler"]:
48 if env["profiler"] == "instruments":
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.")
53 elif env["profiler"] == "tracy":
54 if not env["profiler_path"]:
55 print("profiler_path must be set when using the tracy profiler. Aborting.")
56 Exit(255)
57 profiler_path = find_tracy_path(pathlib.Path(env["profiler_path"]))
58 env.Prepend(CPPPATH=[str(profiler_path.absolute())])
59
60 env_tracy = env.Clone()
61 env_tracy.Append(CPPDEFINES=["TRACY_ENABLE"])
62 if env["profiler_sample_callstack"]:
63 if env["platform"] not in ("windows", "linuxbsd", "android"):
64 # Reference the feature matrix in the tracy documentation.
65 print("Tracy does not support call stack sampling on this platform. Aborting.")
66 Exit(255)
67
68 # 62 is the maximum supported callstack depth reported by the tracy docs.
69 env_tracy.Append(CPPDEFINES=[("TRACY_CALLSTACK", 62)])
70 if env["profiler_track_memory"]:
71 env_tracy.Append(CPPDEFINES=["GODOT_PROFILER_TRACK_MEMORY"])
72 env_tracy.disable_warnings()
73 env_tracy.add_source_files(env.core_sources, str((profiler_path / "TracyClient.cpp").absolute()))
74 elif env["profiler"] == "perfetto":
75 if not env["profiler_path"]:
76 print("profiler_path must be set when using the perfetto profiler. Aborting.")
77 Exit(255)
78 profiler_path = find_perfetto_path(pathlib.Path(env["profiler_path"]))
79 env.Prepend(CPPPATH=[str(profiler_path.absolute())])
80
81 env_perfetto = env.Clone()
82 if env["profiler_sample_callstack"]:
83 print("Perfetto does not support call stack sampling. Aborting.")
84 Exit(255)
85 if env["profiler_track_memory"]:
86 print("Perfetto does not support memory tracking. Aborting.")
87 Exit(255)
88 env_perfetto.disable_warnings()
89 env_perfetto.Prepend(CPPPATH=[str(profiler_path.absolute())])
90 env_perfetto.add_source_files(env.core_sources, str((profiler_path / "perfetto.cc").absolute()))
91 elif env["profiler_path"]:
92 print("profiler is required if profiler_path is set. Aborting.")
93 Exit(255)
94
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 )