diff --git a/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs b/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs index 1a616efccd9..652df229aea 100644 --- a/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs +++ b/src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Threading; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; @@ -73,6 +74,12 @@ public partial class DynamoView : Window, IDisposable private double restoreWidth = 0; private DynamoViewModel dynamoViewModel; private readonly Stopwatch _timer; + + #region Open Workspace performance tools + private static int idleCounter; + private Stopwatch WorkspaceRenderedTimer; + #endregion + private StartPageViewModel startPage; private int tabSlidingWindowStart, tabSlidingWindowEnd; private readonly LoginService loginService; @@ -245,6 +252,7 @@ public DynamoView(DynamoViewModel dynamoViewModel) this.dynamoViewModel.RequestCloseHomeWorkSpace += OnRequestCloseHomeWorkSpace; this.dynamoViewModel.RequestReturnFocusToView += OnRequestReturnFocusToView; this.dynamoViewModel.Model.WorkspaceSaving += OnWorkspaceSaving; + this.dynamoViewModel.Model.WorkspaceOpening += OnWorkspaceOpening; this.dynamoViewModel.Model.WorkspaceOpened += OnWorkspaceOpened; this.dynamoViewModel.Model.WorkspaceAdded += OnWorkspaceAdded; this.dynamoViewModel.Model.WorkspaceHidden += OnWorkspaceHidden; @@ -265,6 +273,12 @@ public DynamoView(DynamoViewModel dynamoViewModel) DefaultMinWidth = MinWidth; } + private void OnWorkspaceOpening(object obj) + { + WorkspaceRenderedTimer ??= Stopwatch.StartNew(); + WorkspaceRenderedTimer.Start(); + } + private void OnRequestCloseHomeWorkSpace() { CalculateWindowMinWidth(); @@ -362,7 +376,24 @@ private void OnWorkspaceOpened(WorkspaceModel workspace) foreach (var extension in viewExtensionManager.StorageAccessViewExtensions) { DynamoModel.RaiseIExtensionStorageAccessWorkspaceOpened(hws, extension, dynamoViewModel.Model.Logger); - } + } + + void Hooks_DispatcherInactive(object sender, EventArgs e) + { + if (idleCounter < 10) + { + Interlocked.Increment(ref idleCounter); + return; + } + + Interlocked.Exchange(ref idleCounter, 0); + dynamoViewModel.Model.Logger.Log($"Opened workspace found at {workspace.FileName} in {WorkspaceRenderedTimer.Elapsed}"); + WorkspaceRenderedTimer.Reset(); + + Dispatcher.Hooks.DispatcherInactive -= Hooks_DispatcherInactive; + } + + Dispatcher.Hooks.DispatcherInactive += Hooks_DispatcherInactive; } private void OnWorkspaceSaving(WorkspaceModel workspace, Graph.SaveContext saveContext) @@ -2015,6 +2046,7 @@ private void WindowClosed(object sender, EventArgs e) this.dynamoViewModel.RequestCloseHomeWorkSpace -= OnRequestCloseHomeWorkSpace; this.dynamoViewModel.RequestReturnFocusToView -= OnRequestReturnFocusToView; this.dynamoViewModel.Model.WorkspaceSaving -= OnWorkspaceSaving; + this.dynamoViewModel.Model.WorkspaceOpening -= OnWorkspaceOpening; this.dynamoViewModel.Model.WorkspaceOpened -= OnWorkspaceOpened; this.dynamoViewModel.Model.WorkspaceAdded -= OnWorkspaceAdded; this.dynamoViewModel.Model.WorkspaceHidden -= OnWorkspaceHidden;