Skip to content

Commit

Permalink
Merge branch 'master' into DYN-2476-First-graph-run-does-not-show-exe…
Browse files Browse the repository at this point in the history
…cution-time-in-TuneUp
  • Loading branch information
ivaylo-matov authored Jul 16, 2024
2 parents 464f5dd + ee93525 commit 5e58989
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 32 deletions.
17 changes: 13 additions & 4 deletions TuneUp/TuneUpWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,17 @@
IsEnabled="{Binding Path=IsRecomputeEnabled}"
Click="RecomputeGraph_Click"
Padding="5,2,5,2">
Force Re-execute
Run All
</Button>
<Button
Name="ExportTimes"
Width="Auto"
Height="Auto"
Margin="2,1,1,10"
Padding="5,2,5,2"
IsEnabled="{Binding Path=IsRecomputeEnabled}"
Click="ExportTimes_Click">
Export
</Button>
<Label Foreground="White">Total Graph Execution Time: </Label>
<Label Foreground="White"
Expand Down Expand Up @@ -124,9 +134,8 @@
CanUserSortColumns="True"
HeadersVisibility="Column"
SelectionChanged="NodeAnalysisTable_SelectionChanged"
Sorting="NodeAnalysisTable_Sorting"
>

PreviewMouseDown="NodeAnalysisTable_PreviewMouseDown"
MouseLeave="NodeAnalysisTable_MouseLeave" >
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
Expand Down
54 changes: 28 additions & 26 deletions TuneUp/TuneUpWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public partial class TuneUpWindow : Window
/// </summary>
private string uniqueId;

/// <summary>
/// A flag indicating whether the current selection change in the DataGrid
/// is initiated by the user (true) or programmatically (false).
/// </summary>
private bool isUserInitiatedSelection = false;

/// <summary>
/// Since there is no API for height offset comparing to
/// DynamoWindow height. Define it as static for now.
Expand Down Expand Up @@ -59,6 +65,8 @@ private void DynamoWindow_SizeChanged(object sender, System.Windows.SizeChangedE

private void NodeAnalysisTable_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!isUserInitiatedSelection) return;

// Get NodeModel(s) that correspond to selected row(s)
var selectedNodes = new List<NodeModel>();
foreach (var item in e.AddedItems)
Expand All @@ -82,6 +90,24 @@ private void NodeAnalysisTable_SelectionChanged(object sender, SelectionChangedE
}
}

/// <summary>
/// Handles the PreviewMouseDown event for the NodeAnalysisTable DataGrid.
/// Sets a flag to indicate that the selection change is user-initiated.
/// </summary>
private void NodeAnalysisTable_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
isUserInitiatedSelection = true;
}

/// <summary>
/// Handles the MouseLeave event for the NodeAnalysisTable DataGrid.
/// Resets the flag to indicate that the selection change is no longer user-initiated.
/// </summary>
private void NodeAnalysisTable_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
isUserInitiatedSelection = false;
}

internal void Dispose()
{
viewLoadedParams.DynamoWindow.SizeChanged -= DynamoWindow_SizeChanged;
Expand All @@ -92,33 +118,9 @@ private void RecomputeGraph_Click(object sender, RoutedEventArgs e)
(NodeAnalysisTable.DataContext as TuneUpWindowViewModel).ResetProfiling();
}

/// <summary>
/// Handles the sorting event for the NodeAnalysisTable DataGrid.
/// Updates the SortingOrder property in the view model based on the column header clicked by the user.
/// </summary>
private void NodeAnalysisTable_Sorting(object sender, DataGridSortingEventArgs e)
private void ExportTimes_Click(object sender, RoutedEventArgs e)
{
var column = e.Column;
var viewModel = NodeAnalysisTable.DataContext as TuneUpWindowViewModel;

if (viewModel != null)
{
switch (column.Header.ToString())
{
case "#":
viewModel.SortingOrder = "number";
break;
case "Name":
viewModel.SortingOrder = "name";
break;
case "Execution Time (ms)":
viewModel.SortingOrder = "time";
break;
}
// Apply custom sorting to ensure total times are at the bottom
viewModel.ApplySorting();
e.Handled = true;
}
(NodeAnalysisTable.DataContext as TuneUpWindowViewModel).ExportToCsv();
}
}
}
29 changes: 29 additions & 0 deletions TuneUp/TuneUpWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Data;
Expand All @@ -12,6 +13,7 @@
using Dynamo.Graph.Workspaces;
using Dynamo.ViewModels;
using Dynamo.Wpf.Extensions;
using Microsoft.Win32;

namespace TuneUp
{
Expand Down Expand Up @@ -523,5 +525,32 @@ public void Dispose()
}

#endregion

#region Export Node times

/// <summary>
/// Exports the ProfiledNodesCollection to a CSV file.
/// </summary>
public void ExportToCsv()
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
//saveFileDialog.RestoreDirectory = false;
saveFileDialog.Filter = "CSV file (*.csv)|*.csv|All files (*.*)|*.*";

if (saveFileDialog.ShowDialog() == true)
{
using (var writer = new StreamWriter(saveFileDialog.FileName))
{
writer.WriteLine("Execution Order,Name,Execution Time (ms)");

foreach (ProfiledNodeViewModel node in ProfiledNodesCollection.View.Cast<ProfiledNodeViewModel>())
{
writer.WriteLine($"{node.ExecutionOrderNumber},{node.Name},{node.ExecutionMilliseconds}");
}
}
}
}

#endregion
}
}
4 changes: 2 additions & 2 deletions TuneUp/manifests/pkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"license": "",
"file_hash": null,
"name": "TuneUp",
"version": "1.0.7",
"description": "*** THE TUNEUP EXTENSION USES NEW API FEATURES THAT ARE ONLY AVAILABLE IN DYNAMO VERSION 2.5 OR ABOVE ***\r\n\r\nTuneUp is in beta and is a view extension for analyzing the performance of Dynamo graphs. TuneUp allows you to see overall graph execution time, per-node execution time, and other helpful information about what's happening under the hood, e.g. nodes run in the current execution v.s. nodes run in the previous execution (which are skipped this run for optimization/ caching). Read more here: https://dynamobim.org/tuneup-extension-explore-your-node-and-graph-execution-times/ \r\n\r\nKnown issues:\r\n1. TuneUp does not work with .dyfs (custom nodes) yet.\r\n2.TuneUp binaries are not semantically versioned and are not intended to be built on top of as an API. Do not treat these binaries like DynamoCore.\r\n3. TuneUp requires Dynamo 2.5 or higher for access to new extension APIs.\r\n4. When user have TuneUp open, after switching workspace in Dynamo, the first graph run does not give execution time and nodes order.",
"version": "1.0.8",
"description": "*** THE TUNEUP EXTENSION USES NEW API FEATURES THAT ARE ONLY AVAILABLE IN DYNAMO VERSION 2.5 OR ABOVE ***\r\n\r\nTuneUp is in beta and is a view extension for analyzing the performance of Dynamo graphs. TuneUp allows you to see overall graph execution time, per-node execution time, and other helpful information about what's happening under the hood, e.g. nodes run in the current execution v.s. nodes run in the previous execution (which are skipped this run for optimization/ caching). Read more here: https://dynamobim.org/tuneup-extension-explore-your-node-and-graph-execution-times/ \r\n\r\nKnown issues:\r\n1. TuneUp does not work with .dyfs (custom nodes) yet.\r\n2.TuneUp binaries are not semantically versioned and are not intended to be built on top of as an API. Do not treat these binaries like DynamoCore.\r\n3. TuneUp requires Dynamo 3.0 or higher for access to new extension APIs.\r\n4. When user have TuneUp open, after switching workspace in Dynamo, the first graph run does not give execution time and nodes order.",
"group": "",
"keywords": [
"profiler",
Expand Down

0 comments on commit 5e58989

Please sign in to comment.