engineInstrumentation.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { PerfCounter } from "../Misc/perfCounter.js";
  2. /**
  3. * This class can be used to get instrumentation data from a Babylon engine
  4. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#engineinstrumentation
  5. */
  6. export class EngineInstrumentation {
  7. // Properties
  8. /**
  9. * Gets the perf counter used for GPU frame time
  10. */
  11. get gpuFrameTimeCounter() {
  12. return this.engine.getGPUFrameTimeCounter();
  13. }
  14. /**
  15. * Gets the GPU frame time capture status
  16. */
  17. get captureGPUFrameTime() {
  18. return this._captureGPUFrameTime;
  19. }
  20. /**
  21. * Enable or disable the GPU frame time capture
  22. */
  23. set captureGPUFrameTime(value) {
  24. if (value === this._captureGPUFrameTime) {
  25. return;
  26. }
  27. this._captureGPUFrameTime = value;
  28. this.engine.captureGPUFrameTime(value);
  29. }
  30. /**
  31. * Gets the perf counter used for shader compilation time
  32. */
  33. get shaderCompilationTimeCounter() {
  34. return this._shaderCompilationTime;
  35. }
  36. /**
  37. * Gets the shader compilation time capture status
  38. */
  39. get captureShaderCompilationTime() {
  40. return this._captureShaderCompilationTime;
  41. }
  42. /**
  43. * Enable or disable the shader compilation time capture
  44. */
  45. set captureShaderCompilationTime(value) {
  46. if (value === this._captureShaderCompilationTime) {
  47. return;
  48. }
  49. this._captureShaderCompilationTime = value;
  50. if (value) {
  51. this._onBeforeShaderCompilationObserver = this.engine.onBeforeShaderCompilationObservable.add(() => {
  52. this._shaderCompilationTime.fetchNewFrame();
  53. this._shaderCompilationTime.beginMonitoring();
  54. });
  55. this._onAfterShaderCompilationObserver = this.engine.onAfterShaderCompilationObservable.add(() => {
  56. this._shaderCompilationTime.endMonitoring();
  57. });
  58. }
  59. else {
  60. this.engine.onBeforeShaderCompilationObservable.remove(this._onBeforeShaderCompilationObserver);
  61. this._onBeforeShaderCompilationObserver = null;
  62. this.engine.onAfterShaderCompilationObservable.remove(this._onAfterShaderCompilationObserver);
  63. this._onAfterShaderCompilationObserver = null;
  64. }
  65. }
  66. /**
  67. * Instantiates a new engine instrumentation.
  68. * This class can be used to get instrumentation data from a Babylon engine
  69. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#engineinstrumentation
  70. * @param engine Defines the engine to instrument
  71. */
  72. constructor(
  73. /**
  74. * Define the instrumented engine.
  75. */
  76. engine) {
  77. this.engine = engine;
  78. this._captureGPUFrameTime = false;
  79. this._captureShaderCompilationTime = false;
  80. this._shaderCompilationTime = new PerfCounter();
  81. // Observers
  82. this._onBeginFrameObserver = null;
  83. this._onEndFrameObserver = null;
  84. this._onBeforeShaderCompilationObserver = null;
  85. this._onAfterShaderCompilationObserver = null;
  86. }
  87. /**
  88. * Dispose and release associated resources.
  89. */
  90. dispose() {
  91. this.engine.onBeginFrameObservable.remove(this._onBeginFrameObserver);
  92. this._onBeginFrameObserver = null;
  93. this.engine.onEndFrameObservable.remove(this._onEndFrameObserver);
  94. this._onEndFrameObserver = null;
  95. this.engine.onBeforeShaderCompilationObservable.remove(this._onBeforeShaderCompilationObserver);
  96. this._onBeforeShaderCompilationObserver = null;
  97. this.engine.onAfterShaderCompilationObservable.remove(this._onAfterShaderCompilationObserver);
  98. this._onAfterShaderCompilationObserver = null;
  99. this.engine = null;
  100. }
  101. }
  102. //# sourceMappingURL=engineInstrumentation.js.map