Skip to content

Commit

Permalink
Lazily render call tree items
Browse files Browse the repository at this point in the history
  • Loading branch information
verdie-g committed Jun 24, 2024
1 parent c37fe0a commit e8de2f3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 114 deletions.
111 changes: 0 additions & 111 deletions DotnetEventsViewer/Components/CallTreeView.razor

This file was deleted.

4 changes: 2 additions & 2 deletions DotnetEventsViewer/DotnetEventsViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components" Version="4.7.2" />
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.7.2" />
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components" Version="4.8.1" />
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.8.0" />
</ItemGroup>

</Project>
46 changes: 45 additions & 1 deletion DotnetEventsViewer/Pages/EventsTree.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,61 @@
<h1>Events Tree</h1>

<QueryBuilder QueryType="QueryType.Tree" OnQuery="OnQuery" />
<CallTreeView Tree="_callTree" Aggregator="_callTreeAggregator" />
@if (_treeView != null)
{
<FluentTreeView Items="_treeView" LazyLoadItems="true" />
}

@code {
private CallTreeNode? _callTree;
private ICallTreeCountAggregator? _callTreeAggregator;
private IEnumerable<ITreeViewItem>? _treeView;

private void OnQuery(QueryResult queryResult)
{
var processor = queryResult.CallTreeAggregator!.CreateProcessor();
_callTree = CallTreeNode.Create(queryResult.FilteredEvents, processor, queryResult.BottomUpTree);
_callTreeAggregator = queryResult.CallTreeAggregator;
_treeView = [CallTreeToView(_callTree)];
}

private ITreeViewItem CallTreeToView(CallTreeNode node)
{
List<ITreeViewItem>? children = null;
if (node.Children != null)
{
children = new List<ITreeViewItem>();
foreach (var child in node.Children)
{
children.Add(CallTreeToView(child.Value));
}
}

return new TreeViewItem
{
Id = node.Id.ToString(),
Text = GenerateNodeText(_callTree!, node),
Items = children,
OnExpandedAsync = OnNodeExpandedAsync,
};
}

private string GenerateNodeText(CallTreeNode root, CallTreeNode node)
{
float ratio = node.Count / (float)root.Count;
return $"({100 * ratio:0.00}% - {_callTreeAggregator!.Format(node.Count)}) {node.MethodDescription}";
}

private Task OnNodeExpandedAsync(TreeViewItemExpandedEventArgs e)
{
var item = e.CurrentItem;
while (item.Items != null && item.Items.Count() == 1)
{
item = item.Items.First();
item.Expanded = true;
}

return Task.CompletedTask;
}

}

0 comments on commit e8de2f3

Please sign in to comment.