SCsub 3.7 KB

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