Skip to content
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

3.4 Improvement - show executed 0ms nodes as 1ms #62

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions TuneUp/ProfiledNodeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,20 @@ public int ExecutionMilliseconds
}
private int executionMilliseconds;

/// <summary>
/// The total execution time of this group in milliseconds
/// </summary>
public int GroupExecutionMilliseconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think this should be okay now.

{
get => groupExecutionMilliseconds;
set
{
groupExecutionMilliseconds = value;
RaisePropertyChanged(nameof(GroupExecutionMilliseconds));
}
}
private int groupExecutionMilliseconds;

/// <summary>
/// Indicates whether this node was executed on the most recent graph run
/// </summary>
Expand Down Expand Up @@ -245,7 +259,6 @@ public bool ShowGroupIndicator
}
private bool showGroupIndicator;


/// <summary>
/// The background brush for this node
/// If this node represents a group, it inherits the background color from the associated AnnotationModel
Expand Down Expand Up @@ -333,7 +346,7 @@ internal void ResetGroupProperties()
GroupGUID = Guid.Empty;
GroupName = string.Empty;
GroupExecutionOrderNumber = null;
GroupExecutionTime = TimeSpan.Zero;
GroupExecutionMilliseconds = 0;
}

internal void ApplyGroupProperties(ProfiledNodeViewModel profiledGroup)
Expand All @@ -359,12 +372,10 @@ public ProfiledNodeViewModel(NodeModel node)
/// An alternative constructor which we can customize data for display in TuneUp datagrid
/// </summary>
/// <param name="name">row display name</param>
/// <param name="exTimeSum">execution time in ms</param>
/// <param name="state">state which determine grouping</param>
public ProfiledNodeViewModel(string name, TimeSpan exTimeSum, ProfiledNodeState state)
public ProfiledNodeViewModel(string name, ProfiledNodeState state)
{
this.Name = name;
this.ExecutionTime = exTimeSum;
State = state;
}

Expand Down
37 changes: 14 additions & 23 deletions TuneUp/TuneUpWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,9 @@ private void CalculateGroupNodes()
ProfiledNodeViewModel groupTotalTimeNode = null;
bool groupIsRenamed = false;

// Reset group state
// Reset group state and execution time
profiledGroup.State = profiledNode.State;
profiledGroup.GroupExecutionTime = TimeSpan.Zero; // Reset execution time
profiledGroup.ExecutionMilliseconds = 0; // Reset UI execution time
profiledNode.GroupExecutionMilliseconds = 0;
MoveNodeToCollection(profiledGroup, ProfiledNodesLatestRun); // Ensure the profiledGroup is in latest run

// Check if the group has been renamed
Expand All @@ -565,8 +564,7 @@ private void CalculateGroupNodes()
else if (processedNodes.Add(node))
{
// Update group state, execution order, and execution time
profiledGroup.GroupExecutionTime += node.ExecutionTime; // accurate, for sorting
profiledGroup.ExecutionMilliseconds += node.ExecutionMilliseconds; // rounded, for display in UI
profiledGroup.GroupExecutionMilliseconds += node.ExecutionMilliseconds;
node.GroupExecutionOrderNumber = groupExecutionCounter;
node.ShowGroupIndicator = ShowGroups;
if (groupIsRenamed)
Expand All @@ -578,7 +576,6 @@ private void CalculateGroupNodes()

// Update the properties of the group node
profiledGroup.GroupExecutionOrderNumber = groupExecutionCounter++;
profiledGroup.ExecutionTime = profiledGroup.GroupExecutionTime;
profiledGroup.WasExecutedOnLastRun = true;


Expand All @@ -591,7 +588,7 @@ private void CalculateGroupNodes()
// Update the groupExecutionTime for all nodes of the group for the purposes of sorting
foreach (var node in nodesInGroup)
{
node.GroupExecutionTime = profiledGroup.GroupExecutionTime;
node.GroupExecutionMilliseconds = profiledGroup.GroupExecutionMilliseconds;
}
}
}
Expand All @@ -601,7 +598,7 @@ private void CalculateGroupNodes()
!profiledNode.IsGroupExecutionTime)
{
profiledNode.GroupExecutionOrderNumber = groupExecutionCounter++;
profiledNode.GroupExecutionTime = profiledNode.ExecutionTime;
profiledNode.GroupExecutionMilliseconds = profiledNode.ExecutionMilliseconds;
}
}

Expand Down Expand Up @@ -629,10 +626,10 @@ internal void OnNodeExecutionEnd(NodeModel nm)

if (executionTime > TimeSpan.Zero)
{
profiledNode.ExecutionTime = executionTime;
// Assign execution time and manually set the execution milliseconds value
// so that group node execution time is based on rounded millisecond values.
profiledNode.ExecutionMilliseconds = (int)Math.Round(executionTime.TotalMilliseconds);
// Nodes should display at least 1ms execution time if they are executed.
profiledNode.ExecutionMilliseconds = Math.Max(1, (int)Math.Round(executionTime.TotalMilliseconds));

if (!profiledNode.WasExecutedOnLastRun)
{
Expand Down Expand Up @@ -741,18 +738,13 @@ internal void OnGroupPropertyChanged(object sender, PropertyChangedEventArgs e)
var totalExecutionMilliseconds = existingProfiledNodesInGroup
.Where(n => !n.IsGroupExecutionTime)
.Sum(n => n.ExecutionMilliseconds);
var totalExecutionTime = existingProfiledNodesInGroup
.Where(n => !n.IsGroupExecutionTime)
.Select(n => n.ExecutionTime)
.Aggregate(TimeSpan.Zero, (sum, next) => sum + next);

profiledGroup.ExecutionMilliseconds = totalExecutionMilliseconds;
profiledGroup.GroupExecutionTime = totalExecutionTime;
profiledGroup.ExecutionMilliseconds = profiledGroup.GroupExecutionMilliseconds = totalExecutionMilliseconds;

// update the grouped nodes
foreach (var profiledNode in existingProfiledNodesInGroup)
{
profiledNode.GroupExecutionTime = totalExecutionTime;
profiledNode.GroupExecutionMilliseconds = totalExecutionMilliseconds;
if (profiledNode.IsGroupExecutionTime)
{
profiledNode.ExecutionMilliseconds = totalExecutionMilliseconds;
Expand Down Expand Up @@ -893,7 +885,7 @@ private void OnCurrentWorkspaceCleared(IWorkspaceModel workspace)
private ProfiledNodeViewModel CreateGroupTotalTimeNode(ProfiledNodeViewModel profiledGroup)
{
var groupTotalTimeNode = new ProfiledNodeViewModel(
ProfiledNodeViewModel.GroupExecutionTimeString, TimeSpan.Zero, ProfiledNodeState.NotExecuted)
ProfiledNodeViewModel.GroupExecutionTimeString, ProfiledNodeState.NotExecuted)
{
GroupGUID = profiledGroup.GroupGUID,
GroupName = profiledGroup.GroupName,
Expand All @@ -912,8 +904,7 @@ private ProfiledNodeViewModel CreateGroupTotalTimeNode(ProfiledNodeViewModel pro
private void UpdateGroupTotalTimeNodeProperties(ProfiledNodeViewModel groupTotalTimeNode, ProfiledNodeViewModel profiledGroup)
{
groupTotalTimeNode.State = profiledGroup.State;
groupTotalTimeNode.GroupExecutionTime = profiledGroup.GroupExecutionTime; // Accurate, for sorting
groupTotalTimeNode.ExecutionMilliseconds = profiledGroup.ExecutionMilliseconds; // Rounded, for display in UI
groupTotalTimeNode.GroupExecutionMilliseconds = groupTotalTimeNode.ExecutionMilliseconds = profiledGroup.GroupExecutionMilliseconds;
groupTotalTimeNode.GroupExecutionOrderNumber = profiledGroup.GroupExecutionOrderNumber;
groupTotalTimeNode.WasExecutedOnLastRun = true;

Expand Down Expand Up @@ -1034,15 +1025,15 @@ public void ApplyCustomSorting(CollectionViewSource collection, string explicitS
case SortByTime:
if (showGroups)
{
collection.SortDescriptions.Add(new SortDescription(nameof(ProfiledNodeViewModel.GroupExecutionTime), sortDirection));
collection.SortDescriptions.Add(new SortDescription(nameof(ProfiledNodeViewModel.GroupExecutionMilliseconds), sortDirection));
collection.SortDescriptions.Add(new SortDescription(nameof(ProfiledNodeViewModel.GroupGUID), sortDirection));
collection.SortDescriptions.Add(new SortDescription(nameof(ProfiledNodeViewModel.IsGroup), ListSortDirection.Descending));
collection.SortDescriptions.Add(new SortDescription(nameof(ProfiledNodeViewModel.IsGroupExecutionTime), ListSortDirection.Ascending));
collection.SortDescriptions.Add(new SortDescription(nameof(ProfiledNodeViewModel.ExecutionTime), sortDirection));
collection.SortDescriptions.Add(new SortDescription(nameof(ProfiledNodeViewModel.ExecutionMilliseconds), sortDirection));
}
else
{
collection.SortDescriptions.Add(new SortDescription(nameof(ProfiledNodeViewModel.ExecutionTime), sortDirection));
collection.SortDescriptions.Add(new SortDescription(nameof(ProfiledNodeViewModel.ExecutionMilliseconds), sortDirection));
}
break;
case SortByName:
Expand Down