Unity-jump-proj
This commit is contained in:
@ -0,0 +1,3 @@
|
||||
{
|
||||
"createSeparatePackage": false
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ebedeac5794145928b99e3e0e6169e7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,409 @@
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Performance.ProfileAnalyzer;
|
||||
using UnityEngine;
|
||||
using System.Text;
|
||||
|
||||
public class FrameTimeGraphSelectionTests
|
||||
{
|
||||
static readonly MoveTestConfiguration[] k_MoveTestConfigurations =
|
||||
{
|
||||
new MoveTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(0, 10)
|
||||
}, 10), // range[0-9] + 10
|
||||
new MoveTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(20, 10)
|
||||
}, -10), // range[20-29] - 10
|
||||
new MoveTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(50, 10),
|
||||
new TestConfiguration.SelectionRange(100, 10)
|
||||
}, 10), // multi-select range[50-59][100-109] + 10
|
||||
new MoveTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(50, 10),
|
||||
new TestConfiguration.SelectionRange(100, 10)
|
||||
}, -10), // multi-select range[50-59][100-109] - 10
|
||||
};
|
||||
|
||||
// Expects a 300 frame capture.
|
||||
static readonly MoveTestConfiguration[] k_MoveClampToBoundsTestConfigurations =
|
||||
{
|
||||
new MoveTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(0, 10)
|
||||
}, -10), // range[0-9] - 10
|
||||
new MoveTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(290, 10)
|
||||
}, 10), // range[290-299] + 10
|
||||
new MoveTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(0, 10),
|
||||
new TestConfiguration.SelectionRange(50, 10)
|
||||
}, -10), // multi-select range[0-9][50-59] - 10
|
||||
new MoveTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(0, 10),
|
||||
new TestConfiguration.SelectionRange(290, 10)
|
||||
}, 10), // multi-select range[0-9][290-299] + 10
|
||||
};
|
||||
|
||||
static readonly ResizeTestConfiguration[] k_ResizeTestConfigurations =
|
||||
{
|
||||
new ResizeTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(100, 100)
|
||||
}, -10, 10), // range[100-199] grow [-10, 10]
|
||||
new ResizeTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(100, 100)
|
||||
}, 10, -10), // range[100-199] shrink [10, -10]
|
||||
new ResizeTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(50, 50),
|
||||
new TestConfiguration.SelectionRange(200, 50)
|
||||
}, -10, 10), // multi-select range[50-99][200-249] grow [-10, 10]
|
||||
new ResizeTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(50, 50),
|
||||
new TestConfiguration.SelectionRange(200, 50)
|
||||
}, 10, -10), // multi-select range[50-99][200-249] shrink [10, -10]
|
||||
new ResizeTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(50, 50),
|
||||
new TestConfiguration.SelectionRange(200, 50)
|
||||
}, -10, 0), // multi-select range[50-99][200-249] grow left [-10, 0]
|
||||
new ResizeTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(50, 50),
|
||||
new TestConfiguration.SelectionRange(200, 50)
|
||||
}, 0, 10), // multi-select range[50-99][200-249] grow right [0, 10]
|
||||
new ResizeTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(50, 50),
|
||||
new TestConfiguration.SelectionRange(200, 50)
|
||||
}, 10, 0), // multi-select range[50-99][200-249] shrink left [10, 0]
|
||||
new ResizeTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(50, 50),
|
||||
new TestConfiguration.SelectionRange(200, 50)
|
||||
}, 0, -10), // multi-select range[50-99][200-249] shrink right [0, -10]
|
||||
};
|
||||
|
||||
// Expects a 300 frame capture.
|
||||
static readonly ResizeTestConfiguration[] k_ResizeClampToBoundsTestConfigurations =
|
||||
{
|
||||
new ResizeTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(0, 10)
|
||||
}, -10, 0), // range[0-9] grow left [-10, 0]
|
||||
new ResizeTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(290, 10)
|
||||
}, 0, 10), // range[290-299] grow right [0, 10]
|
||||
new ResizeTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(0, 10),
|
||||
new TestConfiguration.SelectionRange(50, 10)
|
||||
}, -10, 0), // range[0-9][50-59] grow left [-10, 0]
|
||||
new ResizeTestConfiguration(new TestConfiguration.SelectionRange[]
|
||||
{
|
||||
new TestConfiguration.SelectionRange(0, 10),
|
||||
new TestConfiguration.SelectionRange(290, 10)
|
||||
}, 0, 10), // range[0-9][290-299] grow right [0, 10]
|
||||
};
|
||||
|
||||
FrameTimeGraph m_FrameTimeGraph;
|
||||
List<int> m_ReportedSelection;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
var data = GenerateFrameTimeGraphData();
|
||||
m_FrameTimeGraph = NewFrameTimeGraph();
|
||||
m_FrameTimeGraph.SetData(data);
|
||||
m_FrameTimeGraph.SetRangeCallback(OnFrameTimeGraphDidSetRange);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
m_ReportedSelection = new List<int>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FrameTimeGraph_MoveSelectedRange([ValueSource("k_MoveTestConfigurations")] MoveTestConfiguration configuration)
|
||||
{
|
||||
List<int> expectedSelection = ExpectedSelectedFramesForMoveTestConfiguration(configuration);
|
||||
FrameTimeGraph_MoveSelectedRange(configuration, expectedSelection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FrameTimeGraph_MoveSelectedRange_DoesNotMovePastGraphBounds([ValueSource("k_MoveClampToBoundsTestConfigurations")] MoveTestConfiguration configuration)
|
||||
{
|
||||
List<int> expectedSelection = InitialSelectedFramesForTestConfiguration(configuration);
|
||||
FrameTimeGraph_MoveSelectedRange(configuration, expectedSelection);
|
||||
}
|
||||
|
||||
void FrameTimeGraph_MoveSelectedRange(MoveTestConfiguration configuration, List<int> expectedSelection)
|
||||
{
|
||||
var offset = configuration.offset;
|
||||
int clickCount = 1;
|
||||
bool singleClickAction = true;
|
||||
var currentSelectionState = SelectedRangeStateFromTestConfiguration(configuration);
|
||||
|
||||
m_FrameTimeGraph.MoveSelectedRange(offset, clickCount, singleClickAction, FrameTimeGraph.State.None, currentSelectionState);
|
||||
|
||||
CollectionAssert.AreEqual(expectedSelection, m_ReportedSelection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FrameTimeGraph_ResizeSelectedRange([ValueSource("k_ResizeTestConfigurations")] ResizeTestConfiguration configuration)
|
||||
{
|
||||
List<int> expectedSelection = ExpectedSelectedFramesForResizeTestConfiguration(configuration);
|
||||
FrameTimeGraph_ResizeSelectedRange(configuration, expectedSelection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FrameTimeGraph_ResizeSelectedRange_DoesNotMovePastGraphBounds([ValueSource("k_ResizeClampToBoundsTestConfigurations")] ResizeTestConfiguration configuration)
|
||||
{
|
||||
List<int> expectedSelection = InitialSelectedFramesForTestConfiguration(configuration);
|
||||
FrameTimeGraph_ResizeSelectedRange(configuration, expectedSelection);
|
||||
}
|
||||
|
||||
void FrameTimeGraph_ResizeSelectedRange(ResizeTestConfiguration configuration, List<int> expectedSelection)
|
||||
{
|
||||
var leftOffset = configuration.leftOffset;
|
||||
var rightOffset = configuration.rightOffset;
|
||||
int clickCount = 1;
|
||||
bool singleClickAction = true;
|
||||
var currentSelectionState = SelectedRangeStateFromTestConfiguration(configuration);
|
||||
|
||||
m_FrameTimeGraph.ResizeSelectedRange(leftOffset, rightOffset, clickCount, singleClickAction, FrameTimeGraph.State.None, currentSelectionState);
|
||||
|
||||
CollectionAssert.AreEqual(expectedSelection, m_ReportedSelection);
|
||||
}
|
||||
|
||||
FrameTimeGraph NewFrameTimeGraph()
|
||||
{
|
||||
var draw2D = new Draw2D("Unlit/ProfileAnalyzerShader");
|
||||
DisplayUnits displayUnits = new DisplayUnits(Units.Milliseconds);
|
||||
return new FrameTimeGraph(0, draw2D, displayUnits.Units, ProfileAnalyzerWindow.UIColor.barBackground, ProfileAnalyzerWindow.UIColor.barBackgroundSelected, ProfileAnalyzerWindow.UIColor.bar, ProfileAnalyzerWindow.UIColor.barSelected, ProfileAnalyzerWindow.UIColor.marker, ProfileAnalyzerWindow.UIColor.markerSelected, ProfileAnalyzerWindow.UIColor.thread, ProfileAnalyzerWindow.UIColor.threadSelected, ProfileAnalyzerWindow.UIColor.gridLines);
|
||||
}
|
||||
|
||||
List<FrameTimeGraph.Data> GenerateFrameTimeGraphData()
|
||||
{
|
||||
const int k_DataLength = 300;
|
||||
var data = new List<FrameTimeGraph.Data>(k_DataLength);
|
||||
int i = 0;
|
||||
while (i < k_DataLength)
|
||||
{
|
||||
var frameData = new FrameTimeGraph.Data(Random.value * 16, i);
|
||||
data.Add(frameData);
|
||||
i++;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void OnFrameTimeGraphDidSetRange(List<int> selected, int clickCount, FrameTimeGraph.State inputStatus)
|
||||
{
|
||||
m_ReportedSelection = selected;
|
||||
}
|
||||
|
||||
FrameTimeGraph.SelectedRangeState SelectedRangeStateFromTestConfiguration(TestConfiguration configuration)
|
||||
{
|
||||
List<int> selectedFrames = InitialSelectedFramesForTestConfiguration(configuration);
|
||||
int currentSelectionFirstDataOffset;
|
||||
int currentSelectionLastDataOffset;
|
||||
int firstFrameOffset;
|
||||
int lastFrameOffset;
|
||||
m_FrameTimeGraph.GetSelectedRange(selectedFrames, out currentSelectionFirstDataOffset, out currentSelectionLastDataOffset, out firstFrameOffset, out lastFrameOffset);
|
||||
|
||||
return new FrameTimeGraph.SelectedRangeState()
|
||||
{
|
||||
currentSelectionFirstDataOffset = currentSelectionFirstDataOffset,
|
||||
currentSelectionLastDataOffset = currentSelectionLastDataOffset,
|
||||
lastSelectedFrameOffsets = selectedFrames,
|
||||
};
|
||||
}
|
||||
|
||||
List<int> InitialSelectedFramesForTestConfiguration(TestConfiguration configuration)
|
||||
{
|
||||
List<int> selectedFrames = new List<int>();
|
||||
foreach (var selectionRange in configuration.selections)
|
||||
{
|
||||
var selectionFrames = GenerateListOfFrames(selectionRange.origin, selectionRange.length);
|
||||
selectedFrames.AddRange(selectionFrames);
|
||||
}
|
||||
|
||||
return selectedFrames;
|
||||
}
|
||||
|
||||
List<int> ExpectedSelectedFramesForMoveTestConfiguration(MoveTestConfiguration configuration)
|
||||
{
|
||||
List<int> selectedFrames = new List<int>();
|
||||
var offset = configuration.offset;
|
||||
foreach (var selectionRange in configuration.selections)
|
||||
{
|
||||
var selectionFrames = GenerateListOfFrames(selectionRange.origin + offset, selectionRange.length);
|
||||
selectedFrames.AddRange(selectionFrames);
|
||||
}
|
||||
|
||||
return selectedFrames;
|
||||
}
|
||||
|
||||
List<int> ExpectedSelectedFramesForResizeTestConfiguration(ResizeTestConfiguration configuration)
|
||||
{
|
||||
List<int> selectedFrames = new List<int>();
|
||||
var leftOffset = configuration.leftOffset;
|
||||
var rightOffset = configuration.rightOffset;
|
||||
foreach (var selectionRange in configuration.selections)
|
||||
{
|
||||
var leftIndex = selectionRange.origin + leftOffset;
|
||||
var rightIndex = selectionRange.LastIndex + rightOffset;
|
||||
var selectionLength = rightIndex - leftIndex + 1;
|
||||
var selectionFrames = GenerateListOfFrames(selectionRange.origin + leftOffset, selectionLength);
|
||||
selectedFrames.AddRange(selectionFrames);
|
||||
}
|
||||
|
||||
return selectedFrames;
|
||||
}
|
||||
|
||||
List<int> GenerateListOfFrames(int origin, int count)
|
||||
{
|
||||
var frames = new List<int>();
|
||||
|
||||
int i = 0;
|
||||
while (i < count)
|
||||
{
|
||||
frames.Add(origin + i);
|
||||
++i;
|
||||
}
|
||||
|
||||
return frames;
|
||||
}
|
||||
|
||||
public class TestConfiguration
|
||||
{
|
||||
public SelectionRange[] selections;
|
||||
|
||||
public TestConfiguration(SelectionRange[] selections)
|
||||
{
|
||||
this.selections = selections;
|
||||
}
|
||||
|
||||
protected string SelectionsToString()
|
||||
{
|
||||
var stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < selections.Length; ++i)
|
||||
{
|
||||
var selection = selections[i];
|
||||
stringBuilder.AppendFormat("[{0}-{1}]", selection.origin, selection.LastIndex);
|
||||
}
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
public struct SelectionRange
|
||||
{
|
||||
public int origin;
|
||||
public int length;
|
||||
|
||||
public SelectionRange(int origin, int length)
|
||||
{
|
||||
this.origin = origin;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public int LastIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return origin + length - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MoveTestConfiguration : TestConfiguration
|
||||
{
|
||||
public int offset;
|
||||
|
||||
public MoveTestConfiguration(SelectionRange[] selections, int offset) : base(selections)
|
||||
{
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var stringBuilder = new StringBuilder();
|
||||
if (selections.Length > 1)
|
||||
{
|
||||
stringBuilder.Append("multi-range");
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBuilder.Append("range");
|
||||
}
|
||||
|
||||
stringBuilder.Append(SelectionsToString());
|
||||
stringBuilder.Append(" | ");
|
||||
|
||||
stringBuilder.AppendFormat("{0}[{1}]", (offset > 0) ? "right" : "left", offset);
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public class ResizeTestConfiguration : TestConfiguration
|
||||
{
|
||||
public int leftOffset;
|
||||
public int rightOffset;
|
||||
|
||||
public ResizeTestConfiguration(SelectionRange[] selections, int leftOffset, int rightOffset) : base(selections)
|
||||
{
|
||||
this.leftOffset = leftOffset;
|
||||
this.rightOffset = rightOffset;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var stringBuilder = new StringBuilder();
|
||||
if (selections.Length > 1)
|
||||
{
|
||||
stringBuilder.Append("multi-range");
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBuilder.Append("range");
|
||||
}
|
||||
|
||||
stringBuilder.Append(SelectionsToString());
|
||||
stringBuilder.Append(" | ");
|
||||
|
||||
bool hasLeftOffset = leftOffset != 0;
|
||||
if (hasLeftOffset)
|
||||
{
|
||||
var leftAction = (leftOffset < 0) ? "grow-left" : "shrink-left";
|
||||
stringBuilder.AppendFormat("{0}[{1}]", leftAction, leftOffset);
|
||||
}
|
||||
|
||||
if (rightOffset != 0)
|
||||
{
|
||||
if (hasLeftOffset)
|
||||
{
|
||||
stringBuilder.Append(" ");
|
||||
}
|
||||
|
||||
var rightAction = (rightOffset > 0) ? "grow-right" : "shrink-right";
|
||||
stringBuilder.AppendFormat("{0}[{1}]", rightAction, rightOffset);
|
||||
}
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c21ce1fddf91fe4d972b23e8fe19d83
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,25 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEditor.Performance.ProfileAnalyzer;
|
||||
|
||||
public class MarkerDataAPITests : ProfileAnalyzerBaseTest
|
||||
{
|
||||
[Test]
|
||||
public void MarkerData_ComputeBuckets_GeneratesExpectedValues()
|
||||
{
|
||||
var marker = new MarkerData("Test Marker");
|
||||
marker.presentOnFrameCount = 1;
|
||||
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
var frameTime = new FrameTime(1, 1f * i, 1);
|
||||
marker.frames.Add(frameTime);
|
||||
}
|
||||
|
||||
marker.ComputeBuckets(0, 20);
|
||||
|
||||
for (int i = 1; i < marker.buckets.Length - 1; ++i)
|
||||
{
|
||||
Assert.IsTrue(1 == marker.buckets[i]);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cae35f26de9841808ffebd8ef49562e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,136 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEditor.Performance.ProfileAnalyzer;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class MicrosecondsUnitsFixture : UnitsTestFixture
|
||||
{
|
||||
[SetUp]
|
||||
public void SetupTest()
|
||||
{
|
||||
displayUnits = new DisplayUnits(Units.Microseconds);
|
||||
}
|
||||
}
|
||||
|
||||
public class MicrosecondsUnitsTest : MicrosecondsUnitsFixture
|
||||
{
|
||||
static TestData[] DecimalLimitValues = new TestData[]
|
||||
{
|
||||
new TestData(0.000000001f, "0.0"),
|
||||
new TestData(0.00009f, "0.1"),
|
||||
new TestData(0.0004f, "0.4"),
|
||||
new TestData(0.0005f, "0.5"),
|
||||
new TestData(0.0112f, "11.2"),
|
||||
new TestData(0.0091f, "9.1"), // Show 1 decimal point for <100us
|
||||
new TestData(0.1012f, "101"),
|
||||
new TestData(1.0012f, "1001"),
|
||||
new TestData(10.0012f, "10001"),
|
||||
new TestData(100.0012f, "100001"),
|
||||
new TestData(1000.0012f, "1000001"),
|
||||
new TestData(10000.0012f, "10000000"), // Only 6 sf valid
|
||||
new TestData(100000.0012f, "100000000"),
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void DecimalLimit([ValueSource("DecimalLimitValues")] TestData testData)
|
||||
{
|
||||
string output = displayUnits.ToString(testData.value, showUnits: false, limitToNDigits: 0, showFullValueWhenBelowZero: false);
|
||||
Assert.AreEqual(testData.expectedOutput, output);
|
||||
}
|
||||
|
||||
static TestData[] ShowFullValueWhenBelowZeroValues = new TestData[]
|
||||
{
|
||||
new TestData(0.000000001f, "1E-06"),
|
||||
new TestData(0.00009f, "0.09"),
|
||||
new TestData(0.0004f, "0.4"),
|
||||
new TestData(0.0005f, "0.5"),
|
||||
new TestData(0.0009f, "0.9"),
|
||||
new TestData(0.0015f, "1.5"),
|
||||
new TestData(0.0112f, "11.2"),
|
||||
new TestData(0.0959f, "95.9"),
|
||||
new TestData(0.1012f, "101"),
|
||||
new TestData(1.0012f, "1001"),
|
||||
new TestData(10.0012f, "10001"),
|
||||
new TestData(100.0012f, "100001"),
|
||||
new TestData(1000.0012f, "1000001"),
|
||||
new TestData(10000.0012f, "10000000"), // Only 6 sf valid
|
||||
new TestData(100000.0012f, "100000000"),
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void ShowFullValueWhenBelowZero([ValueSource("ShowFullValueWhenBelowZeroValues")] TestData testData)
|
||||
{
|
||||
string output = displayUnits.ToString(testData.value, showUnits: false, limitToNDigits: 0, showFullValueWhenBelowZero: true);
|
||||
Assert.AreEqual(testData.expectedOutput, output);
|
||||
}
|
||||
|
||||
static TestData[] WithUnitsValues = new TestData[]
|
||||
{
|
||||
new TestData(0.000000001f, "0.0us"),
|
||||
new TestData(0.00009f, "0.1us"),
|
||||
new TestData(0.0004f, "0.4us"),
|
||||
new TestData(0.0005f, "0.5us"),
|
||||
new TestData(0.0015f, "1.5us"),
|
||||
new TestData(0.0112f, "11.2us"),
|
||||
new TestData(0.1012f, "101us"),
|
||||
new TestData(1.0012f, "1001us"),
|
||||
new TestData(10.0012f, "10001us"),
|
||||
new TestData(100.0012f, "100001us"),
|
||||
new TestData(1000.0012f, "1000001us"),
|
||||
new TestData(10000.0012f, "10000000us"), // Only 6 sf valid
|
||||
new TestData(100000.0012f, "100000000us"),
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void WithUnits([ValueSource("WithUnitsValues")] TestData testData)
|
||||
{
|
||||
string output = displayUnits.ToString(testData.value, showUnits: true, limitToNDigits: 0, showFullValueWhenBelowZero: false);
|
||||
Assert.AreEqual(testData.expectedOutput, output);
|
||||
}
|
||||
|
||||
static TestData[] LimitedTo5DigitsValues = new TestData[]
|
||||
{
|
||||
new TestData(0.000000001f, "0.0"),
|
||||
new TestData(0.00009f, "0.1"),
|
||||
new TestData(0.0004f, "0.4"),
|
||||
new TestData(0.0005f, "0.5"),
|
||||
new TestData(0.0112f, "11.2"),
|
||||
new TestData(0.1012f, "101"),
|
||||
new TestData(1.0012f, "1001"),
|
||||
new TestData(10.0012f, "10001"),
|
||||
new TestData(100.0012f, "100ms"),
|
||||
new TestData(1000.0012f, "1s"),
|
||||
new TestData(10000.0012f, "10s"),
|
||||
new TestData(100000.0012f, "100s"),
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void LimitedTo5Digits([ValueSource("LimitedTo5DigitsValues")] TestData testData)
|
||||
{
|
||||
string output = displayUnits.ToString(testData.value, showUnits: false, limitToNDigits: 5, showFullValueWhenBelowZero: false);
|
||||
Assert.AreEqual(testData.expectedOutput, output);
|
||||
}
|
||||
|
||||
static TestData[] WithUnitsLimitedTo5DigitsValuesAndShowFullValueWhenBelowZeroValues = new TestData[]
|
||||
{
|
||||
new TestData(0.000000001f, "0.001ns"),
|
||||
new TestData(0.00009f, "0.09us"),
|
||||
new TestData(0.0004f, "0.4us"),
|
||||
new TestData(0.0005f, "0.5us"),
|
||||
new TestData(0.0015f, "1.5us"),
|
||||
new TestData(0.0112f, "11.2us"),
|
||||
new TestData(0.1012f, "101.2us"),
|
||||
new TestData(1.0012f, "1001.2us"),
|
||||
new TestData(10.0012f, "10001us"),
|
||||
new TestData(100.0012f, "100ms"),
|
||||
new TestData(1000.0012f, "1s"),
|
||||
new TestData(10000.0012f, "10s"), // Only 6 sf valid
|
||||
new TestData(100000.0012f, "100s"),
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void WithUnitsLimitedTo5DigitsAndShowFullValueWhenBelowZero([ValueSource("WithUnitsLimitedTo5DigitsValuesAndShowFullValueWhenBelowZeroValues")] TestData testData)
|
||||
{
|
||||
string output = displayUnits.ToString(testData.value, showUnits: true, limitToNDigits: 5, showFullValueWhenBelowZero: true);
|
||||
Assert.AreEqual(testData.expectedOutput, output);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c2bbfa09badeb746b20e00a6d41da99
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,149 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEditor.Performance.ProfileAnalyzer;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class MillisecondsUnitsFixture : UnitsTestFixture
|
||||
{
|
||||
[SetUp]
|
||||
public void SetupTest()
|
||||
{
|
||||
displayUnits = new DisplayUnits(Units.Milliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
public class MillisecondsUnitsTest : MillisecondsUnitsFixture
|
||||
{
|
||||
static TestData[] DecimalLimitValues = new TestData[]
|
||||
{
|
||||
new TestData(0.00000001f, "0.00"),
|
||||
new TestData(0.0009f, "0.00"),
|
||||
new TestData(0.004f, "0.00"),
|
||||
new TestData(0.005f, "0.01"),
|
||||
new TestData(0.1012f, "0.10"),
|
||||
new TestData(1.0012f, "1.00"),
|
||||
new TestData(10.0012f, "10.00"),
|
||||
new TestData(100.0012f, "100.00"),
|
||||
new TestData(1000.0012f, "1000.00"),
|
||||
new TestData(10000.0012f, "10000.00"),
|
||||
new TestData(100000.0012f, "100000.00"),
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void DecimalLimit([ValueSource("DecimalLimitValues")] TestData testData)
|
||||
{
|
||||
string output = displayUnits.ToString(testData.value, showUnits: false, limitToNDigits: 0, showFullValueWhenBelowZero: false);
|
||||
Assert.AreEqual(testData.expectedOutput, output);
|
||||
}
|
||||
|
||||
static TestData[] ShowFullValueWhenBelowZeroValues = new TestData[]
|
||||
{
|
||||
new TestData(0.00000001f, "1E-08"),
|
||||
new TestData(0.0009f, "0.0009"),
|
||||
new TestData(0.004f, "0.004"),
|
||||
new TestData(0.005f, "0.005"),
|
||||
new TestData(0.01f, "0.01"),
|
||||
new TestData(0.015f, "0.02"),
|
||||
new TestData(0.1012f, "0.10"),
|
||||
new TestData(1.0012f, "1.00"),
|
||||
new TestData(10.0012f, "10.00"),
|
||||
new TestData(100.0012f, "100.00"),
|
||||
new TestData(1000.0012f, "1000.00"),
|
||||
new TestData(10000.0012f, "10000.00"),
|
||||
new TestData(100000.0012f, "100000.00"),
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void ShowFullValueWhenBelowZero([ValueSource("ShowFullValueWhenBelowZeroValues")] TestData testData)
|
||||
{
|
||||
string output = displayUnits.ToString(testData.value, showUnits: false, limitToNDigits: 0, showFullValueWhenBelowZero: true);
|
||||
Assert.AreEqual(testData.expectedOutput, output);
|
||||
}
|
||||
|
||||
static TestData[] ShowUnitsValues = new TestData[]
|
||||
{
|
||||
new TestData(0.00000001f, "0.00ms"),
|
||||
new TestData(0.0009f, "0.00ms"),
|
||||
new TestData(0.004f, "0.00ms"),
|
||||
new TestData(0.005f, "0.01ms"),
|
||||
new TestData(0.1012f, "0.10ms"),
|
||||
new TestData(1.0012f, "1.00ms"),
|
||||
new TestData(10.0012f, "10.00ms"),
|
||||
new TestData(100.0012f, "100.00ms"),
|
||||
new TestData(1000.0012f, "1000.00ms"),
|
||||
new TestData(10000.0012f, "10000.00ms"),
|
||||
new TestData(100000.0012f, "100000.00ms"),
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void ShowUnits([ValueSource("ShowUnitsValues")] TestData testData)
|
||||
{
|
||||
string output = displayUnits.ToString(testData.value, showUnits: true, limitToNDigits: 0, showFullValueWhenBelowZero: false);
|
||||
Assert.AreEqual(testData.expectedOutput, output);
|
||||
}
|
||||
|
||||
static TestData[] LimitedTo5DigitsValues = new TestData[]
|
||||
{
|
||||
new TestData(0.00000001f, "0.00"),
|
||||
new TestData(0.0009f, "0.00"),
|
||||
new TestData(0.004f, "0.00"),
|
||||
new TestData(0.005f, "0.01"),
|
||||
new TestData(0.1012f, "0.10"),
|
||||
new TestData(1.0012f, "1.00"),
|
||||
new TestData(10.0012f, "10.00"),
|
||||
new TestData(100.0012f, "100.00"),
|
||||
new TestData(1000.0012f, "1000.0"),
|
||||
new TestData(10000.0012f, "10000"),
|
||||
new TestData(100000.0012f, "100s"),
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void LimitedTo5Digits([ValueSource("LimitedTo5DigitsValues")] TestData testData)
|
||||
{
|
||||
string output = displayUnits.ToString(testData.value, showUnits: false, limitToNDigits: 5, showFullValueWhenBelowZero: false);
|
||||
Assert.AreEqual(testData.expectedOutput, output);
|
||||
}
|
||||
|
||||
static TestData[] WithUnitsLimitedTo5DigitsValues = new TestData[]
|
||||
{
|
||||
new TestData(0.00000001f, "0.00ms"),
|
||||
new TestData(0.0009f, "0.00ms"),
|
||||
new TestData(0.004f, "0.00ms"),
|
||||
new TestData(0.005f, "0.01ms"),
|
||||
new TestData(0.1012f, "0.10ms"),
|
||||
new TestData(1.0012f, "1.00ms"),
|
||||
new TestData(10.0012f, "10.0ms"),
|
||||
new TestData(100.0012f, "100ms"),
|
||||
new TestData(1000.0012f, "1.00s"),
|
||||
new TestData(10000.0012f, "10.0s"),
|
||||
new TestData(100000.0012f, "100s"),
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void WithUnitsLimitedTo5Digits([ValueSource("WithUnitsLimitedTo5DigitsValues")] TestData testData)
|
||||
{
|
||||
string output = displayUnits.ToString(testData.value, showUnits: true, limitToNDigits: 5, showFullValueWhenBelowZero: false);
|
||||
Assert.AreEqual(testData.expectedOutput, output);
|
||||
}
|
||||
|
||||
static TestData[] WithUnitsLimitedTo5DigitsValuesAndShowFullValueWhenBelowZeroValues = new TestData[]
|
||||
{
|
||||
new TestData(0.00000001f, "0.01ns"),
|
||||
new TestData(0.0009f, "0.90us"),
|
||||
new TestData(0.004f, "4.00us"),
|
||||
new TestData(0.005f, "5.00us"),
|
||||
new TestData(0.1012f, "0.1012ms"),
|
||||
new TestData(1.0012f, "1.0012ms"),
|
||||
new TestData(10.0012f, "10.001ms"),
|
||||
new TestData(100.0012f, "100.00ms"),
|
||||
new TestData(1000.0012f, "1000.0ms"),
|
||||
new TestData(10000.0012f, "10000ms"),
|
||||
new TestData(100000.0012f, "100.00s"),
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void WithUnitsLimitedTo5DigitsAndShowFullValueWhenBelowZero([ValueSource("WithUnitsLimitedTo5DigitsValuesAndShowFullValueWhenBelowZeroValues")] TestData testData)
|
||||
{
|
||||
string output = displayUnits.ToString(testData.value, showUnits: true, limitToNDigits: 5, showFullValueWhenBelowZero: true);
|
||||
Assert.AreEqual(testData.expectedOutput, output);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ced04708ef2075944bfd2ab9cf8e95a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,143 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEditor.Performance.ProfileAnalyzer;
|
||||
using UnityEngine;
|
||||
|
||||
public class ProfileAnalysisAPITests : ProfileAnalyzerBaseTest
|
||||
{
|
||||
[Test]
|
||||
public void ProfileAnalysis_SetRange_ModifiesFirstLastIndices([Values(0, 2)] int first, [Values(150, 300)] int last)
|
||||
{
|
||||
var analysis = new ProfileAnalysis();
|
||||
analysis.SetRange(first, last);
|
||||
|
||||
Assert.IsTrue(first == analysis.GetFrameSummary().first);
|
||||
Assert.IsTrue(first == analysis.GetFrameSummary().minFrameIndex);
|
||||
Assert.IsTrue(first == analysis.GetFrameSummary().maxFrameIndex);
|
||||
Assert.IsTrue(last == analysis.GetFrameSummary().last);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProfileAnalysis_UpdateSummary_AddsFramesToSummary()
|
||||
{
|
||||
var analysis = new ProfileAnalysis();
|
||||
var frameSummary = analysis.GetFrameSummary();
|
||||
|
||||
Assert.IsTrue(0 == frameSummary.frames.Count);
|
||||
|
||||
analysis.UpdateSummary(0, 0.1f);
|
||||
|
||||
Assert.IsTrue(1 == frameSummary.frames.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProfileAnalysis_SetupMarkers_GeneratesExpectedValues()
|
||||
{
|
||||
var analysis = new ProfileAnalysis();
|
||||
|
||||
var marker = new MarkerData("Test Marker");
|
||||
marker.presentOnFrameCount = 1;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
var frameTime = new FrameTime(i, 0.1f * i, 1);
|
||||
marker.frames.Add(frameTime);
|
||||
}
|
||||
|
||||
analysis.AddMarker(marker);
|
||||
analysis.SetupMarkers();
|
||||
|
||||
Assert.IsTrue(marker.count == 0);
|
||||
Assert.IsTrue(marker.firstFrameIndex == -1);
|
||||
Assert.IsTrue(marker.frames.Count == 10);
|
||||
Assert.IsTrue(marker.lastFrame == -1);
|
||||
Assert.IsTrue(marker.maxDepth == 0);
|
||||
Assert.IsTrue(marker.maxFrameIndex == 9);
|
||||
Assert.IsTrue(marker.maxIndividualFrameIndex == 0);
|
||||
Assert.IsTrue(marker.medianFrameIndex == 4);
|
||||
Assert.IsTrue(marker.minDepth == 0);
|
||||
Assert.IsTrue(marker.minFrameIndex == 0);
|
||||
Assert.IsTrue(marker.minIndividualFrameIndex == 0);
|
||||
Assert.IsTrue(marker.msAtMedian == 0);
|
||||
Assert.IsTrue(marker.msMean == 0);
|
||||
Assert.IsTrue(marker.msMinIndividual == float.MaxValue);
|
||||
Assert.IsTrue(marker.msMaxIndividual == float.MinValue);
|
||||
Assert.IsTrue(marker.msMin == 0);
|
||||
Assert.IsTrue(marker.msTotal == 0);
|
||||
Assert.IsTrue(marker.name == "Test Marker");
|
||||
Assert.IsTrue(marker.presentOnFrameCount == 1);
|
||||
|
||||
//Handle floats "approximately"
|
||||
Assert.IsTrue(Mathf.Approximately(marker.msLowerQuartile, 0.2f));
|
||||
Assert.IsTrue(Mathf.Approximately(marker.msMax, 0.9f));
|
||||
Assert.IsTrue(Mathf.Approximately(marker.msUpperQuartile, 0.6f));
|
||||
Assert.IsTrue(Mathf.Approximately(marker.msMedian, 0.4f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProfileAnalysis_SetupMarkerBuckets_GeneratesExpectedValues()
|
||||
{
|
||||
var analysis = new ProfileAnalysis();
|
||||
|
||||
var marker = new MarkerData("Test Marker");
|
||||
marker.presentOnFrameCount = 1;
|
||||
|
||||
int range = 10;
|
||||
float offset = 0.000001f; // Without the offset rounding errors can shift a value into the preceeding bucket
|
||||
for (int i = 0; i <= range; ++i)
|
||||
{
|
||||
float value = ((float)i / (float)range);
|
||||
if (i != 0 && i != range)
|
||||
value += offset;
|
||||
var frameTime = new FrameTime(i, value, 1);
|
||||
marker.frames.Add(frameTime);
|
||||
}
|
||||
|
||||
analysis.AddMarker(marker);
|
||||
analysis.SetupMarkers();
|
||||
analysis.SetupMarkerBuckets();
|
||||
|
||||
Assert.IsTrue(marker.buckets[0] == 1);
|
||||
Assert.IsTrue(marker.buckets[1] == 0);
|
||||
Assert.IsTrue(marker.buckets[2] == 1);
|
||||
Assert.IsTrue(marker.buckets[3] == 0);
|
||||
Assert.IsTrue(marker.buckets[4] == 1);
|
||||
Assert.IsTrue(marker.buckets[5] == 0);
|
||||
Assert.IsTrue(marker.buckets[6] == 1);
|
||||
Assert.IsTrue(marker.buckets[7] == 0);
|
||||
Assert.IsTrue(marker.buckets[8] == 1);
|
||||
Assert.IsTrue(marker.buckets[9] == 0);
|
||||
Assert.IsTrue(marker.buckets[10] == 1);
|
||||
Assert.IsTrue(marker.buckets[11] == 0);
|
||||
Assert.IsTrue(marker.buckets[12] == 1);
|
||||
Assert.IsTrue(marker.buckets[13] == 0);
|
||||
Assert.IsTrue(marker.buckets[14] == 1);
|
||||
Assert.IsTrue(marker.buckets[15] == 0);
|
||||
Assert.IsTrue(marker.buckets[16] == 1);
|
||||
Assert.IsTrue(marker.buckets[17] == 0);
|
||||
Assert.IsTrue(marker.buckets[18] == 1);
|
||||
Assert.IsTrue(marker.buckets[19] == 1); // max value would fall into the next bucket but is clamped to here.
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProfileAnalysis_SetupFrameBuckets_GeneratesExpectedValues()
|
||||
{
|
||||
var analysis = new ProfileAnalysis();
|
||||
|
||||
var marker = new MarkerData("Test Marker");
|
||||
marker.presentOnFrameCount = 1;
|
||||
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
analysis.UpdateSummary(i, 1.0f * i);
|
||||
}
|
||||
|
||||
analysis.SetupFrameBuckets(20);
|
||||
|
||||
var summary = analysis.GetFrameSummary();
|
||||
|
||||
for (int i = 0; i < summary.buckets.Length; ++i)
|
||||
{
|
||||
Assert.IsTrue(1 == summary.buckets[i]);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30fff51cfbcd14354a89a347d5f6fc24
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,25 @@
|
||||
using NUnit.Framework;
|
||||
|
||||
public class ProfileAnalyzerAPITests : ProfileAnalyzerBaseTest
|
||||
{
|
||||
[Test]
|
||||
public void ProfileAnalyzer_EmptyAnalysis_HasNoThreads()
|
||||
{
|
||||
var analyzer = m_SetupData.analyzer;
|
||||
Assert.IsTrue(0 == analyzer.GetThreadNames().Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProfileAnalyzer_EmptyAnalysis_HasNoProgress()
|
||||
{
|
||||
var analyzer = m_SetupData.analyzer;
|
||||
Assert.IsTrue(0 == analyzer.GetProgress());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProfileAnalyzer_EmptyAnalysis_ReturnsNullForAnalysis()
|
||||
{
|
||||
var analysis = GetAnalysisFromFrameData(null);
|
||||
Assert.IsNull(analysis);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96b02e3d30e7c4599bf30551388c053b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,81 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEditor.Performance.ProfileAnalyzer;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ProfileAnalyzerBaseTest
|
||||
{
|
||||
protected struct FrameSetupData
|
||||
{
|
||||
internal ProgressBarDisplay progressBar;
|
||||
internal ProfileAnalyzer analyzer;
|
||||
internal ProfilerWindowInterface profilerWindowInterface;
|
||||
internal ProfileData profileData;
|
||||
internal int depthFilter;
|
||||
internal List<string> threadFilters;
|
||||
internal int firstFrame;
|
||||
internal int lastFrame;
|
||||
internal FrameSetupData(int minFrame, int maxFrame, int filterDepth, List<string> filterThreads)
|
||||
{
|
||||
progressBar = new ProgressBarDisplay();
|
||||
firstFrame = minFrame;
|
||||
lastFrame = maxFrame;
|
||||
analyzer = new ProfileAnalyzer();
|
||||
profilerWindowInterface = new ProfilerWindowInterface(progressBar);
|
||||
profileData = profilerWindowInterface.PullFromProfiler(minFrame, maxFrame);
|
||||
depthFilter = filterDepth;
|
||||
threadFilters = filterThreads;
|
||||
}
|
||||
};
|
||||
|
||||
protected FrameSetupData m_SetupData;
|
||||
|
||||
[SetUp]
|
||||
public void SetupTest()
|
||||
{
|
||||
ProfilerDriver.ClearAllFrames();
|
||||
m_SetupData = new FrameSetupData(1, 300, -1, new List<string> { "1:Main Thread" });
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDownTest()
|
||||
{
|
||||
}
|
||||
|
||||
List<int> SelectRange(int startIndex, int endIndex)
|
||||
{
|
||||
List<int> list = new List<int>();
|
||||
for (int c = startIndex; c <= endIndex; c++)
|
||||
{
|
||||
list.Add(c);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
internal ProfileAnalysis GetAnalysisFromFrameData(ProfileData profileData)
|
||||
{
|
||||
return m_SetupData.analyzer.Analyze(profileData,
|
||||
SelectRange(m_SetupData.firstFrame, m_SetupData.lastFrame),
|
||||
m_SetupData.threadFilters,
|
||||
m_SetupData.depthFilter);
|
||||
}
|
||||
|
||||
protected void StartProfiler()
|
||||
{
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
ProfilerDriver.enabled = true;
|
||||
#endif
|
||||
ProfilerDriver.profileEditor = true;
|
||||
}
|
||||
|
||||
protected void StopProfiler()
|
||||
{
|
||||
EditorApplication.isPlaying = false;
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
ProfilerDriver.enabled = false;
|
||||
#endif
|
||||
ProfilerDriver.profileEditor = false;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15e793ef718504da48ec583556c5e284
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,48 @@
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
public class ProfileAnalyzerCaptureTests : ProfileAnalyzerBaseTest
|
||||
{
|
||||
[UnityTest]
|
||||
public IEnumerator PlayMode_Capture_ContainsNoDuplicates()
|
||||
{
|
||||
StartProfiler();
|
||||
|
||||
yield return null;
|
||||
yield return null;
|
||||
yield return null;
|
||||
yield return null;
|
||||
yield return null;
|
||||
|
||||
StopProfiler();
|
||||
|
||||
// Seem to need one more frame to get the data transfered over so the profile analyzer can pull it.
|
||||
yield return null;
|
||||
|
||||
//analyze the data
|
||||
m_SetupData.profileData = m_SetupData.profilerWindowInterface.PullFromProfiler(m_SetupData.firstFrame, m_SetupData.lastFrame);
|
||||
var analysis = GetAnalysisFromFrameData(m_SetupData.profileData);
|
||||
|
||||
var analysisMarkers = analysis.GetMarkers();
|
||||
var analysisMarkerDict = new Dictionary<string, int>();
|
||||
for (int i = 0; i < analysisMarkers.Count; ++i)
|
||||
{
|
||||
int count = 0;
|
||||
string curName = analysisMarkers[i].name;
|
||||
|
||||
analysisMarkerDict.TryGetValue(curName, out count);
|
||||
|
||||
analysisMarkerDict[curName] = count + 1;
|
||||
}
|
||||
|
||||
Assert.IsTrue(0 != analysisMarkerDict.Count, "analysisMarkerSet count is zero!");
|
||||
|
||||
foreach (var entry in analysisMarkerDict)
|
||||
{
|
||||
Assert.IsTrue(1 == entry.Value, "Duplicates found in analysis marker list: " + entry.Key);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afac56376261b4bd093a5a46f7c0c6d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,62 @@
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ProfileAnalyzerEmptyTests : ProfileAnalyzerBaseTest
|
||||
{
|
||||
List<int> SelectRange(int startIndex, int endIndex)
|
||||
{
|
||||
List<int> list = new List<int>();
|
||||
for (int c = startIndex; c <= endIndex; c++)
|
||||
{
|
||||
list.Add(c);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProfileAnalyzer_EmptyData_IsEmpty()
|
||||
{
|
||||
int k_FirstFrameInProfiler = 1;
|
||||
int k_LastFrameInProfiler = 300;
|
||||
int k_FrameCountInProfiler = k_LastFrameInProfiler - k_FirstFrameInProfiler + 1;
|
||||
// the first and last frame are incomplete (empty) and therefore removed from the frame count of the loaded data in Profile Analyzer
|
||||
int k_FrameCountInProfileAnalyzer = k_FrameCountInProfiler - 2;
|
||||
// The first frame is invalid,
|
||||
int k_FirstValidFrameInProfiler = k_FirstFrameInProfiler + 1;
|
||||
// the first frame being missing is adjusted for via the frame offset, so only the last frame needs to be trimmed in
|
||||
int k_LastFrameInProfileAnalyzer = k_LastFrameInProfiler - 1;
|
||||
|
||||
var analyzer = m_SetupData.analyzer;
|
||||
var profileData = m_SetupData.profilerWindowInterface.PullFromProfiler(k_FirstFrameInProfiler, k_LastFrameInProfiler);
|
||||
var depthFilter = m_SetupData.depthFilter;
|
||||
var threadFilters = m_SetupData.threadFilters;
|
||||
|
||||
int firstFrameIndex = profileData.OffsetToDisplayFrame(0);
|
||||
int lastFrameIndex = profileData.OffsetToDisplayFrame(profileData.GetFrameCount() - 1);
|
||||
|
||||
Assert.AreEqual(k_FirstValidFrameInProfiler, firstFrameIndex, "First Frame index not " + k_FirstValidFrameInProfiler);
|
||||
Assert.AreEqual(k_LastFrameInProfileAnalyzer, lastFrameIndex, "Last Frame index is not " + k_LastFrameInProfileAnalyzer);
|
||||
|
||||
var analysis = analyzer.Analyze(profileData, SelectRange(firstFrameIndex, lastFrameIndex), threadFilters, depthFilter);
|
||||
var frameSummary = analysis.GetFrameSummary();
|
||||
|
||||
Assert.AreEqual(0, analysis.GetThreads().Count);
|
||||
Assert.AreEqual(0, frameSummary.msTotal);
|
||||
Assert.AreEqual(k_FirstValidFrameInProfiler, frameSummary.first);
|
||||
Assert.AreEqual(k_LastFrameInProfileAnalyzer, frameSummary.last);
|
||||
Assert.AreEqual(k_FrameCountInProfileAnalyzer, frameSummary.count);
|
||||
Assert.AreEqual(0, frameSummary.msMean);
|
||||
Assert.AreEqual(0, frameSummary.msMedian);
|
||||
Assert.AreEqual(0, frameSummary.msLowerQuartile);
|
||||
Assert.AreEqual(0, frameSummary.msUpperQuartile);
|
||||
Assert.AreEqual(0, frameSummary.msMin);
|
||||
Assert.AreEqual(0, frameSummary.msMax);
|
||||
Assert.AreEqual(Mathf.RoundToInt((float)(k_LastFrameInProfileAnalyzer + 0.1f) / 2.0f), frameSummary.medianFrameIndex);
|
||||
Assert.AreEqual(k_FirstValidFrameInProfiler, frameSummary.minFrameIndex);
|
||||
Assert.AreEqual(k_FirstValidFrameInProfiler, frameSummary.maxFrameIndex);
|
||||
Assert.AreEqual(0, frameSummary.maxMarkerDepth);
|
||||
Assert.AreEqual(0, frameSummary.totalMarkers);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df8088010ce864bf5b2342f7d6a5803c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,84 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEditor.Performance.ProfileAnalyzer;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ProfileDataAPITests : ProfileAnalyzerBaseTest
|
||||
{
|
||||
[Test]
|
||||
public void ProfileData_AddMarkerName_AddsMarkerAndContainsName()
|
||||
{
|
||||
var data = new ProfileData();
|
||||
var markerNames = new List<string>()
|
||||
{
|
||||
"Marker01",
|
||||
"Marker02",
|
||||
"Marker03",
|
||||
"Marker04"
|
||||
};
|
||||
|
||||
var markerList = new List<ProfileMarker>();
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
var marker = new ProfileMarker()
|
||||
{
|
||||
msMarkerTotal = 0.5f,
|
||||
depth = i
|
||||
};
|
||||
|
||||
int expectedIndex = i % markerNames.Count;
|
||||
data.AddMarkerName(markerNames[expectedIndex], marker);
|
||||
markerList.Add(marker);
|
||||
|
||||
Assert.IsTrue(expectedIndex == marker.nameIndex, "Index mismatch at: " + i + " , " + marker.nameIndex);;
|
||||
}
|
||||
|
||||
for (int i = 0; i < markerList.Count; ++i)
|
||||
{
|
||||
var curName = data.GetMarkerName(markerList[i]);
|
||||
Assert.IsTrue(markerNames.Contains(curName));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProfileData_AddThreadName_AddsThreadAndContainsName()
|
||||
{
|
||||
var data = new ProfileData();
|
||||
var threadNames = new List<string>()
|
||||
{
|
||||
"Thread01",
|
||||
"Thread02",
|
||||
"Thread03",
|
||||
"Thread04"
|
||||
};
|
||||
|
||||
var threadDict = new Dictionary<string, ProfileThread>();
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
int expectedIndex = i % threadNames.Count;
|
||||
string threadName = threadNames[expectedIndex];
|
||||
ProfileThread thread;
|
||||
|
||||
if (!threadDict.TryGetValue(threadName, out thread))
|
||||
{
|
||||
thread = new ProfileThread();
|
||||
threadDict.Add(threadName, thread);
|
||||
}
|
||||
|
||||
var marker = new ProfileMarker()
|
||||
{
|
||||
msMarkerTotal = 0.5f,
|
||||
depth = i
|
||||
};
|
||||
|
||||
thread.markers.Add(marker);
|
||||
data.AddThreadName(threadName, thread);
|
||||
Assert.IsTrue(expectedIndex == thread.threadIndex, "Index mismatch at: " + i + " , " + thread.threadIndex);;
|
||||
}
|
||||
|
||||
foreach (var curThread in threadDict)
|
||||
{
|
||||
var curName = data.GetThreadName(curThread.Value);
|
||||
Assert.IsTrue(threadNames.Contains(curName));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 542691619c7a540408193902ae073a51
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,38 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEditor.Performance.ProfileAnalyzer;
|
||||
|
||||
public class ProfileDataTests
|
||||
{
|
||||
[Test]
|
||||
public void Save_WithNullData_ReturnsFalse()
|
||||
{
|
||||
var filename = "filename.pdata";
|
||||
ProfileData nullProfileData = null;
|
||||
|
||||
bool success = ProfileData.Save(filename, nullProfileData);
|
||||
|
||||
Assert.IsFalse(success, "Calling ProfileData.Save with null data should return false.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Save_WithNullFilename_ReturnsFalse()
|
||||
{
|
||||
string filename = null;
|
||||
var profileData = new ProfileData();
|
||||
|
||||
bool success = ProfileData.Save(filename, profileData);
|
||||
|
||||
Assert.IsFalse(success, "Calling ProfileData.Save with a null filename should return false.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Save_WithEmptyFilename_ReturnsFalse()
|
||||
{
|
||||
string filename = string.Empty;
|
||||
var profileData = new ProfileData();
|
||||
|
||||
bool success = ProfileData.Save(filename, profileData);
|
||||
|
||||
Assert.IsFalse(success, "Calling ProfileData.Save with an empty filename should return false.");
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1751800eb256f54f81cc0f9c81c6cc7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,25 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEditor.Performance.ProfileAnalyzer;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class UnitsTestFixture
|
||||
{
|
||||
internal DisplayUnits displayUnits;
|
||||
|
||||
public struct TestData
|
||||
{
|
||||
public readonly float value;
|
||||
public readonly string expectedOutput;
|
||||
|
||||
public TestData(float value, string expectedOutput)
|
||||
{
|
||||
this.value = value;
|
||||
this.expectedOutput = expectedOutput;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0} becomes {1}", value, expectedOutput);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52c7ca0f6ab0a464883f39201b038df6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "Unity.Performance.Profile-Analyzer.EditorTests",
|
||||
"references": [
|
||||
"Unity.Performance.Profile-Analyzer.Editor"
|
||||
],
|
||||
"optionalUnityReferences": [
|
||||
"TestAssemblies"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": []
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97505fd80b553409c995f274ad2a533b
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user