diff --git a/VContainer/Assets/VContainer/Editor/Diagnostics/VContainerDiagnosticsTreeView.cs b/VContainer/Assets/VContainer/Editor/Diagnostics/VContainerDiagnosticsTreeView.cs index a710c5af..8231b31d 100644 --- a/VContainer/Assets/VContainer/Editor/Diagnostics/VContainerDiagnosticsTreeView.cs +++ b/VContainer/Assets/VContainer/Editor/Diagnostics/VContainerDiagnosticsTreeView.cs @@ -17,6 +17,7 @@ public sealed class DiagnosticsInfoTreeViewItem : TreeViewItem public RegistrationBuilder RegistrationBuilder => DiagnosticsInfo.RegisterInfo.RegistrationBuilder; public Registration Registration => DiagnosticsInfo.ResolveInfo.Registration; public int? RefCount => DiagnosticsInfo.ResolveInfo.RefCount; + public long InitialResolveTime => DiagnosticsInfo.ResolveInfo.InitialResolveTime; public string TypeSummary => TypeNameHelper.GetTypeAlias(Registration.ImplementationType); @@ -85,6 +86,7 @@ public sealed class VContainerDiagnosticsInfoTreeView : TreeView new MultiColumnHeaderState.Column { headerContent = new GUIContent("Register"), width = 15f }, new MultiColumnHeaderState.Column { headerContent = new GUIContent("RefCount"), width = 5f }, new MultiColumnHeaderState.Column { headerContent = new GUIContent("Scope"), width = 20f }, + new MultiColumnHeaderState.Column { headerContent = new GUIContent("Time"), width = 20f }, }; static int idSeed; @@ -246,6 +248,9 @@ protected override void RowGUI(RowGUIArgs args) case 5: EditorGUI.LabelField(cellRect, item.ScopeName, labelStyle); break; + case 6: + EditorGUI.LabelField(cellRect, item.InitialResolveTime.ToString(), labelStyle); + break; default: throw new ArgumentOutOfRangeException(nameof(columnIndex), columnIndex, null); } @@ -295,6 +300,10 @@ IEnumerable Sort( return ascending ? items.OrderBy(x => x.ScopeName) : items.OrderByDescending(x => x.ScopeName); + case 6: + return ascending + ? items.OrderBy(x => x.InitialResolveTime) + : items.OrderByDescending(x => x.InitialResolveTime); default: throw new ArgumentOutOfRangeException(nameof(sortedColumnIndex), sortedColumnIndex, null); } diff --git a/VContainer/Assets/VContainer/Runtime/Diagnostics/DiagnosticsCollector.cs b/VContainer/Assets/VContainer/Runtime/Diagnostics/DiagnosticsCollector.cs index 546c4742..c6102d2c 100644 --- a/VContainer/Assets/VContainer/Runtime/Diagnostics/DiagnosticsCollector.cs +++ b/VContainer/Assets/VContainer/Runtime/Diagnostics/DiagnosticsCollector.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Threading; using VContainer.Internal; @@ -69,11 +70,14 @@ public object TraceResolve(Registration registration, Func owner?.Dependencies.Add(current); resolveCallStack.Value.Push(current); + var watch = Stopwatch.StartNew(); var instance = resolving(registration); + watch.Stop(); resolveCallStack.Value.Pop(); if (!current.ResolveInfo.Instances.Contains(instance)) { + current.ResolveInfo.InitialResolveTime = watch.ElapsedMilliseconds; current.ResolveInfo.Instances.Add(instance); } diff --git a/VContainer/Assets/VContainer/Runtime/Diagnostics/ResolveInfo.cs b/VContainer/Assets/VContainer/Runtime/Diagnostics/ResolveInfo.cs index 1d337cf3..0b392d68 100644 --- a/VContainer/Assets/VContainer/Runtime/Diagnostics/ResolveInfo.cs +++ b/VContainer/Assets/VContainer/Runtime/Diagnostics/ResolveInfo.cs @@ -8,6 +8,7 @@ public sealed class ResolveInfo public List Instances { get; } = new List(); public int MaxDepth { get; set; } = -1; public int RefCount { get; set; } + public long InitialResolveTime { get; set; } public ResolveInfo(Registration registration) {