Skip to content

Commit

Permalink
Merge pull request #754 from yuehuang010/main
Browse files Browse the repository at this point in the history
Add search menu for Top Expansive
  • Loading branch information
KirillOsenkov authored Jan 31, 2024
2 parents 5a670e6 + 3443f0e commit 797bcef
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
24 changes: 24 additions & 0 deletions src/StructuredLogViewer/Controls/BuildControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public partial class BuildControl : UserControl
private MenuItem viewSubtreeTextItem;
private MenuItem searchInSubtreeItem;
private MenuItem searchInNodeByNameItem;
private MenuItem searchThisNode;
private MenuItem excludeSubtreeFromSearchItem;
private MenuItem excludeNodeByNameFromSearch;
private MenuItem goToTimeLineItem;
Expand Down Expand Up @@ -185,6 +186,7 @@ public BuildControl(Build build, string logFilePath)
excludeSubtreeFromSearchItem = new MenuItem() { Header = "Exclude subtree from search" };
excludeNodeByNameFromSearch = new MenuItem() { Header = "Exclude node from search" };
searchInNodeByNameItem = new MenuItem() { Header = "Search in this node." };
searchThisNode = new MenuItem() { Header = "Search This Node" };
goToTimeLineItem = new MenuItem() { Header = "Go to timeline" };
goToTracingItem = new MenuItem() { Header = "Go to tracing" };
copyChildrenItem = new MenuItem() { Header = "Copy children" };
Expand Down Expand Up @@ -217,6 +219,7 @@ public BuildControl(Build build, string logFilePath)
excludeSubtreeFromSearchItem.Click += (s, a) => ExcludeSubtreeFromSearch();
excludeNodeByNameFromSearch.Click += (s, a) => ExcludeNodeByNameFromSearch();
searchInNodeByNameItem.Click += (s, a) => SearchInNodeByName();
searchThisNode.Click += (s, a) => SearchThisNode();
goToTimeLineItem.Click += (s, a) => GoToTimeLine();
goToTracingItem.Click += (s, a) => GoToTracing();
copyChildrenItem.Click += (s, a) => CopyChildren();
Expand All @@ -243,6 +246,7 @@ public BuildControl(Build build, string logFilePath)
contextMenu.AddItem(searchNuGetItem);
contextMenu.AddItem(searchInSubtreeItem);
contextMenu.AddItem(searchInNodeByNameItem);
contextMenu.AddItem(searchThisNode);
contextMenu.AddItem(excludeSubtreeFromSearchItem);
contextMenu.AddItem(excludeNodeByNameFromSearch);
contextMenu.AddItem(goToTimeLineItem);
Expand Down Expand Up @@ -389,6 +393,7 @@ public void Dispose()
excludeSubtreeFromSearchItem = null;
excludeNodeByNameFromSearch = null;
searchInNodeByNameItem = null;
searchThisNode = null;
goToTimeLineItem = null;
goToTracingItem = null;
copyChildrenItem = null;
Expand Down Expand Up @@ -855,6 +860,16 @@ private void ContextMenu_Opened(object sender, RoutedEventArgs e)
debugItem.Visibility = canRun;
hideItem.Visibility = node is TreeNode ? Visibility.Visible : Visibility.Collapsed;

if (node is SearchableItem searchItem)
{
searchThisNode.Visibility = Visibility.Visible;
searchThisNode.Header = $"Search {searchItem.SearchText}";
}
else
{
searchThisNode.Visibility = Visibility.Collapsed;
}

if (node is TimedNode timedNode)
{
showTimeItem.Visibility = Visibility.Visible;
Expand Down Expand Up @@ -1569,6 +1584,15 @@ public void SearchInNodeByName()
}
}

public void SearchThisNode()
{
if (treeView.SelectedItem is SearchableItem searchNode)
{
searchLogControl.SearchText = searchNode.SearchText;
SelectSearchTab();
}
}

public void ExcludeSubtreeFromSearch()
{
if (treeView.SelectedItem is TimedNode treeNode)
Expand Down
4 changes: 4 additions & 0 deletions src/StructuredLogViewer/Controls/TracingControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,10 @@ private Panel CreatePanelForNodeDivider(bool showTime)
var textBlock = new TextBlock();
textBlock.Text = $"{i}s";

// Set these to make TextBlock scale like TrueType.
textBlock.SnapsToDevicePixels = true;
TextOptions.SetTextFormattingMode(textBlock, TextFormattingMode.Ideal);

// add textHeight/2 pixels of front padding
Canvas.SetLeft(textBlock, textHeight / 2 + i * OneSecondPixelWidth);
canvas.Children.Add(textBlock);
Expand Down
10 changes: 6 additions & 4 deletions src/StructuredLogger/Analyzers/BuildAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,18 @@ string Intern(string text)
var top10Tasks = build.GetOrCreateNodeWithName<Folder>(folderName);
foreach (var kvp in durations)
{
var taskItem = new Item
var taskItem = new SearchableItem
{
Text = Intern(kvp.Key) + " = " + Intern($"{TextUtilities.DisplayDuration(kvp.Value.Duration)}, {kvp.Value.Count} calls.")
Text = Intern(kvp.Key) + " = " + Intern($"{TextUtilities.DisplayDuration(kvp.Value.Duration)}, {kvp.Value.Count} calls."),
SearchText = $@"$task ""{kvp.Key}""",
};
var childNodes = kvp.Value.ChildNodes.OrderByDescending(kv => kv.Value.Duration).Take(10);
foreach (var durationNodes in childNodes)
{
taskItem.AddChild(new Item
taskItem.AddChild(new SearchableItem
{
Text = Intern(durationNodes.Key) + " = " + Intern($"{TextUtilities.DisplayDuration(durationNodes.Value.Duration)}, {durationNodes.Value.Count} calls.")
Text = Intern(durationNodes.Key) + " = " + Intern($"{TextUtilities.DisplayDuration(durationNodes.Value.Duration)}, {durationNodes.Value.Count} calls."),
SearchText = $@"$target ""{durationNodes.Key}""",
});
}
top10Tasks.AddChild(taskItem);
Expand Down
19 changes: 19 additions & 0 deletions src/StructuredLogger/ObjectModel/SearchableItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Build.Logging.StructuredLogger
{
public class SearchableItem : Item
{
public SearchableItem() : base() { }

public string SearchText
{
get { return _searchText ?? this.Text; }
set { _searchText = value; }
}

private string _searchText;
}
}

0 comments on commit 797bcef

Please sign in to comment.