|
1 | 1 | using System; |
| 2 | +using System.Collections; |
2 | 3 | using System.Collections.Generic; |
3 | 4 | using UnityEngine.InputSystem; |
4 | 5 | using UnityEngine.InputSystem.LowLevel; |
@@ -1100,4 +1101,103 @@ public void Performance_OptimizedControls_ReadingPose4kTimes(OptimizationTestTyp |
1100 | 1101 | } |
1101 | 1102 |
|
1102 | 1103 | #endif |
| 1104 | + |
| 1105 | + #if UNITY_2022_3_OR_NEWER |
| 1106 | + |
| 1107 | + // All the profiler markers in the package code. |
| 1108 | + // Needed for the tests below. |
| 1109 | + string[] allInputSystemProfilerMarkers = |
| 1110 | + { |
| 1111 | + "InputUpdate", |
| 1112 | + "InputSystem.onBeforeUpdate", |
| 1113 | + "InputSystem.onAfterUpdate", |
| 1114 | + "PreUpdate.NewInputUpdate", |
| 1115 | + "PreUpdate.InputForUIUpdate", |
| 1116 | + "FixedUpdate.NewInputFixedUpdate" |
| 1117 | + }; |
| 1118 | + |
| 1119 | + [PrebuildSetup(typeof(ProjectWideActionsBuildSetup))] |
| 1120 | + [PostBuildCleanup(typeof(ProjectWideActionsBuildSetup))] |
| 1121 | + [UnityTest, Performance] |
| 1122 | + [Category("Performance")] |
| 1123 | + public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_FPS() |
| 1124 | + { |
| 1125 | + var keyboard = InputSystem.AddDevice<Keyboard>(); |
| 1126 | + var mouse = InputSystem.AddDevice<Mouse>(); |
| 1127 | + |
| 1128 | + var moveAction = InputSystem.actions.FindAction("Move"); |
| 1129 | + var lookAction = InputSystem.actions.FindAction("Look"); |
| 1130 | + var attackAction = InputSystem.actions.FindAction("Attack"); |
| 1131 | + var jumpAction = InputSystem.actions.FindAction("Jump"); |
| 1132 | + var sprintAction = InputSystem.actions.FindAction("Sprint"); |
| 1133 | + |
| 1134 | + int performedCallCount = 0; |
| 1135 | + |
| 1136 | + moveAction.performed += context => { |
| 1137 | + performedCallCount++; |
| 1138 | + }; |
| 1139 | + |
| 1140 | + lookAction.performed += context => { |
| 1141 | + performedCallCount++; |
| 1142 | + }; |
| 1143 | + |
| 1144 | + attackAction.performed += context => { |
| 1145 | + performedCallCount++; |
| 1146 | + }; |
| 1147 | + |
| 1148 | + jumpAction.performed += context => { |
| 1149 | + performedCallCount++; |
| 1150 | + }; |
| 1151 | + |
| 1152 | + sprintAction.performed += context => { |
| 1153 | + performedCallCount++; |
| 1154 | + }; |
| 1155 | + |
| 1156 | + using (Measure.ProfilerMarkers(allInputSystemProfilerMarkers)) |
| 1157 | + { |
| 1158 | + Press(keyboard.wKey, queueEventOnly: true); |
| 1159 | + |
| 1160 | + for (int i = 0; i < 500; ++i) |
| 1161 | + { |
| 1162 | + if (i % 60 == 0) |
| 1163 | + { |
| 1164 | + PressAndRelease(keyboard.aKey, queueEventOnly: true); |
| 1165 | + PressAndRelease(keyboard.sKey, queueEventOnly: true); |
| 1166 | + PressAndRelease(keyboard.dKey, queueEventOnly: true); |
| 1167 | + |
| 1168 | + PressAndRelease(keyboard.leftShiftKey, queueEventOnly: true); |
| 1169 | + |
| 1170 | + PressAndRelease(keyboard.spaceKey, queueEventOnly: true); |
| 1171 | + } |
| 1172 | + |
| 1173 | + Click(mouse.leftButton, queueEventOnly: true); |
| 1174 | + |
| 1175 | + //mouse movements for higher polling mice |
| 1176 | + for (int j = 0; j < 99; ++j) |
| 1177 | + { |
| 1178 | + Move(mouse.position, new Vector2(i + j, i + j), queueEventOnly: true); |
| 1179 | + } |
| 1180 | + |
| 1181 | + InputSystem.Update(); |
| 1182 | + |
| 1183 | + yield return null; |
| 1184 | + } |
| 1185 | + } |
| 1186 | + } |
| 1187 | + |
| 1188 | + [PrebuildSetup(typeof(ProjectWideActionsBuildSetup))] |
| 1189 | + [PostBuildCleanup(typeof(ProjectWideActionsBuildSetup))] |
| 1190 | + [UnityTest, Performance] |
| 1191 | + [Category("Performance")] |
| 1192 | + public IEnumerator Performance_MeasureInputSystemFrameTimeWithProfilerMarkers_DoingNothing() |
| 1193 | + { |
| 1194 | + yield return Measure.Frames() |
| 1195 | + .WarmupCount(30) |
| 1196 | + .DontRecordFrametime() |
| 1197 | + .MeasurementCount(500) |
| 1198 | + .ProfilerMarkers(allInputSystemProfilerMarkers) |
| 1199 | + .Run(); |
| 1200 | + } |
| 1201 | + |
| 1202 | + #endif |
1103 | 1203 | } |
0 commit comments