Skip to content

Commit 9cefa77

Browse files
author
Unity Technologies
committed
com.unity.test-framework.performance@0.1.42-preview
## [0.1.42] - 2018-10-15 ### Improvements to report window and minor fixes Save profiler output on perf tests Add a button on report window to open profiler output for test Remove unsupported features for legacy scripting runtime Fix version attribute for test cases Remove unnecessary assembly definition ## [0.1.41] - 2018-10-2 ### Test report graph
1 parent 835a624 commit 9cefa77

File tree

12 files changed

+149
-65
lines changed

12 files changed

+149
-65
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## [0.1.42] - 2018-10-15
4+
5+
### Improvements to report window and minor fixes
6+
7+
Save profiler output on perf tests
8+
Add a button on report window to open profiler output for test
9+
Remove unsupported features for legacy scripting runtime
10+
Fix version attribute for test cases
11+
Remove unnecessary assembly definition
12+
313
## [0.1.41] - 2018-10-2
414

515
### Test report graph
80.7 KB
Loading

Documentation~/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,19 @@ The Performance Test Report is split into two views: the *test view* and the *sa
289289

290290
![Performance test report](images/graphtool.png)
291291

292+
## Viewing profiler data
293+
294+
When running performance tests on editor or standalone platforms, the framework saves profiler data locally for each test. To view profiler data for a test:
295+
1. Open Profiler window
296+
2. Open Performance Test Report window
297+
3. Select the test you wish to view profiler data
298+
4. Click on "Load profiler data for test"
299+
5. Go back to profiler window, the data should be loaded
300+
301+
*Note: If the button is not visible, it means profiler data has not been saved for the test.*
302+
303+
![Open profiler button](images/graphtool2.png)
304+
292305
## More Examples
293306

294307
#### Example 1: Measure execution time to serialize simple object to JSON

Editor/TestReportGraph/Gintas.TestRunner.Graph.asmdef

Lines changed: 0 additions & 16 deletions
This file was deleted.

Editor/TestReportGraph/Gintas.TestRunner.Graph.asmdef.meta

Lines changed: 0 additions & 7 deletions
This file was deleted.

Editor/TestReportGraph/TestListTable.cs

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,27 @@ class TestListTableItem : TreeViewItem
1313
public PerformanceTest test;
1414
public double deviation;
1515
public double standardDeviation;
16+
public double median;
1617

17-
public TestListTableItem(int id, int depth, string displayName, PerformanceTest test) : base(id, depth, displayName)
18+
public TestListTableItem(int id, int depth, string displayName, PerformanceTest test) : base(id, depth,
19+
displayName)
1820
{
1921
this.test = test;
2022

2123
deviation = 0f;
22-
if (test!=null)
24+
if (test != null)
2325
{
2426
foreach (var sample in test.SampleGroups)
2527
{
2628
if (sample.StandardDeviation > deviation)
2729
standardDeviation = sample.StandardDeviation;
28-
30+
2931
double thisDeviation = sample.StandardDeviation / sample.Median;
3032
if (thisDeviation > deviation)
33+
{
3134
deviation = thisDeviation;
35+
median = sample.Median;
36+
}
3237
}
3338
}
3439
}
@@ -48,6 +53,7 @@ public enum MyColumns
4853
SampleCount,
4954
StandardDeviation,
5055
Deviation,
56+
Median
5157
}
5258

5359
public enum SortOption
@@ -56,6 +62,7 @@ public enum SortOption
5662
SampleCount,
5763
StandardDeviation,
5864
Deviation,
65+
Median
5966
}
6067

6168
// Sort options per column
@@ -65,20 +72,25 @@ public enum SortOption
6572
SortOption.SampleCount,
6673
SortOption.StandardDeviation,
6774
SortOption.Deviation,
75+
SortOption.Median
6876
};
6977

7078

71-
public TestListTable(TreeViewState state, MultiColumnHeader multicolumnHeader, TestReportWindow testReportWindow) : base(state, multicolumnHeader)
79+
public TestListTable(TreeViewState state, MultiColumnHeader multicolumnHeader,
80+
TestReportWindow testReportWindow) : base(state, multicolumnHeader)
7281
{
7382
m_testReportWindow = testReportWindow;
7483

75-
Assert.AreEqual(m_SortOptions.Length, Enum.GetValues(typeof(MyColumns)).Length, "Ensure number of sort options are in sync with number of MyColumns enum values");
84+
Assert.AreEqual(m_SortOptions.Length, Enum.GetValues(typeof(MyColumns)).Length,
85+
"Ensure number of sort options are in sync with number of MyColumns enum values");
7686

7787
// Custom setup
7888
rowHeight = kRowHeights;
7989
showAlternatingRowBackgrounds = true;
8090
showBorder = true;
81-
customFoldoutYOffset = (kRowHeights - EditorGUIUtility.singleLineHeight) * 0.5f; // center foldout in the row since we also center content. See RowGUI
91+
customFoldoutYOffset =
92+
(kRowHeights - EditorGUIUtility.singleLineHeight) *
93+
0.5f; // center foldout in the row since we also center content. See RowGUI
8294
// extraSpaceBeforeIconAndLabel = 0;
8395
multicolumnHeader.sortingChanged += OnSortingChanged;
8496

@@ -186,6 +198,9 @@ void SortByMultipleColumns()
186198
case SortOption.StandardDeviation:
187199
orderedQuery = orderedQuery.ThenBy(l => l.standardDeviation, ascending);
188200
break;
201+
case SortOption.Median:
202+
orderedQuery = orderedQuery.ThenBy(l => l.median, ascending);
203+
break;
189204
}
190205
}
191206

@@ -206,6 +221,8 @@ IOrderedEnumerable<TestListTableItem> InitialOrder(IEnumerable<TestListTableItem
206221
return myTypes.Order(l => l.deviation, ascending);
207222
case SortOption.StandardDeviation:
208223
return myTypes.Order(l => l.standardDeviation, ascending);
224+
case SortOption.Median:
225+
return myTypes.Order(l => l.median, ascending);
209226
default:
210227
Assert.IsTrue(false, "Unhandled enum");
211228
break;
@@ -217,11 +234,11 @@ IOrderedEnumerable<TestListTableItem> InitialOrder(IEnumerable<TestListTableItem
217234

218235
protected override void RowGUI(RowGUIArgs args)
219236
{
220-
var item = (TestListTableItem)args.item;
237+
var item = (TestListTableItem) args.item;
221238

222239
for (int i = 0; i < args.GetNumVisibleColumns(); ++i)
223240
{
224-
CellGUI(args.GetCellRect(i), item, (MyColumns)args.GetColumn(i), ref args);
241+
CellGUI(args.GetCellRect(i), item, (MyColumns) args.GetColumn(i), ref args);
225242
}
226243
}
227244

@@ -233,10 +250,10 @@ void CellGUI(Rect cellRect, TestListTableItem item, MyColumns column, ref RowGUI
233250
switch (column)
234251
{
235252
case MyColumns.Name:
236-
{
237-
args.rowRect = cellRect;
238-
base.RowGUI(args);
239-
}
253+
{
254+
args.rowRect = cellRect;
255+
base.RowGUI(args);
256+
}
240257
break;
241258
case MyColumns.SampleCount:
242259
EditorGUI.LabelField(cellRect, string.Format("{0}", item.test.SampleGroups.Count));
@@ -247,6 +264,9 @@ void CellGUI(Rect cellRect, TestListTableItem item, MyColumns column, ref RowGUI
247264
case MyColumns.StandardDeviation:
248265
EditorGUI.LabelField(cellRect, string.Format("{0:f2}", item.standardDeviation));
249266
break;
267+
case MyColumns.Median:
268+
EditorGUI.LabelField(cellRect, string.Format("{0:f2}", item.median));
269+
break;
250270
}
251271
}
252272

@@ -273,7 +293,7 @@ public static MultiColumnHeaderState CreateDefaultMultiColumnHeaderState(float t
273293
autoResize = false,
274294
allowToggleVisibility = false
275295
});
276-
string[] names = { "Sample Groups", "Standard Deviation", "Deviation" };
296+
string[] names = {"Sample Groups", "Standard Deviation", "Deviation", "Median"};
277297
foreach (var name in names)
278298
{
279299
var column = new MultiColumnHeaderState.Column
@@ -287,18 +307,23 @@ public static MultiColumnHeaderState CreateDefaultMultiColumnHeaderState(float t
287307
autoResize = true
288308
};
289309
columnList.Add(column);
290-
};
310+
}
311+
312+
;
291313
var columns = columnList.ToArray();
292314

293-
Assert.AreEqual(columns.Length, Enum.GetValues(typeof(MyColumns)).Length, "Number of columns should match number of enum values: You probably forgot to update one of them.");
315+
Assert.AreEqual(columns.Length, Enum.GetValues(typeof(MyColumns)).Length,
316+
"Number of columns should match number of enum values: You probably forgot to update one of them.");
294317

295318
var state = new MultiColumnHeaderState(columns);
296-
state.visibleColumns = new int[] {
297-
(int)MyColumns.Name,
298-
(int)MyColumns.SampleCount,
299-
(int)MyColumns.Deviation,
300-
(int)MyColumns.StandardDeviation
301-
};
319+
state.visibleColumns = new int[]
320+
{
321+
(int) MyColumns.Name,
322+
(int) MyColumns.SampleCount,
323+
(int) MyColumns.Deviation,
324+
(int) MyColumns.StandardDeviation,
325+
(int) MyColumns.Median
326+
};
302327
return state;
303328
}
304329

@@ -313,7 +338,8 @@ protected override void SelectionChanged(IList<int> selectedIds)
313338

314339
static class MyExtensionMethods
315340
{
316-
public static IOrderedEnumerable<T> Order<T, TKey>(this IEnumerable<T> source, Func<T, TKey> selector, bool ascending)
341+
public static IOrderedEnumerable<T> Order<T, TKey>(this IEnumerable<T> source, Func<T, TKey> selector,
342+
bool ascending)
317343
{
318344
if (ascending)
319345
{
@@ -325,7 +351,8 @@ public static IOrderedEnumerable<T> Order<T, TKey>(this IEnumerable<T> source, F
325351
}
326352
}
327353

328-
public static IOrderedEnumerable<T> ThenBy<T, TKey>(this IOrderedEnumerable<T> source, Func<T, TKey> selector, bool ascending)
354+
public static IOrderedEnumerable<T> ThenBy<T, TKey>(this IOrderedEnumerable<T> source, Func<T, TKey> selector,
355+
bool ascending)
329356
{
330357
if (ascending)
331358
{
@@ -337,4 +364,4 @@ public static IOrderedEnumerable<T> ThenBy<T, TKey>(this IOrderedEnumerable<T> s
337364
}
338365
}
339366
}
340-
}
367+
}

Editor/TestReportGraph/TestReportWindow.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.IO;
99
using System.Linq;
1010
using Unity.PerformanceTesting;
11+
using Unity.PerformanceTesting.Runtime;
1112

1213
namespace Unity.PerformanceTesting
1314
{
@@ -25,6 +26,7 @@ public class TestReportWindow : EditorWindow
2526
public Color m_colorStandardLine = new Color(1.0f, 1.0f, 1.0f);
2627
public Color m_colorMedianLine = new Color(0.2f, 0.5f, 1.0f, 0.5f);
2728
public Color m_colorMedianText = new Color(0.4f, 0.7f, 1.0f, 1.0f);
29+
public Color m_colorWarningText = Color.red;
2830
private PerformanceTestRun m_resultsData;
2931
private string m_selectedTest;
3032

@@ -177,10 +179,6 @@ private void OnGUI()
177179
Draw();
178180
}
179181

180-
private void Update()
181-
{
182-
}
183-
184182
private double GetPercentageOffset(List<SamplePoint> samplePoint, float percent, out int outputFrameIndex)
185183
{
186184
int index = (int) ((samplePoint.Count - 1) * percent / 100);
@@ -240,9 +238,9 @@ private void Draw()
240238
{
241239
LoadData();
242240
CreateTestListTable();
243-
if(m_resultsData == null) return;
244-
if(m_resultsData.Results == null) return;
245-
if(m_resultsData.Results.Any(result => result.TestName == m_selectedTest))
241+
if (m_resultsData == null) return;
242+
if (m_resultsData.Results == null) return;
243+
if (m_resultsData.Results.Any(result => result.TestName == m_selectedTest))
246244
SelectTest(m_selectedTest);
247245
else
248246
SelectTest(0);
@@ -251,7 +249,7 @@ private void Draw()
251249
if (m_resultsData == null)
252250
return;
253251

254-
if (m_resultsData.Results.Count <=0)
252+
if (m_resultsData.Results.Count <= 0)
255253
GUILayout.Label("No performance test data found.\nNote this is supported only on 2018.3 or newer.");
256254
else
257255
{
@@ -266,6 +264,19 @@ private void Draw()
266264
}
267265
}
268266

267+
if (!string.IsNullOrEmpty(m_selectedTest))
268+
{
269+
var profileDataFile = Path.Combine(Application.persistentDataPath,
270+
Utils.RemoveIllegalCharacters(m_selectedTest) + ".raw");
271+
if (File.Exists(profileDataFile))
272+
{
273+
if (GUILayout.Button(string.Format("Load profiler data for test: {0}", m_selectedTest)))
274+
{
275+
ProfilerDriver.LoadProfile(profileDataFile, false);
276+
}
277+
}
278+
}
279+
269280
m_showSamples = BoldFoldout(m_showSamples, "Sample Group View");
270281
if (m_showSamples)
271282
{
@@ -283,6 +294,7 @@ private void Draw()
283294
dataIndex += result.SampleGroups.Count;
284295
continue;
285296
}
297+
286298
foreach (var sampleGroup in result.SampleGroups)
287299
{
288300
var data = m_sampleGroupAdditionalData[dataIndex];
@@ -308,7 +320,10 @@ private void Draw()
308320
Draw2Column("Max", max);
309321
GUILayout.FlexibleSpace();
310322
Color oldColor = GUI.contentColor;
311-
GUI.contentColor = m_colorMedianText;
323+
if (median < 0.01f)
324+
GUI.contentColor = m_colorWarningText;
325+
else
326+
GUI.contentColor = m_colorMedianText;
312327
Draw2Column("Median", median);
313328
GUI.contentColor = oldColor;
314329
//Draw2Column("SD", (float)sampleGroup.StandardDeviation);
@@ -318,7 +333,7 @@ private void Draw()
318333
EditorGUILayout.EndVertical();
319334
DrawBarGraph(position.width - 200, 100, sampleGroup.Samples, graphMin, max, median);
320335
DrawBoxAndWhiskerPlot(50, 100, min, lowerQuartile, median, upperQuartile, max, min, max,
321-
(float)sampleGroup.StandardDeviation, m_colorWhite, m_colorBoxAndWhiskerBackground);
336+
(float) sampleGroup.StandardDeviation, m_colorWhite, m_colorBoxAndWhiskerBackground);
322337
EditorGUILayout.EndHorizontal();
323338

324339
EditorGUILayout.EndVertical();

Editor/TestResultXmlParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private void ValidateInput(string resultXmlFileName)
2121
{
2222
if (string.IsNullOrEmpty(resultXmlFileName))
2323
{
24-
throw new ArgumentNullException(resultXmlFileName, nameof(resultXmlFileName));
24+
throw new ArgumentNullException(resultXmlFileName, resultXmlFileName);
2525
}
2626

2727
if (!File.Exists(resultXmlFileName))
@@ -171,7 +171,7 @@ private PerformanceTestRun TryDeserializePerformanceTestRunJsonObject(string jso
171171

172172
private string GetJsonFromHashtag(string tag, string line)
173173
{
174-
if (!line.Contains($"##{tag}:")) return null;
174+
if (!line.Contains(string.Format("##{0}:",tag))) return null;
175175
var jsonStart = line.IndexOf('{');
176176
var openBrackets = 0;
177177
var stringIndex = jsonStart;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ To install the Performance Testing Extension package
2121
``` json
2222
{
2323
"dependencies": {
24-
"com.unity.test-framework.performance": "0.1.41-preview",
24+
"com.unity.test-framework.performance": "0.1.42-preview",
2525
"com.unity.modules.jsonserialize": "1.0.0",
2626
"com.unity.modules.unitywebrequest": "1.0.0",
2727
"com.unity.modules.unityanalytics": "1.0.0",

0 commit comments

Comments
 (0)