Skip to content

Commit

Permalink
Add bottom-up setting (fix #12)
Browse files Browse the repository at this point in the history
  • Loading branch information
verdie-g committed May 1, 2024
1 parent 5f65c5e commit 079e026
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 25 deletions.
38 changes: 25 additions & 13 deletions DotnetEventViewer/CallTree/CallTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public class CallTreeNode
{
public static CallTreeNode Create(
IEnumerable<Event> events,
ICallTreeCountAggregatorProcessor processor)
ICallTreeCountAggregatorProcessor processor,
bool bottomUp)
{
CallTreeNode root = new(0, new MethodDescription("root", ""));

Expand All @@ -19,29 +20,40 @@ public static CallTreeNode Create(

var currentNode = root;

for (int i = 0; i < evt.StackTrace.Frames.Length; i += 1)
if (bottomUp)
{
var frame = evt.StackTrace.Frames[i];
currentNode.Children ??= new Dictionary<ulong, CallTreeNode>();
if (!currentNode.Children.TryGetValue(frame.Address, out var childNode))
for (int i = 0; i < evt.StackTrace.Frames.Length; i += 1)
{
childNode = new CallTreeNode(id, frame);
currentNode.Children[frame.Address] = childNode;
id += 1;
AddCallToNode(evt.StackTrace.Frames[i], ref currentNode, ref id);
}

currentNode = childNode;

if (i == evt.StackTrace.Frames.Length - 1)
}
else
{
for (int i = evt.StackTrace.Frames.Length - 1; i >= 0; i -= 1)
{
processor.UpdateLeafNode(ref currentNode._count, evt);
AddCallToNode(evt.StackTrace.Frames[i], ref currentNode, ref id);
}
}

processor.UpdateLeafNode(ref currentNode._count, evt);
}

root.PropagateCount();

return root;

static void AddCallToNode(MethodDescription frame, ref CallTreeNode node, ref int id)
{
node.Children ??= new Dictionary<ulong, CallTreeNode>();
if (!node.Children.TryGetValue(frame.Address, out var childNode))
{
childNode = new CallTreeNode(id, frame);
node.Children[frame.Address] = childNode;
id += 1;
}

node = childNode;
}
}

private long _count;
Expand Down
32 changes: 22 additions & 10 deletions DotnetEventViewer/Components/QueryBuilder.razor
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,26 @@
OptionText="@(d => d.Name)"
OptionDisabled="IsAggregatorDisabled"
@bind-SelectedOption="Query.SelectedAggregator"/>
<FluentCheckbox
Id="tp-stacks-only"
Label="Thread Pool Stacks Only"
Style="margin-top: 6px"
@bind-Value="Query.ThreadPoolStacksOnly" />
<FluentTooltip Anchor="tp-stacks-only">
Tries to filter out events that occured on a non-threadpool thread. Useful to investigate thread
pool starvation. This option is not 100% accurate.
</FluentTooltip>
<FluentButton
id="extra-options"
Appearance="Appearance.Neutral"
@onclick="() => _extraOptionsOpen = !_extraOptionsOpen"
IconStart="@(new Icons.Filled.Size20.Settings())">
</FluentButton>
<FluentMenu Anchor="extra-options" @bind-Open="_extraOptionsOpen">
<FluentMenuItem
Role="MenuItemRole.MenuItemCheckbox"
Checked="@Query.BottomUpTree"
OnClick="() => Query.BottomUpTree = !Query.BottomUpTree">
Bottom-up Tree
</FluentMenuItem>
<FluentMenuItem
Role="MenuItemRole.MenuItemCheckbox"
Checked="@Query.ThreadPoolStacksOnly"
OnClick="() => Query.ThreadPoolStacksOnly = !Query.ThreadPoolStacksOnly">
Thread Pool Stacks Only
</FluentMenuItem>
</FluentMenu>
}
<FluentButton Type="ButtonType.Submit"
Appearance="Appearance.Accent"
Expand Down Expand Up @@ -124,6 +135,7 @@
private Field[] _allFields = [];
private EditContext _editContext = default!;
private ValidationMessageStore _messageStore = default!;
private bool _extraOptionsOpen;

[Parameter, EditorRequired]
public QueryType QueryType { get; set; }
Expand Down Expand Up @@ -328,7 +340,7 @@
.ToArray();
}

_ = OnQuery.InvokeAsync(new QueryResult(filteredEvents, Query.SelectedColumnFields, Query.SelectedAggregator));
_ = OnQuery.InvokeAsync(new QueryResult(filteredEvents, Query.SelectedColumnFields, Query.SelectedAggregator, Query.BottomUpTree));
}

private bool FilterEvent(Event evt, Query query, EventKey[] eventKeys)
Expand Down
2 changes: 1 addition & 1 deletion DotnetEventViewer/Pages/EventsTree.razor
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
private void OnQuery(QueryResult queryResult)
{
var processor = queryResult.CallTreeAggregator!.CreateProcessor();
_callTree = CallTreeNode.Create(queryResult.FilteredEvents, processor);
_callTree = CallTreeNode.Create(queryResult.FilteredEvents, processor, queryResult.BottomUpTree);
_callTreeAggregator = queryResult.CallTreeAggregator;
}

Expand Down
1 change: 1 addition & 0 deletions DotnetEventViewer/Querying/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ internal class Query
public Filter[] Filters { get; set; } = [];
public IEnumerable<Field>? SelectedColumnFields { get; set; }
public ICallTreeCountAggregator? SelectedAggregator { get; set; }
public bool BottomUpTree { get; set; } = true;
public bool ThreadPoolStacksOnly { get; set; }
}
8 changes: 7 additions & 1 deletion DotnetEventViewer/Querying/QueryResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

namespace DotnetEventViewer.Querying;

public class QueryResult(IReadOnlyList<Event> filteredEvents, IEnumerable<Field>? columnFields, ICallTreeCountAggregator? callTreeAggregator)
public class QueryResult(
IReadOnlyList<Event> filteredEvents,
IEnumerable<Field>? columnFields,
ICallTreeCountAggregator? callTreeAggregator,
bool bottomUpTree)
{
public IReadOnlyList<Event> FilteredEvents { get; } = filteredEvents;

Expand All @@ -12,4 +16,6 @@ public class QueryResult(IReadOnlyList<Event> filteredEvents, IEnumerable<Field>

/// <summary>Non-null for <see cref="QueryType.Tree"/>.</summary>
public ICallTreeCountAggregator? CallTreeAggregator { get; } = callTreeAggregator;

public bool BottomUpTree { get; } = bottomUpTree;
}

0 comments on commit 079e026

Please sign in to comment.