From 0e7ea940366216a37f3a69fe08190cdfc61023df Mon Sep 17 00:00:00 2001 From: Stefan Schubert Date: Mon, 7 Oct 2024 14:49:26 +0200 Subject: [PATCH 1/7] new tests initial version --- .../Tests/InputSystem/CorePerformanceTests.cs | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/Assets/Tests/InputSystem/CorePerformanceTests.cs b/Assets/Tests/InputSystem/CorePerformanceTests.cs index e5480672bd..b895775892 100644 --- a/Assets/Tests/InputSystem/CorePerformanceTests.cs +++ b/Assets/Tests/InputSystem/CorePerformanceTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using UnityEngine.InputSystem; using UnityEngine.InputSystem.LowLevel; @@ -1100,4 +1101,70 @@ public void Performance_OptimizedControls_ReadingPose4kTimes(OptimizationTestTyp } #endif + +#if UNITY_2022_3_OR_NEWER + [PrebuildSetup(typeof(ProjectWideActionsBuildSetup))] + [PostBuildCleanup(typeof(ProjectWideActionsBuildSetup))] + [UnityTest, Performance] + [Category("Performance")] + public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkersSimpleUseCase() + { + string[] markers = + { + "InputUpdate", + "InputSystem.onBeforeUpdate", + "InputSystem.onAfterUpdate", + "PreUpdate.NewInputUpdate", + "PreUpdate.InputForUIUpdate", + "FixedUpdate.NewInputFixedUpdate" + }; + + using(Measure.ProfilerMarkers(markers)) + { + var gamepad = InputSystem.AddDevice(); + var keyboard = InputSystem.AddDevice(); + + for (var i = 0; i < 100; ++i) + { + Set(gamepad.leftStick, new Vector2(i / 1000f, i / 1000f), queueEventOnly: true); + Press(gamepad.buttonSouth, queueEventOnly: true); + Press(gamepad.buttonNorth, queueEventOnly: true); + Release(gamepad.buttonSouth, queueEventOnly: true); + Release(gamepad.buttonNorth, queueEventOnly: true); + + PressAndRelease(keyboard.wKey, queueEventOnly: true); + PressAndRelease(keyboard.aKey, queueEventOnly: true); + PressAndRelease(keyboard.sKey, queueEventOnly: true); + PressAndRelease(keyboard.dKey, queueEventOnly: true); + + InputSystem.Update(); + yield return null; + } + } + } + + [PrebuildSetup(typeof(ProjectWideActionsBuildSetup))] + [PostBuildCleanup(typeof(ProjectWideActionsBuildSetup))] + [UnityTest, Performance] + [Category("Performance")] + public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkersDoingNothing() + { + string[] markers = + { + "InputUpdate", + "InputSystem.onBeforeUpdate", + "InputSystem.onAfterUpdate", + "PreUpdate.NewInputUpdate", + "PreUpdate.InputForUIUpdate", + "FixedUpdate.NewInputFixedUpdate" + }; + + yield return Measure.Frames() + .WarmupCount(30) + .DontRecordFrametime() + .MeasurementCount(300) + .ProfilerMarkers(markers) + .Run(); + } } +#endif \ No newline at end of file From 09f414de0ef8eed5c26dace9029fc8a13bfad5b4 Mon Sep 17 00:00:00 2001 From: Stefan Schubert Date: Wed, 9 Oct 2024 16:14:51 +0200 Subject: [PATCH 2/7] adding callbacks to triggered actions --- .../Tests/InputSystem/CorePerformanceTests.cs | 110 +++++++++++++++--- 1 file changed, 97 insertions(+), 13 deletions(-) diff --git a/Assets/Tests/InputSystem/CorePerformanceTests.cs b/Assets/Tests/InputSystem/CorePerformanceTests.cs index b895775892..335948e69d 100644 --- a/Assets/Tests/InputSystem/CorePerformanceTests.cs +++ b/Assets/Tests/InputSystem/CorePerformanceTests.cs @@ -13,6 +13,7 @@ using UnityEngine.InputSystem.Users; using UnityEngine.InputSystem.Utilities; using UnityEngine.TestTools; +using static System.Collections.Specialized.BitVector32; ////TODO: add test for domain reload logic @@ -1107,7 +1108,7 @@ public void Performance_OptimizedControls_ReadingPose4kTimes(OptimizationTestTyp [PostBuildCleanup(typeof(ProjectWideActionsBuildSetup))] [UnityTest, Performance] [Category("Performance")] - public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkersSimpleUseCase() + public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_FPS() { string[] markers = { @@ -1118,31 +1119,114 @@ public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkersSim "PreUpdate.InputForUIUpdate", "FixedUpdate.NewInputFixedUpdate" }; + + var keyboard = InputSystem.AddDevice(); + var mouse = InputSystem.AddDevice(); + + var moveAction = InputSystem.actions.FindAction("Move"); + var lookAction = InputSystem.actions.FindAction("Look"); + var attackAction = InputSystem.actions.FindAction("Attack"); + + int performedCallCount = 0; + + moveAction.performed += context => { + + performedCallCount++; + }; + + lookAction.performed += context => { + + performedCallCount++; + }; + + attackAction.performed += context => { + + performedCallCount++; + }; using(Measure.ProfilerMarkers(markers)) - { - var gamepad = InputSystem.AddDevice(); - var keyboard = InputSystem.AddDevice(); - + { for (var i = 0; i < 100; ++i) { - Set(gamepad.leftStick, new Vector2(i / 1000f, i / 1000f), queueEventOnly: true); - Press(gamepad.buttonSouth, queueEventOnly: true); - Press(gamepad.buttonNorth, queueEventOnly: true); - Release(gamepad.buttonSouth, queueEventOnly: true); - Release(gamepad.buttonNorth, queueEventOnly: true); - PressAndRelease(keyboard.wKey, queueEventOnly: true); PressAndRelease(keyboard.aKey, queueEventOnly: true); PressAndRelease(keyboard.sKey, queueEventOnly: true); - PressAndRelease(keyboard.dKey, queueEventOnly: true); + PressAndRelease(keyboard.dKey, queueEventOnly: true); - InputSystem.Update(); + Click(mouse.leftButton, queueEventOnly: true); + + Move(mouse.position, new Vector2(i, i), queueEventOnly: true); + + InputSystem.Update(); + yield return null; } } } + [PrebuildSetup(typeof(ProjectWideActionsBuildSetup))] + [PostBuildCleanup(typeof(ProjectWideActionsBuildSetup))] + [UnityTest, Performance] + [Category("Performance")] + public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_Touch() + { + string[] markers = + { + "InputUpdate", + "InputSystem.onBeforeUpdate", + "InputSystem.onAfterUpdate", + "PreUpdate.NewInputUpdate", + "PreUpdate.InputForUIUpdate", + "FixedUpdate.NewInputFixedUpdate" + }; + + var touchScreen = InputSystem.AddDevice(); + + int performedCallCount = 0; + + var lookAction = InputSystem.actions.FindAction("Look"); + var attackAction = InputSystem.actions.FindAction("Attack"); + attackAction.AddBinding("/press"); + + + lookAction.performed += context => { + + performedCallCount++; + //Debug.Log(context.control.ToString()); + }; + + attackAction.performed += context => { + + performedCallCount++; + Debug.Log(context.control.ToString()); + }; + + BeginTouch(1, new Vector2(1, 2), queueEventOnly: true); + + using(Measure.ProfilerMarkers(markers)) + { + for (var i = 0; i < 100; ++i) + { + MoveTouch(1, new Vector2(1+i, 2+i), queueEventOnly: true); + + if(i % 2 == 0) { + BeginTouch(2, new Vector2(40+i, 40+i), queueEventOnly: true); + } + + else { + EndTouch(2, new Vector2(40+i-1, 40+i-1), queueEventOnly: true); + } + + InputSystem.Update(); + + Debug.Log(performedCallCount); + + yield return null; + } + } + } + + [PrebuildSetup(typeof(ProjectWideActionsBuildSetup))] [PostBuildCleanup(typeof(ProjectWideActionsBuildSetup))] [UnityTest, Performance] From 13f67b77210d35fb3366df7044d3b9f0f2f0c7ad Mon Sep 17 00:00:00 2001 From: Stefan Schubert Date: Wed, 9 Oct 2024 16:48:19 +0200 Subject: [PATCH 3/7] higher mouse movement rate --- .../Tests/InputSystem/CorePerformanceTests.cs | 89 +++++-------------- 1 file changed, 23 insertions(+), 66 deletions(-) diff --git a/Assets/Tests/InputSystem/CorePerformanceTests.cs b/Assets/Tests/InputSystem/CorePerformanceTests.cs index 335948e69d..dff65d8ade 100644 --- a/Assets/Tests/InputSystem/CorePerformanceTests.cs +++ b/Assets/Tests/InputSystem/CorePerformanceTests.cs @@ -1126,6 +1126,8 @@ public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_FP var moveAction = InputSystem.actions.FindAction("Move"); var lookAction = InputSystem.actions.FindAction("Look"); var attackAction = InputSystem.actions.FindAction("Attack"); + var jumpAction = InputSystem.actions.FindAction("Jump"); + var sprintAction = InputSystem.actions.FindAction("Sprint"); int performedCallCount = 0; @@ -1143,95 +1145,50 @@ public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_FP performedCallCount++; }; + + jumpAction.performed += context => { + + performedCallCount++; + }; + + sprintAction.performed += context => { + + performedCallCount++; + }; using(Measure.ProfilerMarkers(markers)) { - for (var i = 0; i < 100; ++i) + for (int i = 0; i < 500; ++i) { PressAndRelease(keyboard.wKey, queueEventOnly: true); PressAndRelease(keyboard.aKey, queueEventOnly: true); PressAndRelease(keyboard.sKey, queueEventOnly: true); PressAndRelease(keyboard.dKey, queueEventOnly: true); - Click(mouse.leftButton, queueEventOnly: true); - - Move(mouse.position, new Vector2(i, i), queueEventOnly: true); - - InputSystem.Update(); - - yield return null; - } - } - } - - [PrebuildSetup(typeof(ProjectWideActionsBuildSetup))] - [PostBuildCleanup(typeof(ProjectWideActionsBuildSetup))] - [UnityTest, Performance] - [Category("Performance")] - public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_Touch() - { - string[] markers = - { - "InputUpdate", - "InputSystem.onBeforeUpdate", - "InputSystem.onAfterUpdate", - "PreUpdate.NewInputUpdate", - "PreUpdate.InputForUIUpdate", - "FixedUpdate.NewInputFixedUpdate" - }; - - var touchScreen = InputSystem.AddDevice(); - - int performedCallCount = 0; - - var lookAction = InputSystem.actions.FindAction("Look"); - var attackAction = InputSystem.actions.FindAction("Attack"); - attackAction.AddBinding("/press"); + PressAndRelease(keyboard.leftShiftKey, queueEventOnly: true); - - lookAction.performed += context => { - - performedCallCount++; - //Debug.Log(context.control.ToString()); - }; - - attackAction.performed += context => { - - performedCallCount++; - Debug.Log(context.control.ToString()); - }; - - BeginTouch(1, new Vector2(1, 2), queueEventOnly: true); + PressAndRelease(keyboard.spaceKey, queueEventOnly: true); - using(Measure.ProfilerMarkers(markers)) - { - for (var i = 0; i < 100; ++i) - { - MoveTouch(1, new Vector2(1+i, 2+i), queueEventOnly: true); + Click(mouse.leftButton, queueEventOnly: true); - if(i % 2 == 0) { - BeginTouch(2, new Vector2(40+i, 40+i), queueEventOnly: true); - } - - else { - EndTouch(2, new Vector2(40+i-1, 40+i-1), queueEventOnly: true); + //mouse movements for higher polling mice (66*60 ~ 4kHz) + for (int j = 0; j < 66; ++j) { + + Move(mouse.position, new Vector2(i+j, i+j), queueEventOnly: true); } - InputSystem.Update(); - - Debug.Log(performedCallCount); + InputSystem.Update(); yield return null; } } } - [PrebuildSetup(typeof(ProjectWideActionsBuildSetup))] [PostBuildCleanup(typeof(ProjectWideActionsBuildSetup))] [UnityTest, Performance] [Category("Performance")] - public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkersDoingNothing() + public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_DoingNothing() { string[] markers = { @@ -1246,7 +1203,7 @@ public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkersDoi yield return Measure.Frames() .WarmupCount(30) .DontRecordFrametime() - .MeasurementCount(300) + .MeasurementCount(500) .ProfilerMarkers(markers) .Run(); } From 6ad080c4b72ac9c1e73a562a132290e0f25af78f Mon Sep 17 00:00:00 2001 From: Stefan Schubert Date: Thu, 10 Oct 2024 11:32:55 +0200 Subject: [PATCH 4/7] formatting --- .../Tests/InputSystem/CorePerformanceTests.cs | 64 +++++++++---------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/Assets/Tests/InputSystem/CorePerformanceTests.cs b/Assets/Tests/InputSystem/CorePerformanceTests.cs index dff65d8ade..139a2f9903 100644 --- a/Assets/Tests/InputSystem/CorePerformanceTests.cs +++ b/Assets/Tests/InputSystem/CorePerformanceTests.cs @@ -1103,11 +1103,11 @@ public void Performance_OptimizedControls_ReadingPose4kTimes(OptimizationTestTyp #endif -#if UNITY_2022_3_OR_NEWER + #if UNITY_2022_3_OR_NEWER [PrebuildSetup(typeof(ProjectWideActionsBuildSetup))] [PostBuildCleanup(typeof(ProjectWideActionsBuildSetup))] [UnityTest, Performance] - [Category("Performance")] + [Category("Performance")] public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_FPS() { string[] markers = @@ -1118,46 +1118,41 @@ public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_FP "PreUpdate.NewInputUpdate", "PreUpdate.InputForUIUpdate", "FixedUpdate.NewInputFixedUpdate" - }; + }; var keyboard = InputSystem.AddDevice(); var mouse = InputSystem.AddDevice(); - + var moveAction = InputSystem.actions.FindAction("Move"); var lookAction = InputSystem.actions.FindAction("Look"); var attackAction = InputSystem.actions.FindAction("Attack"); var jumpAction = InputSystem.actions.FindAction("Jump"); var sprintAction = InputSystem.actions.FindAction("Sprint"); - + int performedCallCount = 0; - moveAction.performed += context => { - - performedCallCount++; + moveAction.performed += context => { + performedCallCount++; }; - + lookAction.performed += context => { - - performedCallCount++; + performedCallCount++; }; - - attackAction.performed += context => { - - performedCallCount++; + + attackAction.performed += context => { + performedCallCount++; }; - jumpAction.performed += context => { - + jumpAction.performed += context => { performedCallCount++; }; - sprintAction.performed += context => { - - performedCallCount++; + sprintAction.performed += context => { + performedCallCount++; }; - - using(Measure.ProfilerMarkers(markers)) - { + + using (Measure.ProfilerMarkers(markers)) + { for (int i = 0; i < 500; ++i) { PressAndRelease(keyboard.wKey, queueEventOnly: true); @@ -1169,18 +1164,18 @@ public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_FP PressAndRelease(keyboard.spaceKey, queueEventOnly: true); - Click(mouse.leftButton, queueEventOnly: true); - + Click(mouse.leftButton, queueEventOnly: true); + //mouse movements for higher polling mice (66*60 ~ 4kHz) - for (int j = 0; j < 66; ++j) { - - Move(mouse.position, new Vector2(i+j, i+j), queueEventOnly: true); + for (int j = 0; j < 66; ++j) + { + Move(mouse.position, new Vector2(i + j, i + j), queueEventOnly: true); } InputSystem.Update(); - + yield return null; - } + } } } @@ -1198,14 +1193,15 @@ public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_Do "PreUpdate.NewInputUpdate", "PreUpdate.InputForUIUpdate", "FixedUpdate.NewInputFixedUpdate" - }; + }; yield return Measure.Frames() .WarmupCount(30) - .DontRecordFrametime() + .DontRecordFrametime() .MeasurementCount(500) .ProfilerMarkers(markers) - .Run(); + .Run(); } + + #endif } -#endif \ No newline at end of file From 79525e045620aef6636af2f751375e40b02f6862 Mon Sep 17 00:00:00 2001 From: Stefan Schubert Date: Thu, 10 Oct 2024 16:55:26 +0200 Subject: [PATCH 5/7] review feedback --- .../Tests/InputSystem/CorePerformanceTests.cs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Assets/Tests/InputSystem/CorePerformanceTests.cs b/Assets/Tests/InputSystem/CorePerformanceTests.cs index 139a2f9903..5e788445f1 100644 --- a/Assets/Tests/InputSystem/CorePerformanceTests.cs +++ b/Assets/Tests/InputSystem/CorePerformanceTests.cs @@ -1153,21 +1153,26 @@ public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_FP using (Measure.ProfilerMarkers(markers)) { + + Press(keyboard.wKey, queueEventOnly: true); + for (int i = 0; i < 500; ++i) { - PressAndRelease(keyboard.wKey, queueEventOnly: true); - PressAndRelease(keyboard.aKey, queueEventOnly: true); - PressAndRelease(keyboard.sKey, queueEventOnly: true); - PressAndRelease(keyboard.dKey, queueEventOnly: true); + + if (i % 60 == 0) { + PressAndRelease(keyboard.aKey, queueEventOnly: true); + PressAndRelease(keyboard.sKey, queueEventOnly: true); + PressAndRelease(keyboard.dKey, queueEventOnly: true); - PressAndRelease(keyboard.leftShiftKey, queueEventOnly: true); + PressAndRelease(keyboard.leftShiftKey, queueEventOnly: true); - PressAndRelease(keyboard.spaceKey, queueEventOnly: true); + PressAndRelease(keyboard.spaceKey, queueEventOnly: true); + } Click(mouse.leftButton, queueEventOnly: true); - //mouse movements for higher polling mice (66*60 ~ 4kHz) - for (int j = 0; j < 66; ++j) + //mouse movements for higher polling mice + for (int j = 0; j < 99; ++j) { Move(mouse.position, new Vector2(i + j, i + j), queueEventOnly: true); } From 93dff2b0853e09026f0e374123dfde00617f003a Mon Sep 17 00:00:00 2001 From: Stefan Schubert Date: Thu, 10 Oct 2024 17:34:20 +0200 Subject: [PATCH 6/7] formatting --- Assets/Tests/InputSystem/CorePerformanceTests.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Assets/Tests/InputSystem/CorePerformanceTests.cs b/Assets/Tests/InputSystem/CorePerformanceTests.cs index 5e788445f1..1a866c0c69 100644 --- a/Assets/Tests/InputSystem/CorePerformanceTests.cs +++ b/Assets/Tests/InputSystem/CorePerformanceTests.cs @@ -1153,13 +1153,12 @@ public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_FP using (Measure.ProfilerMarkers(markers)) { - Press(keyboard.wKey, queueEventOnly: true); for (int i = 0; i < 500; ++i) { - - if (i % 60 == 0) { + if (i % 60 == 0) + { PressAndRelease(keyboard.aKey, queueEventOnly: true); PressAndRelease(keyboard.sKey, queueEventOnly: true); PressAndRelease(keyboard.dKey, queueEventOnly: true); From 9d8d5f7b7584dac4a764af26591fcf0a928cb2ae Mon Sep 17 00:00:00 2001 From: Stefan Schubert Date: Wed, 23 Oct 2024 15:05:29 +0200 Subject: [PATCH 7/7] move profiler markers array to class level --- .../Tests/InputSystem/CorePerformanceTests.cs | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/Assets/Tests/InputSystem/CorePerformanceTests.cs b/Assets/Tests/InputSystem/CorePerformanceTests.cs index 1a866c0c69..5d7d8ac230 100644 --- a/Assets/Tests/InputSystem/CorePerformanceTests.cs +++ b/Assets/Tests/InputSystem/CorePerformanceTests.cs @@ -13,7 +13,6 @@ using UnityEngine.InputSystem.Users; using UnityEngine.InputSystem.Utilities; using UnityEngine.TestTools; -using static System.Collections.Specialized.BitVector32; ////TODO: add test for domain reload logic @@ -1104,22 +1103,25 @@ public void Performance_OptimizedControls_ReadingPose4kTimes(OptimizationTestTyp #endif #if UNITY_2022_3_OR_NEWER + + // All the profiler markers in the package code. + // Needed for the tests below. + string[] allInputSystemProfilerMarkers = + { + "InputUpdate", + "InputSystem.onBeforeUpdate", + "InputSystem.onAfterUpdate", + "PreUpdate.NewInputUpdate", + "PreUpdate.InputForUIUpdate", + "FixedUpdate.NewInputFixedUpdate" + }; + [PrebuildSetup(typeof(ProjectWideActionsBuildSetup))] [PostBuildCleanup(typeof(ProjectWideActionsBuildSetup))] [UnityTest, Performance] [Category("Performance")] public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_FPS() { - string[] markers = - { - "InputUpdate", - "InputSystem.onBeforeUpdate", - "InputSystem.onAfterUpdate", - "PreUpdate.NewInputUpdate", - "PreUpdate.InputForUIUpdate", - "FixedUpdate.NewInputFixedUpdate" - }; - var keyboard = InputSystem.AddDevice(); var mouse = InputSystem.AddDevice(); @@ -1151,7 +1153,7 @@ public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_FP performedCallCount++; }; - using (Measure.ProfilerMarkers(markers)) + using (Measure.ProfilerMarkers(allInputSystemProfilerMarkers)) { Press(keyboard.wKey, queueEventOnly: true); @@ -1189,21 +1191,11 @@ public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_FP [Category("Performance")] public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_DoingNothing() { - string[] markers = - { - "InputUpdate", - "InputSystem.onBeforeUpdate", - "InputSystem.onAfterUpdate", - "PreUpdate.NewInputUpdate", - "PreUpdate.InputForUIUpdate", - "FixedUpdate.NewInputFixedUpdate" - }; - yield return Measure.Frames() .WarmupCount(30) .DontRecordFrametime() .MeasurementCount(500) - .ProfilerMarkers(markers) + .ProfilerMarkers(allInputSystemProfilerMarkers) .Run(); }