Skip to content

Commit e2049a6

Browse files
committed
Process selection dialog: implement filter
1 parent 991618f commit e2049a6

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

src/PerfView/Dialogs/SelectProcess.xaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@
3131
</FlowDocument>
3232
</RichTextBox.Document>
3333
</RichTextBox>
34+
<Grid DockPanel.Dock="Top" >
35+
<Grid.ColumnDefinitions>
36+
<ColumnDefinition Width="Auto"/>
37+
<ColumnDefinition Width="100*"/>
38+
</Grid.ColumnDefinitions>
39+
<Rectangle Grid.Column="0" Grid.ColumnSpan="3" Fill="#FFD1D1D1"/>
40+
<TextBlock Grid.Column="0" VerticalAlignment="Center" Margin="5,0,0,0" ToolTip="Only processes that match this filter pattern are displayed.">
41+
<Hyperlink Command="Help" CommandParameter="ProcessFilterTextBox">Filter:</Hyperlink>
42+
</TextBlock>
43+
<TextBox Name="ProcessFilterTextBox" TextChanged="FilterTextChanged" Grid.Column="1" Margin="5,2,2,2" />
44+
</Grid>
3445
<Grid DockPanel.Dock="Bottom" Background="#FFB0B0B0" >
3546
<Grid.ColumnDefinitions>
3647
<ColumnDefinition Width="*"/>
@@ -47,8 +58,8 @@
4758
ToolTip="Investigate all processes"/>
4859
<Button Margin="5,4" Grid.Column="5" Width="80" Content="Cancel" Click="CancelClicked" IsCancel="True" />
4960
</Grid>
50-
<Grid PreviewKeyDown="KeyDownHander">
51-
<WPFToolKit:DataGrid Name="Grid"
61+
<Grid PreviewKeyDown="GridKeyDownHander">
62+
<WPFToolKit:DataGrid Name="Grid"
5263
AlternatingRowBackground="#FFF2F1A4"
5364
AutoGenerateColumns="False"
5465
MouseDoubleClick="OKClicked"

src/PerfView/Dialogs/SelectProcess.xaml.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.Media;
5+
using System.Text.RegularExpressions;
56
using System.Windows;
7+
using System.Windows.Controls;
68
using System.Windows.Input;
79

810
namespace PerfView
@@ -22,6 +24,8 @@ public SelectProcess(Window parentWindow, IEnumerable<IProcess> processes, TimeS
2224
AllProcsButton.Visibility = System.Windows.Visibility.Hidden;
2325
}
2426

27+
ProcessFilterTextBox.Text = "";
28+
2529
UpdateItemSource();
2630
var filteredProcesses = Grid.ItemsSource as List<IProcess>;
2731

@@ -95,7 +99,26 @@ private void UpdateItemSource()
9599
return;
96100
}
97101

98-
Grid.ItemsSource = m_processes;
102+
var filterText = ProcessFilterTextBox.Text;
103+
if (filterText == "")
104+
{
105+
Grid.ItemsSource = m_processes;
106+
return;
107+
}
108+
var regex = Regex.Escape(filterText);
109+
regex = regex.Replace(@"\*", ".*");
110+
var filterRegex = new Regex(regex, RegexOptions.IgnoreCase);
111+
112+
List<IProcess> processes = new List<IProcess>();
113+
foreach (var process in m_processes)
114+
{
115+
if (filterRegex.Match(process.Name).Success || filterRegex.Match(process.CommandLine).Success)
116+
{
117+
processes.Add(process);
118+
}
119+
}
120+
121+
Grid.ItemsSource = processes;
99122
}
100123

101124
internal void OKClicked(object sender, RoutedEventArgs e)
@@ -120,7 +143,7 @@ private void DoHyperlinkHelp(object sender, ExecutedRoutedEventArgs e)
120143
{
121144
MainWindow.DisplayUsersGuide(e.Parameter as string);
122145
}
123-
private void KeyDownHander(object sender, KeyEventArgs e)
146+
private void GridKeyDownHander(object sender, KeyEventArgs e)
124147
{
125148
if (e.Key == Key.Return)
126149
{
@@ -147,6 +170,11 @@ private void KeyDownHander(object sender, KeyEventArgs e)
147170
e.Handled = true;
148171
}
149172
}
173+
private void FilterTextChanged(object sender, TextChangedEventArgs e)
174+
{
175+
UpdateItemSource();
176+
}
177+
150178
private void AllProcsClicked(object sender, RoutedEventArgs e)
151179
{
152180
m_action(null);

src/PerfView/SupportFiles/UsersGuide.htm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,13 @@ <h3>
821821
you type the first character of the process name it will navigate to the first process
822822
with that name.&nbsp;
823823
</p>
824+
<p>
825+
<a id="ProcessFilterTextBox"><strong>Process Filter Textbox</strong></a> The box just
826+
above the list of process.&nbsp;&nbsp; If you type text in this box, then only
827+
processes that match this string (process name or command line, case insensitive) will
828+
be displayed. &nbsp;&nbsp; The * character is a wild card.&nbsp;&nbsp; This is a quick
829+
way of finding a particular process.
830+
</p>
824831
<p>
825832
If you wish to see samples for more than one process for your analysis click the
826833
&#39;All Procs&#39; button.&nbsp;&nbsp;&nbsp;&nbsp;

0 commit comments

Comments
 (0)