Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
AlonTalmi committed Feb 29, 2024
1 parent 4a23aa6 commit f633c41
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -295,6 +300,10 @@ IEnumerable<DiagnosticsInfoTreeViewItem> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using VContainer.Internal;

Expand Down Expand Up @@ -69,11 +70,14 @@ public object TraceResolve(Registration registration, Func<Registration, object>
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public sealed class ResolveInfo
public List<object> Instances { get; } = new List<object>();
public int MaxDepth { get; set; } = -1;
public int RefCount { get; set; }
public long InitialResolveTime { get; set; }

public ResolveInfo(Registration registration)
{
Expand Down

0 comments on commit f633c41

Please sign in to comment.