Core: Add Apple Instruments support

This commit is contained in:
Stuart Carnie 2025-11-30 08:59:13 +11:00
parent 25203e24c4
commit 93b6348cfe
5 changed files with 131 additions and 19 deletions

View file

@ -12,35 +12,47 @@ Import("env")
env.add_source_files(env.core_sources, "*.cpp")
def get_profiler_and_path_from_path(path: pathlib.Path) -> tuple[str, pathlib.Path]:
def find_perfetto_path(path: pathlib.Path) -> pathlib.Path:
if not path.is_dir():
print("profiler_path must be empty or point to a directory.")
Exit(255)
if (path / "sdk" / "perfetto.cc").is_file():
# perfetto root directory.
return "perfetto", path / "sdk"
return path / "sdk"
if (path / "perfetto.cc").is_file():
# perfetto sdk directory.
return "perfetto", path
return path
if (path / "public" / "TracyClient.cpp").is_file():
# tracy root directory
return "tracy", path / "public"
if (path / "TracyClient.cpp").is_file():
# tracy public directory
return "tracy", path
print("Unrecognized profiler_path option. Please set a path to either tracy or perfetto.")
print("Invalid profiler_path. Unable to find perfetto.cc.")
Exit(255)
env["profiler"] = None
if env["profiler_path"]:
profiler_name, profiler_path = get_profiler_and_path_from_path(pathlib.Path(env["profiler_path"]))
env["profiler"] = profiler_name
def find_tracy_path(path: pathlib.Path) -> pathlib.Path:
if not path.is_dir():
print("profiler_path must point to a directory.")
Exit(255)
if profiler_name == "tracy":
if (path / "public" / "TracyClient.cpp").is_file():
# tracy root directory
return path / "public"
if (path / "TracyClient.cpp").is_file():
# tracy public directory
return path
print("Invalid profiler_path. Unable to find TracyClient.cpp.")
Exit(255)
if env["profiler"]:
if env["profiler"] == "instruments":
# Nothing else to do for Instruments.
pass
elif env["profiler"] == "tracy":
if not env["profiler_path"]:
print("profiler_path must be set when using the tracy profiler. Aborting.")
Exit(255)
profiler_path = find_tracy_path(pathlib.Path(env["profiler_path"]))
env.Prepend(CPPPATH=[str(profiler_path.absolute())])
env_tracy = env.Clone()
@ -55,7 +67,11 @@ if env["profiler_path"]:
env_tracy.Append(CPPDEFINES=[("TRACY_CALLSTACK", 62)])
env_tracy.disable_warnings()
env_tracy.add_source_files(env.core_sources, str((profiler_path / "TracyClient.cpp").absolute()))
elif profiler_name == "perfetto":
elif env["profiler"] == "perfetto":
if not env["profiler_path"]:
print("profiler_path must be set when using the perfetto profiler. Aborting.")
Exit(255)
profiler_path = find_perfetto_path(pathlib.Path(env["profiler_path"]))
env.Prepend(CPPPATH=[str(profiler_path.absolute())])
env_perfetto = env.Clone()
@ -65,6 +81,8 @@ if env["profiler_path"]:
env_perfetto.disable_warnings()
env_perfetto.Prepend(CPPPATH=[str(profiler_path.absolute())])
env_perfetto.add_source_files(env.core_sources, str((profiler_path / "perfetto.cc").absolute()))
elif env["profiler_path"]:
print("profiler is required if profiler_path is set. Aborting.")
Exit(255)
env.CommandNoCache("profiling.gen.h", [env.Value(env["profiler"])], env.Run(profiling_builders.profiler_gen_builder))