-
Notifications
You must be signed in to change notification settings - Fork 654
DYN-1899: Node Execution Events #9823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 28 commits
56dbd73
eec64b9
4362151
75643c7
6a07e6c
38b8461
44a00a8
5c04a06
a21fd6a
4235133
302b9dd
6bf5548
8d4511b
8f9df0f
e91ef30
82373cc
1434ba0
706974c
760ae95
6ffd883
5b1c073
f11f924
710c7ee
e0be270
c2dc9c2
5bbc94b
a7e3a82
49604e9
5609485
39d6e14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,38 @@ private void OnDispatchedToUI(object sender, UIDispatcherEventArgs e) | |
/// </summary> | ||
public event Action<PortModel> PortDisconnected; | ||
|
||
public class NodeExecutionEventArgs : EventArgs | ||
{ | ||
public Guid GUID { get; private set; } | ||
public object Data { get; private set; } | ||
|
||
public NodeExecutionEventArgs(NodeModel model, object data) | ||
{ | ||
this.GUID = model.GUID; | ||
this.Data = data; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Event triggered before a node is executed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this comment should indicate that these events are only fired when profiling is enabled. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alternatively we could rename them to be less general. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notes have been added to both events to indicate that they will only be fired when profiling is turned on. My thought is that the names should remain general in the case that it is decided to make the event firing non-dependent on profiling being turned on so to not break the API. |
||
/// </summary> | ||
public event Action<NodeModel, NodeExecutionEventArgs> NodeExecutionBegin; | ||
|
||
internal void OnNodeExecutionBegin(object data) | ||
QilongTang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
NodeExecutionBegin?.Invoke(this, new NodeExecutionEventArgs(this, data)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it appears this passes the nodes evaluated output to this handler? |
||
} | ||
|
||
/// <summary> | ||
/// Event triggered after a node is executed. | ||
/// </summary> | ||
public event Action<NodeModel, NodeExecutionEventArgs> NodeExecutionEnd; | ||
|
||
internal void OnNodeExecutionEnd(object data) | ||
{ | ||
NodeExecutionEnd?.Invoke(this, new NodeExecutionEventArgs(this, data)); | ||
} | ||
|
||
#endregion | ||
|
||
#region public properties | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
using System.Collections.Generic; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
using Dynamo.Graph.Workspaces; | ||
using Dynamo.Models; | ||
using Dynamo.Graph.Nodes; | ||
using NUnit.Framework; | ||
|
||
namespace Dynamo.Tests | ||
|
@@ -94,5 +96,58 @@ public void TestProfilingSingleNodePublicMethodsOnly() | |
Assert.IsNotNull(profilingData.NodeExecutionTime(node)); | ||
Assert.Greater(profilingData.NodeExecutionTime(node)?.Ticks, 0); | ||
} | ||
|
||
private static List<Guid> executingNodes = new List<Guid>(); | ||
private static int nodeExecutionBeginCount = 0; | ||
private static int nodeExecutionEndCount = 0; | ||
|
||
private static void onNodeExectuionBegin(NodeModel sender, NodeModel.NodeExecutionEventArgs args) | ||
{ | ||
// Assert that the node has ot been executed more than once | ||
CollectionAssert.DoesNotContain(executingNodes, args.GUID); | ||
|
||
executingNodes.Add(args.GUID); | ||
nodeExecutionBeginCount++; | ||
} | ||
|
||
private static void onNodeExectuionEnd(NodeModel sender, NodeModel.NodeExecutionEventArgs args) | ||
{ | ||
// Assert that the node ending execution had the begin exectuion event fired previously | ||
CollectionAssert.Contains(executingNodes, args.GUID); | ||
|
||
nodeExecutionEndCount++; | ||
} | ||
|
||
[Test] | ||
public void TestNodeExecutionEvents() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add test that asserts the value of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After looking into the tests for the data object it seemed to me that the data object was redundant because the NodeModel object was the important information which was already being passed in. I removed the class that contained the NodeModel GUID and the now extraneous data and just rely on the NodeModel object that was being passed through already. |
||
{ | ||
// Note: This test file is saved in manual run mode | ||
string openPath = Path.Combine(TestDirectory, @"core\profiling\createSomePoints.dyn"); | ||
OpenModel(openPath); | ||
|
||
var nodes = CurrentDynamoModel.CurrentWorkspace.Nodes; | ||
foreach(var node in nodes) | ||
{ | ||
node.NodeExecutionBegin += onNodeExectuionBegin; | ||
node.NodeExecutionEnd += onNodeExectuionEnd; | ||
} | ||
|
||
// Currently the node execution begin/end events are only enabled when profiling is enabled | ||
var engineController = CurrentDynamoModel.EngineController; | ||
var homeWorkspace = CurrentDynamoModel.Workspaces.OfType<HomeWorkspaceModel>().FirstOrDefault(); | ||
engineController.EnableProfiling(true, homeWorkspace, nodes); | ||
|
||
BeginRun(); | ||
|
||
// Assert that all nodes were executed and the begin and end events were fired as expectd | ||
Assert.AreEqual(4, nodeExecutionBeginCount); | ||
Assert.AreEqual(4, nodeExecutionEndCount); | ||
|
||
foreach (var node in nodes) | ||
{ | ||
node.NodeExecutionBegin -= onNodeExectuionBegin; | ||
node.NodeExecutionEnd -= onNodeExectuionEnd; | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the public properties and the class itself should have some ///summary tags please.