-
Notifications
You must be signed in to change notification settings - Fork 329
NEW: Added achievable frequency and latency (processing delay) to Input Debugger (ISX-2254) #2142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ekcoh
merged 15 commits into
develop
from
isx-2254-frequency-and-latency-in-input-debugger
Mar 13, 2025
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7cb1b4c
ADD: Added frequency and latency (processing delay) to Input debugger.
ekcoh 0a77be5
Updated changelog.
ekcoh cdf7ad1
Merge branch 'develop' into isx-2254-frequency-and-latency-in-input-d…
ekcoh 0a9a9ad
Fixed formatting
ekcoh d479d44
Merge branch 'isx-2254-frequency-and-latency-in-input-debugger' of gi…
ekcoh 45573a3
Added unit tests for debugger calculators.
ekcoh 37b18db
Updated tooltip
ekcoh 40948db
Removed partial keyword accidentally added during refactoring
ekcoh 8af0ad1
Updated tooltip and field label based on review discussion
ekcoh 3cfa59d
Merge branch 'develop' into isx-2254-frequency-and-latency-in-input-d…
ekcoh 8175826
Merge branch 'develop' into isx-2254-frequency-and-latency-in-input-d…
ekcoh 30c285a
Added info to manual for new Input Debugger metrics, updated DeviceIn…
ekcoh 2858da1
Update Packages/com.unity.inputsystem/Documentation~/Debugging.md
ekcoh ced5e1a
Update Packages/com.unity.inputsystem/InputSystem/Editor/Debugger/Inp…
ekcoh 24378e2
Merge branch 'develop' into isx-2254-frequency-and-latency-in-input-d…
ekcoh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
Assets/Tests/InputSystem.Editor/InputLatencyCalculatorTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| using NUnit.Framework; | ||
| using Unity.Collections; | ||
| using UnityEngine.InputSystem.Editor; | ||
| using UnityEngine.InputSystem.LowLevel; | ||
|
|
||
| namespace Tests.InputSystem.Editor | ||
| { | ||
| public class InputLatencyCalculatorTests | ||
| { | ||
| private InputLatencyCalculator m_Sut; // Software Under Test | ||
|
|
||
| /// <summary> | ||
| /// Adds a number of samples to the calculator under test. | ||
| /// </summary> | ||
| /// <param name="currentRealtimeSinceStartup">The current timestamp (reflecting wall-clock time).</param> | ||
| /// <param name="samplesRealtimeSinceStartup">List of timestamps to be propagated as events to the calculator.</param> | ||
| private void GivenSamples(double currentRealtimeSinceStartup, params double[] samplesRealtimeSinceStartup) | ||
| { | ||
| var n = samplesRealtimeSinceStartup.Length; | ||
| using (InputEventBuffer buffer = new InputEventBuffer()) | ||
| { | ||
| unsafe | ||
| { | ||
| for (var i = 0; i < n; ++i) | ||
| { | ||
| var ptr = buffer.AllocateEvent(InputEvent.kBaseEventSize, 2048, Allocator.Temp); | ||
| ptr->time = samplesRealtimeSinceStartup[i]; | ||
| m_Sut.ProcessSample(ptr, currentRealtimeSinceStartup); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void AssertNoMetrics() | ||
| { | ||
| Assert.True(float.IsNaN(m_Sut.averageLatencySeconds)); | ||
| Assert.True(float.IsNaN(m_Sut.minLatencySeconds)); | ||
| Assert.True(float.IsNaN(m_Sut.maxLatencySeconds)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void MetricsShouldBeUndefined_WhenCalculatorHasNoSamples() | ||
| { | ||
| m_Sut = new InputLatencyCalculator(0.0); | ||
| AssertNoMetrics(); | ||
| m_Sut.Update(10.0); | ||
| AssertNoMetrics(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void MetricsShouldBeDefined_WhenCalculatorHasSamplesButPeriodHasNotElapsed() | ||
| { | ||
| m_Sut = new InputLatencyCalculator(1.0); | ||
| GivenSamples(1.9, 1.1, 1.2, 1.9); | ||
| m_Sut.Update(1.99); | ||
| AssertNoMetrics(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void MetricsShouldOnlyUpdate_WhenPeriodHasElapsed() | ||
| { | ||
| m_Sut = new InputLatencyCalculator(0.0); | ||
| GivenSamples(0.5, 0.3, 0.4, 0.5); | ||
| m_Sut.Update(1.0); | ||
| Assert.That(m_Sut.averageLatencySeconds, Is.EqualTo(0.1f)); | ||
| Assert.That(m_Sut.minLatencySeconds, Is.EqualTo(0.0f)); | ||
| Assert.That(m_Sut.maxLatencySeconds, Is.EqualTo(0.2f)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void MetricShouldNotBeAffected_WhenMoreThanAPeriodHasElapsed() | ||
| { | ||
| m_Sut = new InputLatencyCalculator(0.0); | ||
| GivenSamples(0.5, 0.3, 0.4, 0.5); | ||
| m_Sut.Update(2.0); | ||
| Assert.That(m_Sut.averageLatencySeconds, Is.EqualTo(0.1f)); | ||
| Assert.That(m_Sut.minLatencySeconds, Is.EqualTo(0.0f)); | ||
| Assert.That(m_Sut.maxLatencySeconds, Is.EqualTo(0.2f)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void MetricsShouldReset_WhenNotReceivingASampleForAPeriod() | ||
| { | ||
| m_Sut = new InputLatencyCalculator(0.0); | ||
| GivenSamples(0.5, 0.3, 0.4, 0.5); | ||
| m_Sut.Update(1.0); | ||
| m_Sut.Update(2.0); | ||
| AssertNoMetrics(); | ||
| } | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
Assets/Tests/InputSystem.Editor/InputLatencyCalculatorTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
Assets/Tests/InputSystem.Editor/SampleFrequencyCalculatorTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| using NUnit.Framework; | ||
| using Unity.Collections; | ||
| using UnityEngine.InputSystem.Editor; | ||
| using UnityEngine.InputSystem.LowLevel; | ||
|
|
||
| namespace Tests.InputSystem.Editor | ||
| { | ||
| public class SampleFrequencyCalculatorTests | ||
| { | ||
| private SampleFrequencyCalculator m_Sut; // Software Under Test | ||
|
|
||
| /// <summary> | ||
| /// Adds a number of samples to the calculator under test. | ||
| /// </summary> | ||
| /// <param name="samplesRealtimeSinceStartup">List of timestamps to be propagated as events to the calculator.</param> | ||
| private void GivenSamples(params double[] samplesRealtimeSinceStartup) | ||
| { | ||
| var n = samplesRealtimeSinceStartup.Length; | ||
| using (InputEventBuffer buffer = new InputEventBuffer()) | ||
| { | ||
| unsafe | ||
| { | ||
| for (var i = 0; i < n; ++i) | ||
| { | ||
| var ptr = buffer.AllocateEvent(InputEvent.kBaseEventSize, 2048, Allocator.Temp); | ||
| ptr->time = samplesRealtimeSinceStartup[i]; | ||
| m_Sut.ProcessSample(ptr); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public void FrequencyShouldBeZero_WhenCalculatorHasNoSamples() | ||
| { | ||
| m_Sut = new SampleFrequencyCalculator(10, 0.0); | ||
| Assert.That(m_Sut.frequency, Is.EqualTo(0.0f)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void FrequencyShouldBeZero_WhenCalculatorHasSamplesButPeriodHasNotElapsed() | ||
| { | ||
| m_Sut = new SampleFrequencyCalculator(10.0f, 1.0); | ||
| GivenSamples(1.1, 1.2, 1.9); | ||
| m_Sut.Update(1.99); | ||
| Assert.That(m_Sut.frequency, Is.EqualTo(0.0f)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void MetricsShouldOnlyUpdate_WhenPeriodHasElapsed() | ||
| { | ||
| m_Sut = new SampleFrequencyCalculator(10.0f, 0.0); | ||
| GivenSamples(0.3, 0.4, 0.5); | ||
| m_Sut.Update(1.0); | ||
| Assert.That(m_Sut.frequency, Is.EqualTo(3.0f)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void MetricsShouldBeBasedOnActualElapsedPeriod_WhenMoreThanAPeriodHasElapsed() | ||
| { | ||
| m_Sut = new SampleFrequencyCalculator(10.0f, 0.0); | ||
| GivenSamples(0.5, 0.3, 0.4, 0.5); | ||
| m_Sut.Update(2.0); | ||
| Assert.That(m_Sut.frequency, Is.EqualTo(2.0f)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void MetricsShouldNotBeUpdated_WhenLessThanAPeriodHasElapsed() | ||
| { | ||
| m_Sut = new SampleFrequencyCalculator(10.0f, 0.0); | ||
| GivenSamples(0.5, 0.3, 0.4, 0.5); | ||
| m_Sut.Update(2.0); | ||
| m_Sut.Update(2.9); | ||
| Assert.That(m_Sut.frequency, Is.EqualTo(2.0f)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void MetricsShouldReset_WhenNotReceivingASampleForAPeriod() | ||
| { | ||
| m_Sut = new SampleFrequencyCalculator(1.0f, 0.0); | ||
| GivenSamples(0.5, 0.3, 0.4, 0.5); | ||
| m_Sut.Update(1.0); | ||
| m_Sut.Update(2.0); | ||
| Assert.That(m_Sut.frequency, Is.EqualTo(0.0f)); | ||
| } | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
Assets/Tests/InputSystem.Editor/SampleFrequencyCalculatorTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.