diff --git a/src/Sentry.Unity/SentryBehavior.cs b/src/Sentry.Unity/SentryBehavior.cs index 957f131a3..6eca76187 100644 --- a/src/Sentry.Unity/SentryBehavior.cs +++ b/src/Sentry.Unity/SentryBehavior.cs @@ -1,18 +1,68 @@ -using Sentry; +using System; +using System.Collections; +using System.Threading; using UnityEngine; -using Sentry.Unity; -using System; -using Sentry.Protocol; -public class SentryBehavior : MonoBehaviour +namespace Sentry.Unity { - public void Disable() + public class SentryBehavior : MonoBehaviour { - - } + private int goodFrames; + private int slowFrames; + private int frozFrames; + + private float slowThreshold = 0.02f; + private float frozThreshold = 1.0f; + + private float lastTime; + + private void Start() + { + frozThreshold = Time.maximumDeltaTime; + } + + private void Update() + { + MeasureDeltaTime(); + CheckFrame(); + + if (Input.GetKeyDown(KeyCode.S)) + { + var sleepDuration = Time.maximumDeltaTime + 0.1f; + Debug.Log($"=========== Sleep for: {sleepDuration}ms ==========="); + Thread.Sleep((int)(sleepDuration * 1000)); + } + } - // TODO: Flush events. See note on OnApplicationQuit - //private void OnApplicationPause() => - // TODO: Flush events, see note on OnApplicationQuit - // private void OnApplicationFocus { if (!focusStatus) Flush events! } + private void MeasureDeltaTime() + { + var measuredDeltaTime = Time.realtimeSinceStartup - lastTime; + lastTime = Time.realtimeSinceStartup; + Debug.Log($"Measured delta time: {measuredDeltaTime}"); + } + + private void CheckFrame() + { + if (Time.deltaTime >= frozThreshold) + { + frozFrames++; + } + else if (Time.deltaTime > slowThreshold) + { + slowFrames++; + } + else + { + goodFrames++; + } + + Debug.Log($"Good: {goodFrames} | Slow: {slowFrames} | Frozen: {frozFrames}"); + } + + + // TODO: Flush events. See note on OnApplicationQuit + //private void OnApplicationPause() => + // TODO: Flush events, see note on OnApplicationQuit + // private void OnApplicationFocus { if (!focusStatus) Flush events! } + } }