Skip to content

Commit

Permalink
3.4 imptovement - show executed 0 ms nodes as 1ms
Browse files Browse the repository at this point in the history
  • Loading branch information
ivaylo-matov committed Sep 24, 2024
1 parent 98793bd commit 22828b1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 57 deletions.
47 changes: 15 additions & 32 deletions TuneUp/ProfiledNodeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ internal set
private const string DefaultGroupName = "Title <Double click here to edit group title>";
private const string DefaultDisplayGroupName = "Title";

private string name = String.Empty;
/// <summary>
/// The name of this profiled node. This value can be either an actual
/// node name or can be virtually any row you want to append to
Expand All @@ -98,7 +97,8 @@ public string Name
}
internal set { name = value; }
}

private string name = String.Empty;

/// <summary>
/// The order number of this node in the most recent graph run.
/// Returns null if the node was not executed during the most recent graph run.
Expand Down Expand Up @@ -130,47 +130,32 @@ public int? GroupExecutionOrderNumber
private int? groupExecutionOrderNumber;

/// <summary>
/// The most recent execution time of this node
/// The most recent execution time of this node in milliseconds
/// </summary>
public TimeSpan ExecutionTime
public int ExecutionMilliseconds
{
get => executionTime;
get => executionMilliseconds;
set
{
executionTime = value;
RaisePropertyChanged(nameof(ExecutionTime));
executionMilliseconds = value;
RaisePropertyChanged(nameof(ExecutionMilliseconds));
}
}
private TimeSpan executionTime;

/// <summary>
/// The total execution time of all node in the group.
/// </summary>
public TimeSpan GroupExecutionTime
{
get => groupExecutionTime;
set
{
groupExecutionTime = value;
RaisePropertyChanged(nameof(GroupExecutionTime));
}
}
private TimeSpan groupExecutionTime;
private int executionMilliseconds;

/// <summary>
/// The most recent execution time of this node in milliseconds
/// The total execution time of the group in milliseconds
/// </summary>
public int ExecutionMilliseconds
public int GroupExecutionMilliseconds
{
get => executionMilliseconds;
get => groupExecutionMilliseconds;
set
{
executionMilliseconds = value;
RaisePropertyChanged(nameof(ExecutionMilliseconds));
groupExecutionMilliseconds = value;
RaisePropertyChanged(nameof(GroupExecutionMilliseconds));
}
}
private int executionMilliseconds;
private int groupExecutionMilliseconds;

/// <summary>
/// Indicates whether this node was executed on the most recent graph run
Expand Down Expand Up @@ -245,7 +230,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 +317,7 @@ internal void ResetGroupProperties()
GroupGUID = Guid.Empty;
GroupName = string.Empty;
GroupExecutionOrderNumber = null;
GroupExecutionTime = TimeSpan.Zero;
GroupExecutionMilliseconds = 0;
}

internal void ApplyGroupProperties(ProfiledNodeViewModel profiledGroup)
Expand Down Expand Up @@ -361,10 +345,9 @@ public ProfiledNodeViewModel(NodeModel node)
/// <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
41 changes: 16 additions & 25 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
profiledGroup.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 All @@ -628,11 +625,11 @@ internal void OnNodeExecutionEnd(NodeModel nm)
var executionTime = profiledNode.Stopwatch.Elapsed;

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 @@ -737,22 +734,17 @@ internal void OnGroupPropertyChanged(object sender, PropertyChangedEventArgs e)
groupDictionary[groupModel.GUID].Add(profiledNode);
}

// Update group execution time
// Update group execution times
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

0 comments on commit 22828b1

Please sign in to comment.