Skip to content

Commit f9303b1

Browse files
authored
Menu for flame graph and some minor UX improvements (#595)
* inclusive/exclusive samples: two commands instead of using column header name + use CanExecute pattern * find by name only when single node is selected * find by name in call tree view only when single node is selected * goto actions can use selected node * allow (un)grouping only when something is selected * allow changing priority when in Memory View + add tooltip to menu item to explain what it is * allow folding module/item when something is selected * allow symbols lookup when something is selected * allow go to source only when single item is selected * allow to set time range when text box is focused or some nodes are selected * allow include/exclude only when something is selected * simplify the Expand/Collapse code * simplify the Set BackgroundColor code + use the color for menu items * simplify open events * remove unused methods, extra empty lines + use expressions for 1 liners * make the context menu work for Flame Graph tab * use event which fires sooner
1 parent 8850b34 commit f9303b1

File tree

4 files changed

+355
-683
lines changed

4 files changed

+355
-683
lines changed

src/PerfView/StackViewer/CallTreeView.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ private int IndexInParent(CallTreeNode node)
345345
/// <summary>
346346
/// This is basically a CallTreeNode with extra state (state of expand boxes) associated needed for the viewer
347347
/// </summary>
348-
public class CallTreeViewNode
348+
public class CallTreeViewNode : INotifyPropertyChanged
349349
{
350350
[Conditional("DEBUG")]
351351
public void ValidateTree()
@@ -355,13 +355,19 @@ public void ValidateTree()
355355
#endif
356356
}
357357

358-
public void SetBackgroundColor(System.Drawing.Color color)
358+
public string BackgroundColor
359359
{
360-
BackgroundColor = color.Name;
360+
get => _backgroundColor;
361+
set
362+
{
363+
if(_backgroundColor != value)
364+
{
365+
_backgroundColor = value;
366+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(BackgroundColor)));
367+
}
368+
}
361369
}
362370

363-
public string BackgroundColor { get; set; }
364-
365371
/// <summary>
366372
/// Is the node expanded or not.
367373
/// </summary>
@@ -731,6 +737,9 @@ private static int FindChild(ObservableCollectionEx<CallTreeViewNode> flattenedT
731737
internal bool m_isExpanded; // Is this node expanded.
732738
private int m_indexGuess; // Where we think we are in the flattened tree, may not be accurate but wortch checking
733739
internal int m_depth; // My nesting level from root. (root == 0);
740+
private string _backgroundColor;
741+
742+
public event PropertyChangedEventHandler PropertyChanged;
734743
#endregion
735744
}
736745

src/PerfView/StackViewer/FlameGraphDrawingCanvas.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Windows.Controls;
77
using System.Windows.Input;
88
using System.Windows.Media;
9+
using Microsoft.Diagnostics.Tracing.Stacks;
910
using PerfView.Utilities;
1011
using static PerfView.FlameGraph;
1112

@@ -22,13 +23,15 @@ public class FlameGraphDrawingCanvas : Canvas
2223
private List<Visual> visuals = new List<Visual>();
2324
private FlameBoxesMap flameBoxesMap = new FlameBoxesMap();
2425
private ToolTip tooltip = new ToolTip() { FontSize = 20.0 };
26+
private CallTreeNode selectedNode;
2527
private ScaleTransform scaleTransform = new ScaleTransform(1.0f, 1.0f, 0.0f, 0.0f);
2628
private Cursor cursor;
2729

2830
public FlameGraphDrawingCanvas()
2931
{
3032
MouseMove += OnMouseMove;
3133
MouseLeave += OnMouseLeave;
34+
MouseRightButtonDown += (s, e) => selectedNode = flameBoxesMap.Find(e.MouseDevice.GetPosition(this)).Node;
3235
PreviewMouseWheel += OnPreviewMouseWheel;
3336
MouseLeftButtonDown += OnMouseLeftButtonDown;
3437
MouseLeftButtonUp += OnMouseLeftButtonUp;
@@ -38,6 +41,8 @@ public FlameGraphDrawingCanvas()
3841

3942
public bool IsEmpty => visuals.Count == 0;
4043

44+
public CallTreeNodeBase SelectedNode => selectedNode;
45+
4146
protected override int VisualChildrenCount => visuals.Count;
4247

4348
protected override Visual GetVisualChild(int index) => visuals[index];
@@ -102,7 +107,7 @@ private void OnMouseMove(object sender, MouseEventArgs e)
102107
if (!IsEmpty && e.LeftButton == MouseButtonState.Released)
103108
{
104109
var position = scaleTransform.Inverse.Transform(Mouse.GetPosition(this));
105-
var tooltipText = flameBoxesMap.Find(position);
110+
var tooltipText = flameBoxesMap.Find(position).TooltipText;
106111
if (tooltipText != null)
107112
{
108113
ShowTooltip(tooltipText);
@@ -295,7 +300,7 @@ internal void Sort()
295300
}
296301
}
297302

298-
internal string Find(Point point)
303+
internal FlameBox Find(Point point)
299304
{
300305
foreach (var rowData in boxesMap)
301306
{
@@ -323,14 +328,14 @@ internal string Find(Point point)
323328

324329
if (rowData.Value[mid].X <= point.X && point.X <= (rowData.Value[mid].X + rowData.Value[mid].Width))
325330
{
326-
return rowData.Value[mid].TooltipText;
331+
return rowData.Value[mid];
327332
}
328333

329-
return null;
334+
return default(FlameBox);
330335
}
331336
}
332337

333-
return null;
338+
return default(FlameBox);
334339
}
335340

336341
private static int CompareByX(FlameBox left, FlameBox right) => left.X.CompareTo(right.X);

0 commit comments

Comments
 (0)