Skip to content

Commit 1d085a2

Browse files
committedNov 29, 2023
Refactor namespaces
1 parent 5696184 commit 1d085a2

33 files changed

+213
-172
lines changed
 

‎Editor/MultipleTestResultComparison.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using PerformanceTestReportViewer.Definition;
55
using Unity.PerformanceTesting.Data;
66

7-
namespace PerformanceTestReportViewer
7+
namespace PerformanceTestReportViewer.Editor
88
{
99
public class MultipleTestResultComparison
1010
{

‎Editor/PerformanceTestingReportViewerWindow.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
using UnityEngine;
66
using UnityEngine.UIElements;
77

8-
namespace PerformanceTestReportViewer
8+
namespace PerformanceTestReportViewer.Editor
99
{
1010
public class PerformanceTestingReportViewerWindow : EditorWindow
1111
{
12-
private UI.PerformanceTestReportViewer viewer;
12+
private Editor.UI.PerformanceTestReportViewer viewer;
1313
private ViewerOptions viewerOptions;
1414

1515
[MenuItem("Window/Analysis/PerformanceTestingReportViewer %#&V")]
@@ -26,7 +26,7 @@ public void CreateGUI()
2626
string path = Constants.LayoutPath + "/PerformanceTestingReportViewerWindow.uxml";
2727
var asset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(path);
2828
asset.CloneTree(rootVisualElement);
29-
viewer = rootVisualElement.Q<UI.PerformanceTestReportViewer>();
29+
viewer = rootVisualElement.Q<Editor.UI.PerformanceTestReportViewer>();
3030

3131
if (File.Exists(EditorConfigPath))
3232
viewerOptions = ViewerOptions.DeserializeFromString(File.ReadAllText(EditorConfigPath));

‎Editor/UI/Sprites.meta ‎Editor/Resources.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.

‎Editor/Resources/middleState.png

127 Bytes
Loading
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎Editor/SampleElement.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Linq;
22
using PerformanceTestReportViewer.Definition;
33

4-
namespace PerformanceTestReportViewer
4+
namespace PerformanceTestReportViewer.Editor
55
{
66
public class SampleElement
77
{
@@ -23,7 +23,7 @@ public bool MustShown(ViewerOptions options, TestResultOptions testResultOptions
2323
if (testResultOptions != null && testResultOptions.MustShown(SampleDefinition) == false)
2424
return false;
2525

26-
if (Utility.TryParseFromSampleGroupName(RawName, out string context, out string category, out string definition) == false)
26+
if (PerformanceTestReportViewerUtility.TryParseFromSampleGroupName(RawName, out string context, out string category, out string definition) == false)
2727
return false;
2828

2929
if (options.IsSampleTargetOn(context) == false)

‎Editor/TestInformationGetter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static bool IsComparableTest(string className)
124124
public static ISampleDefinition FindSampleGroupDefinition(string sampleGroupName, PerformanceTestResultContext context)
125125
{
126126
LazyInit();
127-
if (Utility.TryParseFromSampleGroupName(sampleGroupName, out string sampleTargetName, out string categoryName, out string definitionName) == false)
127+
if (PerformanceTestReportViewerUtility.TryParseFromSampleGroupName(sampleGroupName, out string sampleTargetName, out string categoryName, out string definitionName) == false)
128128
throw new Exception($"Unable to parse sample group name {sampleGroupName}!");
129129

130130
if (sampleDefinitions.TryGetValue($"{categoryName}.{definitionName}", out ISampleDefinition sampleDefinition))

‎Editor/UI/ChartUtility.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using PerformanceTestReportViewer.UI.Visualizers;
4+
using PerformanceTestReportViewer.Editor.UI.Visualizers;
55
using UnityEditor;
66
using UnityEngine;
77
using UnityEngine.UIElements;
88

9-
namespace PerformanceTestReportViewer.UI
9+
namespace PerformanceTestReportViewer.Editor.UI
1010
{
1111
public static class ChartUtility
1212
{

‎Editor/UI/Enums.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace PerformanceTestReportViewer.UI
1+
namespace PerformanceTestReportViewer.Editor.UI
22
{
33
public enum SortMethod
44
{

‎Editor/UI/Layouts/PerformanceTestReportViewer.uxml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</ui:GroupBox>
2424
</ui:VisualElement>
2525
<ui:GroupBox name="contentGroupBox" style="flex-direction: row; flex-shrink: 1; flex-grow: 1;">
26-
<PerformanceTestReportViewer.UI.TestResultListView name="testResultListView" style="min-width: 30%; flex-grow: 0; max-width: 50%;" />
26+
<PerformanceTestReportViewer.Editor.UI.TestResultListView name="testResultListView" style="min-width: 30%; flex-grow: 0; max-width: 50%;" />
2727
<ui:ScrollView name="viewPanel" style="flex-grow: 1;" />
2828
</ui:GroupBox>
2929
</ui:UXML>

‎Editor/UI/Layouts/PerformanceTestingReportViewerWindow.uxml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements"
33
noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
44
<Style src="project://database/Packages/PerformanceTestReportViewer/Editor/UI/Styles/PerformanceTestingReportViewer Style.uss?fileID=7433441132597879392&amp;guid=e3525ea95753f484b906cb7dd3556bde&amp;type=3#PerformanceTestingReportViewerWindow"/>
5-
<PerformanceTestReportViewer.UI.PerformanceTestReportViewer name="PerformanceTestReportViewer"
5+
<PerformanceTestReportViewer.Editor.UI.PerformanceTestReportViewer name="PerformanceTestReportViewer"
66
style="justify-content: flex-start; align-items: stretch; align-self: auto; height: 100%;"/>
77
</ui:UXML>

‎Editor/UI/Layouts/ThreeStateToggle.uxml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
2+
<Style src="project://database/Packages/com.penspanic.performancetestreportviewer/Editor/UI/Styles/PerformanceTestReportViewer%20Style.uss?fileID=7433441132597879392&amp;guid=e3525ea95753f484b906cb7dd3556bde&amp;type=3#PerformanceTestReportViewer Style" />
23
<ui:VisualElement name="ThreeStateToggle" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); flex-direction: row; flex-shrink: 0; margin-left: 4px; margin-right: 4px; margin-top: 2px; margin-bottom: 2px;">
34
<ui:Label tabindex="-1" text="Label" display-tooltip-when-elided="true" name="label" style="-unity-text-align: middle-left; min-width: auto; flex-grow: 0;" />
4-
<ui:VisualElement focusable="true" name="VisualElement" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); min-width: auto; min-height: auto; flex-basis: auto; flex-shrink: 0; flex-direction: row; align-self: center; justify-content: center;">
5-
<ui:Image name="checkMarkImage" style="flex-grow: 0; background-color: rgb(255, 255, 255); background-image: none; width: 16px; height: 16px; flex-shrink: 0; border-left-color: rgb(106, 106, 106); border-right-color: rgb(106, 106, 106); border-top-color: rgb(106, 106, 106); border-bottom-color: rgb(106, 106, 106); -unity-background-image-tint-color: rgb(46, 46, 46); border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; align-items: stretch; display: flex;" />
5+
<ui:VisualElement style="flex-grow: 0; align-items: auto; justify-content: center; flex-shrink: 0;">
6+
<ui:Image name="checkMarkImage" class="threestate-toggle-check-mark" style="flex-grow: 0; width: 14px; height: 14px; flex-shrink: 0; align-items: stretch; display: flex; align-self: center;" />
67
</ui:VisualElement>
78
<ui:Button display-tooltip-when-elided="true" name="settingButton" style="margin-left: 2px; margin-right: 2px; margin-top: 0; margin-bottom: 0; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0; background-image: none; width: 7px; height: 14px; -unity-background-scale-mode: stretch-to-fill; justify-content: center; align-self: center; -unity-slice-left: 0; -unity-slice-top: 0; -unity-slice-right: 0; -unity-slice-bottom: 0; background-color: rgb(188, 188, 188); border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; -unity-background-image-tint-color: rgb(137, 137, 137); border-left-color: rgb(38, 38, 38); border-right-color: rgb(38, 38, 38); border-top-color: rgb(38, 38, 38); border-bottom-color: rgb(38, 38, 38);" />
89
</ui:VisualElement>

‎Editor/UI/PerformanceTestReportViewer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using PerformanceTestReportViewer.Definition;
5-
using PerformanceTestReportViewer.UI.Visualizers;
5+
using PerformanceTestReportViewer.Editor.UI.Visualizers;
66
using Unity.PerformanceTesting.Data;
77
using UnityEditor;
88
using UnityEngine;
99
using UnityEngine.UIElements;
1010
using PopupWindow = UnityEditor.PopupWindow;
1111

12-
namespace PerformanceTestReportViewer.UI
12+
namespace PerformanceTestReportViewer.Editor.UI
1313
{
1414
public class PerformanceTestReportViewer : VisualElement
1515
{

‎Editor/UI/Sprites/middleState.png

-664 Bytes
Binary file not shown.

‎Editor/UI/Styles/PerformanceTestReportViewer Style.uss

+16
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,19 @@
66
.fit-field > Label {
77
min-width: 50px;
88
}
9+
10+
.threestate-toggle-checkmark-checked {
11+
background-image: resource('uipackageresources/images/d_toggle_on.png');
12+
}
13+
14+
.threestate-toggle-checkmark-middlestate {
15+
background-image: resource('middleState');
16+
}
17+
18+
.threestate-toggle-checkmark-unchecked {
19+
background-image: resource('uipackageresources/images/d_toggle_bg.png');
20+
}
21+
22+
.threestate-toggle-check-mark {
23+
-unity-background-image-tint-color: white;
24+
}

‎Editor/UI/TestResultListView.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using UnityEngine;
88
using UnityEngine.UIElements;
99

10-
namespace PerformanceTestReportViewer.UI
10+
namespace PerformanceTestReportViewer.Editor.UI
1111
{
1212
public class TestResultListView : VisualElement
1313
{
@@ -117,7 +117,7 @@ private IList<TreeViewItemData<ITreeViewItem>> BuildTreeDataList()
117117
Dictionary<string, GroupedResultItem> groupedResultItems = new();
118118
foreach (PerformanceTestResult testResult in ViewerModule.Instance.PerformanceTestResults.Results)
119119
{
120-
bool isParameterizedTest = Utility.IsParameterizedTest(testResult.Name, out string groupedDefinitionName, out string parameter);
120+
bool isParameterizedTest = PerformanceTestReportViewerUtility.IsParameterizedTest(testResult.Name, out string groupedDefinitionName, out string parameter);
121121
if (isParameterizedTest || TestInformationGetter.IsComparableTest(testResult.ClassName))
122122
{
123123
if (string.IsNullOrEmpty(groupedDefinitionName))

‎Editor/UI/ThreeStateToggle.cs

+20-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
using UnityEngine;
44
using UnityEngine.UIElements;
55

6-
namespace PerformanceTestReportViewer.UI
6+
namespace PerformanceTestReportViewer.Editor.UI
77
{
88
public class ThreeStateToggle : VisualElement
99
{
10+
public class Classes
11+
{
12+
public const string checkmark_unchecked = "threestate-toggle-checkmark-unchecked";
13+
public const string checkmark_checked = "threestate-toggle-checkmark-checked";
14+
public const string checkmark_middlestate = "threestate-toggle-checkmark-middlestate";
15+
}
16+
1017
private new class UxmlTraits : VisualElement.UxmlTraits
1118
{
1219
UxmlEnumAttributeDescription<StateType> m_StateAttribute = new(){ name = "state" };
@@ -88,13 +95,22 @@ private void RefreshImage()
8895
switch (_state)
8996
{
9097
case StateType.Unchecked:
91-
checkMarkImage.image = null;
98+
checkMarkImage.RemoveFromClassList(Classes.checkmark_checked);
99+
checkMarkImage.RemoveFromClassList(Classes.checkmark_middlestate);
100+
101+
checkMarkImage.AddToClassList(Classes.checkmark_unchecked);
92102
break;
93103
case StateType.MiddleState:
94-
checkMarkImage.image = AssetDatabase.LoadAssetAtPath<Texture>($"{Constants.SpritesPath}/middleState.png");
104+
checkMarkImage.RemoveFromClassList(Classes.checkmark_checked);
105+
checkMarkImage.RemoveFromClassList(Classes.checkmark_unchecked);
106+
107+
checkMarkImage.AddToClassList(Classes.checkmark_middlestate);
95108
break;
96109
case StateType.Checked:
97-
checkMarkImage.image = AssetDatabase.LoadAssetAtPath<Texture>($"{Constants.SpritesPath}/checked.png");
110+
checkMarkImage.RemoveFromClassList(Classes.checkmark_unchecked);
111+
checkMarkImage.RemoveFromClassList(Classes.checkmark_middlestate);
112+
113+
checkMarkImage.AddToClassList(Classes.checkmark_checked);
98114
break;
99115
}
100116
}

‎Editor/UI/Visualizers/AbstractVisualizer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using UnityEngine;
55
using UnityEngine.UIElements;
66

7-
namespace PerformanceTestReportViewer.UI.Visualizers
7+
namespace PerformanceTestReportViewer.Editor.UI.Visualizers
88
{
99
public abstract class ItemData
1010
{
@@ -122,7 +122,7 @@ void Do(string testNameWithNamespace, string[] parameters)
122122
}
123123
else
124124
{
125-
if (Utility.TryExtractCommonStrings(names, out string commonString, out string[] variations))
125+
if (PerformanceTestReportViewerUtility.TryExtractCommonStrings(names, out string commonString, out string[] variations))
126126
{
127127
commonString = commonString.TrimEnd('.');
128128

‎Editor/UI/Visualizers/BarsVisualizer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using UnityEngine;
77
using UnityEngine.UIElements;
88

9-
namespace PerformanceTestReportViewer.UI.Visualizers
9+
namespace PerformanceTestReportViewer.Editor.UI.Visualizers
1010
{
1111
public class BarsVisualizer : AbstractVisualizer
1212
{

‎Editor/UI/Visualizers/MultipleTestResultComparisonVisualizer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using UnityEngine.LowLevel;
77
using UnityEngine.UIElements;
88

9-
namespace PerformanceTestReportViewer.UI.Visualizers
9+
namespace PerformanceTestReportViewer.Editor.UI.Visualizers
1010
{
1111
public class MultipleTestResultComparisonVisualizer : AbstractVisualizer
1212
{

‎Editor/Utility.cs

+7-130
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,19 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Text.RegularExpressions;
54
using PerformanceTestReportViewer.Definition;
6-
using PerformanceTestReportViewer.UI;
7-
using Unity.PerformanceTesting.Data;
5+
using PerformanceTestReportViewer.Editor.UI;
86

9-
namespace PerformanceTestReportViewer
7+
namespace PerformanceTestReportViewer.Editor
108
{
11-
public static class Utility
9+
internal static class Utility
1210
{
13-
// [prefix][categoryName]Definition
14-
public static readonly Regex sampleGroupNameWithSampleTargetRegex = new(@"^\[([\w\.]+)\]\[([\w\.]+)\](.+)$");
15-
public static readonly Regex sampleGroupNameWithoutSampleTargetRegex = new(@"^\[([\w\.]+)\](.+)$");
16-
public static bool TryParseFromSampleGroupName(string sampleGroupName, out string sampleTarget, out string category, out string definition)
17-
{
18-
sampleTarget = string.Empty;
19-
category = string.Empty;
20-
definition = string.Empty;
21-
22-
if (sampleGroupName == "Time")
23-
{
24-
definition = sampleGroupName;
25-
return true;
26-
}
27-
28-
var match = sampleGroupNameWithSampleTargetRegex.Match(sampleGroupName);
29-
if (match.Success == false)
30-
{
31-
match = sampleGroupNameWithoutSampleTargetRegex.Match(sampleGroupName);
32-
if (match.Success == false)
33-
return false;
34-
35-
category = match.Groups[1].Value;
36-
definition = match.Groups[2].Value;
37-
return true;
38-
}
39-
40-
if (match.Groups.Count != 4)
41-
return false;
42-
43-
sampleTarget = match.Groups[1].Value;
44-
category = match.Groups[2].Value;
45-
definition = match.Groups[3].Value;
46-
return true;
47-
}
48-
49-
public static string FormatSampleGroupName(string sampleTarget, string category, string definition)
50-
{
51-
if (string.IsNullOrEmpty(sampleTarget))
52-
return $"[{category}]{definition}";
53-
54-
return $"[{sampleTarget}][{category}]{definition}";
55-
}
56-
57-
private static readonly Regex parameterizedTestNameRegex = new Regex(@"(.*)\((.+)\)");
58-
public static bool IsParameterizedTest(string testName, out string testNameWithoutParameter, out string parameter)
11+
public static IEnumerable<string> GetTags(this PerformanceTestResultContext resultContext)
5912
{
60-
// TODO: Not working when the parameter value contains '(' or ')' ...
61-
parameter = string.Empty;
62-
testNameWithoutParameter = string.Empty;
63-
var match = parameterizedTestNameRegex.Match(testName);
64-
65-
if (match.Success == false)
66-
return false;
67-
68-
if (match.Groups.Count != 3)
69-
return false;
13+
if (resultContext == null || resultContext.Results == null || resultContext.Results.Length == 0)
14+
return Enumerable.Empty<string>();
7015

71-
testNameWithoutParameter = match.Groups[1].Value;
72-
parameter = match.Groups[2].Value;
73-
return true;
16+
return resultContext.GetSampleGroupDefinitions().SelectMany(g => g.Tags).Distinct();
7417
}
7518

7619
public static IEnumerable<T> TrySort<T, T2>(this IEnumerable<T> collection, Func<T, T2> keySelector, SortMethod sortMethod)
@@ -88,31 +31,6 @@ public static IEnumerable<T> TrySort<T, T2>(this IEnumerable<T> collection, Func
8831
}
8932
}
9033

91-
public static IEnumerable<string> GetSampleTargets(this PerformanceTestResultContext resultContext)
92-
{
93-
if (resultContext == null || resultContext.Results == null || resultContext.Results.Length == 0)
94-
return Enumerable.Empty<string>();
95-
96-
return resultContext.Results
97-
.SelectMany(t => t.SampleGroups)
98-
.Select(s =>
99-
{
100-
bool result = TryParseFromSampleGroupName(s.Name, out string sampleTarget, out _, out _);
101-
return (result, sampleTarget);
102-
})
103-
.Where(p => p.result && string.IsNullOrEmpty(p.sampleTarget) == false)
104-
.Select(p => p.sampleTarget)
105-
.Distinct();
106-
}
107-
108-
public static IEnumerable<string> GetTags(this PerformanceTestResultContext resultContext)
109-
{
110-
if (resultContext == null || resultContext.Results == null || resultContext.Results.Length == 0)
111-
return Enumerable.Empty<string>();
112-
113-
return resultContext.GetSampleGroupDefinitions().SelectMany(g => g.Tags).Distinct();
114-
}
115-
11634
public static IEnumerable<ISampleDefinition> GetSampleGroupDefinitions(this PerformanceTestResultContext resultContext)
11735
{
11836
return resultContext.Results
@@ -134,46 +52,5 @@ public static string GetSampleUnit(this SampleElement[] elements)
13452

13553
return string.Empty;
13654
}
137-
138-
public static bool TryExtractCommonStrings(string[] input, out string common, out string[] variations)
139-
{
140-
variations = null;
141-
common = FindCommonPrefix(input);
142-
if (string.IsNullOrEmpty(common))
143-
return false;
144-
145-
variations = new string[input.Length];
146-
for (int i = 0; i < input.Length; ++i)
147-
{
148-
string remaining = input[i].Substring(common.Length);
149-
variations[i] = remaining;
150-
}
151-
152-
return true;
153-
}
154-
155-
private static string FindCommonPrefix(string[] strings)
156-
{
157-
if (strings == null || strings.Length == 0)
158-
return "";
159-
160-
string firstString = strings[0];
161-
162-
for (int i = 1; i < strings.Length; i++)
163-
{
164-
int j = 0;
165-
while (j < firstString.Length && j < strings[i].Length && firstString[j] == strings[i][j])
166-
{
167-
j++;
168-
}
169-
170-
firstString = firstString.Substring(0, j);
171-
172-
if (string.IsNullOrEmpty(firstString))
173-
break;
174-
}
175-
176-
return firstString;
177-
}
17855
}
17956
}

‎Editor/Utility.cs.meta

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Editor/ViewerModule.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Unity.PerformanceTesting.Data;
66
using UnityEngine;
77

8-
namespace PerformanceTestReportViewer
8+
namespace PerformanceTestReportViewer.Editor
99
{
1010
public class ViewerModule
1111
{

‎Editor/ViewerOptions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
using System.Runtime.Serialization.Formatters.Binary;
66
using System.Text;
77
using PerformanceTestReportViewer.Definition;
8-
using PerformanceTestReportViewer.UI;
8+
using PerformanceTestReportViewer.Editor.UI;
99
using Unity.PerformanceTesting.Data;
1010
using UnityEngine;
1111

12-
namespace PerformanceTestReportViewer
12+
namespace PerformanceTestReportViewer.Editor
1313
{
1414
[Serializable]
1515
public class ViewerOptions
@@ -59,7 +59,7 @@ public static ViewerOptions DeserializeFromString(string str)
5959

6060
public bool IsOn(SampleGroup sampleGroup)
6161
{
62-
if (Utility.TryParseFromSampleGroupName(sampleGroup.Name, out string contextName, out string categoryName, out string definitionName) == false)
62+
if (PerformanceTestReportViewerUtility.TryParseFromSampleGroupName(sampleGroup.Name, out string contextName, out string categoryName, out string definitionName) == false)
6363
return true;
6464

6565
return IsOn(contextName, categoryName, definitionName);

‎PerformanceTestReportViewerUtility.cs

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text.RegularExpressions;
5+
using PerformanceTestReportViewer.Definition;
6+
7+
namespace PerformanceTestReportViewer
8+
{
9+
public static class PerformanceTestReportViewerUtility
10+
{
11+
// [prefix][categoryName]Definition
12+
public static readonly Regex sampleGroupNameWithSampleTargetRegex = new(@"^\[([\w\.]+)\]\[([\w\.]+)\](.+)$");
13+
public static readonly Regex sampleGroupNameWithoutSampleTargetRegex = new(@"^\[([\w\.]+)\](.+)$");
14+
public static bool TryParseFromSampleGroupName(string sampleGroupName, out string sampleTarget, out string category, out string definition)
15+
{
16+
sampleTarget = string.Empty;
17+
category = string.Empty;
18+
definition = string.Empty;
19+
20+
if (sampleGroupName == "Time")
21+
{
22+
definition = sampleGroupName;
23+
return true;
24+
}
25+
26+
var match = sampleGroupNameWithSampleTargetRegex.Match(sampleGroupName);
27+
if (match.Success == false)
28+
{
29+
match = sampleGroupNameWithoutSampleTargetRegex.Match(sampleGroupName);
30+
if (match.Success == false)
31+
return false;
32+
33+
category = match.Groups[1].Value;
34+
definition = match.Groups[2].Value;
35+
return true;
36+
}
37+
38+
if (match.Groups.Count != 4)
39+
return false;
40+
41+
sampleTarget = match.Groups[1].Value;
42+
category = match.Groups[2].Value;
43+
definition = match.Groups[3].Value;
44+
return true;
45+
}
46+
47+
public static string FormatSampleGroupName(string sampleTarget, string category, string definition)
48+
{
49+
if (string.IsNullOrEmpty(sampleTarget))
50+
return $"[{category}]{definition}";
51+
52+
return $"[{sampleTarget}][{category}]{definition}";
53+
}
54+
55+
private static readonly Regex parameterizedTestNameRegex = new Regex(@"(.*)\((.+)\)");
56+
public static bool IsParameterizedTest(string testName, out string testNameWithoutParameter, out string parameter)
57+
{
58+
// TODO: Not working when the parameter value contains '(' or ')' ...
59+
parameter = string.Empty;
60+
testNameWithoutParameter = string.Empty;
61+
var match = parameterizedTestNameRegex.Match(testName);
62+
63+
if (match.Success == false)
64+
return false;
65+
66+
if (match.Groups.Count != 3)
67+
return false;
68+
69+
testNameWithoutParameter = match.Groups[1].Value;
70+
parameter = match.Groups[2].Value;
71+
return true;
72+
}
73+
74+
75+
76+
public static IEnumerable<string> GetSampleTargets(this PerformanceTestResultContext resultContext)
77+
{
78+
if (resultContext == null || resultContext.Results == null || resultContext.Results.Length == 0)
79+
return Enumerable.Empty<string>();
80+
81+
return resultContext.Results
82+
.SelectMany(t => t.SampleGroups)
83+
.Select(s =>
84+
{
85+
bool result = TryParseFromSampleGroupName(s.Name, out string sampleTarget, out _, out _);
86+
return (result, sampleTarget);
87+
})
88+
.Where(p => p.result && string.IsNullOrEmpty(p.sampleTarget) == false)
89+
.Select(p => p.sampleTarget)
90+
.Distinct();
91+
}
92+
93+
94+
95+
public static bool TryExtractCommonStrings(string[] input, out string common, out string[] variations)
96+
{
97+
variations = null;
98+
common = FindCommonPrefix(input);
99+
if (string.IsNullOrEmpty(common))
100+
return false;
101+
102+
variations = new string[input.Length];
103+
for (int i = 0; i < input.Length; ++i)
104+
{
105+
string remaining = input[i].Substring(common.Length);
106+
variations[i] = remaining;
107+
}
108+
109+
return true;
110+
}
111+
112+
private static string FindCommonPrefix(string[] strings)
113+
{
114+
if (strings == null || strings.Length == 0)
115+
return "";
116+
117+
string firstString = strings[0];
118+
119+
for (int i = 1; i < strings.Length; i++)
120+
{
121+
int j = 0;
122+
while (j < firstString.Length && j < strings[i].Length && firstString[j] == strings[i][j])
123+
{
124+
j++;
125+
}
126+
127+
firstString = firstString.Substring(0, j);
128+
129+
if (string.IsNullOrEmpty(firstString))
130+
break;
131+
}
132+
133+
return firstString;
134+
}
135+
}
136+
}

‎PerformanceTestReportViewerUtility.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Runtime.meta

-8
This file was deleted.

‎Editor/SampleGroups.cs ‎SampleGroups.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static SampleGroup CreateSampleGroup(
5050
string sampleTarget)
5151
{
5252
return new SampleGroup(
53-
Utility.FormatSampleGroupName(sampleTarget, categoryName, sampleDefinition.Name),
53+
PerformanceTestReportViewerUtility.FormatSampleGroupName(sampleTarget, categoryName, sampleDefinition.Name),
5454
sampleDefinition.SampleUnit,
5555
increaseIsBetter: sampleDefinition.IncreaseIsBetter.GetValueOrDefault(false)
5656
);
File renamed without changes.

0 commit comments

Comments
 (0)
Please sign in to comment.