Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Commit be4badd

Browse files
feat: WPERF-954 wpa plugin config
See merge request Linaro/WindowsPerf/vs-extension!107 === ChangeLog === * feat: add default slelected directory in picker * feat: add env variable notice + directory picker * feat: wpa plugin config
1 parent a026015 commit be4badd

File tree

7 files changed

+252
-6
lines changed

7 files changed

+252
-6
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<UserControl
2+
x:Class="WindowsPerfGUI.Options.WPAOptions"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
d:DesignHeight="450"
8+
d:DesignWidth="800"
9+
mc:Ignorable="d">
10+
<ScrollViewer>
11+
<StackPanel>
12+
<Label Content="Custom search directory" />
13+
<Grid Margin="5">
14+
<Grid.ColumnDefinitions>
15+
<ColumnDefinition Width="*" />
16+
<ColumnDefinition Width="100" />
17+
</Grid.ColumnDefinitions>
18+
<TextBox
19+
x:Name="CustomSearchDir"
20+
Grid.Column="0"
21+
Margin="0,0,5,0"
22+
TextChanged="CustomSearchDir_TextChanged" />
23+
<Button
24+
Name="SelectDirectoryButton"
25+
Grid.Column="1"
26+
Click="Button_Click"
27+
Content="Select" />
28+
</Grid>
29+
<StackPanel x:Name="CheckboxContainer" Margin="5">
30+
<CheckBox
31+
Name="UseDefaultSearchLocation"
32+
Margin="0,0,0,5"
33+
Click="UseDefaultSearchLocation_Click" />
34+
<TextBlock
35+
x:Name="EnvironmentVariableNotice"
36+
FontSize="10"
37+
Visibility="Collapsed" />
38+
</StackPanel>
39+
</StackPanel>
40+
</ScrollViewer>
41+
</UserControl>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// BSD 3-Clause License
2+
//
3+
// Copyright (c) 2022, Arm Limited
4+
// All rights reserved.
5+
//
6+
// Redistribution and use in source and binary forms, with or without
7+
// modification, are permitted provided that the following conditions are met:
8+
//
9+
// 1. Redistributions of source code must retain the above copyright notice, this
10+
// list of conditions and the following disclaimer.
11+
//
12+
// 2. Redistributions in binary form must reproduce the above copyright notice,
13+
// this list of conditions and the following disclaimer in the documentation
14+
// and/or other materials provided with the distribution.
15+
//
16+
// 3. Neither the name of the copyright holder nor the names of its
17+
// contributors may be used to endorse or promote products derived from
18+
// this software without specific prior written permission.
19+
//
20+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
31+
using System.Windows.Controls;
32+
using System.Windows.Forms;
33+
using UserControl = System.Windows.Controls.UserControl;
34+
35+
namespace WindowsPerfGUI.Options
36+
{
37+
/// <summary>
38+
/// Interaction logic for WPAOptions.xaml
39+
/// </summary>
40+
public partial class WPAOptions : UserControl
41+
{
42+
public WPAOptions()
43+
{
44+
InitializeComponent();
45+
}
46+
47+
internal WPAOptionsPage wpaOptionsPage;
48+
49+
public void Initialize()
50+
{
51+
string defaultSearchDir = Environment.GetEnvironmentVariable(
52+
"WPA_ADDITIONAL_SEARCH_DIRECTORIES"
53+
);
54+
55+
string checkboxLabel = "Use default search directory";
56+
if (!string.IsNullOrEmpty(defaultSearchDir))
57+
{
58+
checkboxLabel += $": {defaultSearchDir}";
59+
}
60+
61+
UseDefaultSearchLocation.Content = checkboxLabel;
62+
63+
if (!string.IsNullOrEmpty(defaultSearchDir))
64+
{
65+
EnvironmentVariableNotice.Visibility = System.Windows.Visibility.Visible;
66+
EnvironmentVariableNotice.Text =
67+
$"WPA_ADDITIONAL_SEARCH_DIRECTORIES=\"{defaultSearchDir}\"";
68+
}
69+
UseDefaultSearchLocation.IsChecked = WPerfOptions.Instance.UseDefaultSearchDirectory;
70+
CustomSearchDir.IsEnabled = !WPerfOptions.Instance.UseDefaultSearchDirectory;
71+
SelectDirectoryButton.IsEnabled = !WPerfOptions.Instance.UseDefaultSearchDirectory;
72+
CustomSearchDir.Text = WPerfOptions.Instance.WPAPluginSearchDirectory;
73+
}
74+
75+
private void UseDefaultSearchLocation_Click(object sender, System.Windows.RoutedEventArgs e)
76+
{
77+
bool newValue = !WPerfOptions.Instance.UseDefaultSearchDirectory;
78+
CustomSearchDir.IsEnabled = !newValue;
79+
SelectDirectoryButton.IsEnabled = !newValue;
80+
UseDefaultSearchLocation.IsChecked = newValue;
81+
WPerfOptions.Instance.UseDefaultSearchDirectory = newValue;
82+
WPerfOptions.Instance.Save();
83+
}
84+
85+
private void CustomSearchDir_TextChanged(object sender, TextChangedEventArgs e)
86+
{
87+
WPerfOptions.Instance.WPAPluginSearchDirectory = CustomSearchDir.Text;
88+
WPerfOptions.Instance.Save();
89+
}
90+
91+
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
92+
{
93+
using var fbd = new FolderBrowserDialog()
94+
{
95+
SelectedPath = WPerfOptions.Instance.WPAPluginSearchDirectory,
96+
};
97+
DialogResult result = fbd.ShowDialog();
98+
99+
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
100+
{
101+
CustomSearchDir.Text = fbd.SelectedPath;
102+
}
103+
}
104+
}
105+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// BSD 3-Clause License
2+
//
3+
// Copyright (c) 2022, Arm Limited
4+
// All rights reserved.
5+
//
6+
// Redistribution and use in source and binary forms, with or without
7+
// modification, are permitted provided that the following conditions are met:
8+
//
9+
// 1. Redistributions of source code must retain the above copyright notice, this
10+
// list of conditions and the following disclaimer.
11+
//
12+
// 2. Redistributions in binary form must reproduce the above copyright notice,
13+
// this list of conditions and the following disclaimer in the documentation
14+
// and/or other materials provided with the distribution.
15+
//
16+
// 3. Neither the name of the copyright holder nor the names of its
17+
// contributors may be used to endorse or promote products derived from
18+
// this software without specific prior written permission.
19+
//
20+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
31+
using System.Runtime.InteropServices;
32+
using System.Windows;
33+
34+
namespace WindowsPerfGUI.Options
35+
{
36+
[ComVisible(true)]
37+
[Guid("4D40035D-E4E9-4D48-9DE3-1D6D35507EF0")]
38+
public class WPAOptionsPage : UIElementDialogPage
39+
{
40+
protected override UIElement Child
41+
{
42+
get
43+
{
44+
WPAOptions page = new() { wpaOptionsPage = this };
45+
page.Initialize();
46+
return page;
47+
}
48+
}
49+
}
50+
}

WindowsPerfGUI/Options/WPerfOptions.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,17 @@ public class WPerfOptions : BaseOptionModel<WPerfOptions>
5252
public bool WperfVersionCheckIgnore { get; set; } = false;
5353
public bool IsWperfInitialized { get; set; } = false;
5454
public bool HasSPESupport { get; set; } = false;
55+
public bool UseDefaultSearchDirectory { get; set; } = true;
56+
public string WPAPluginSearchDirectory { get; set; }
5557
public WperfVersion WperfCurrentVersion { get; set; }
5658
public WperfList WperfList { get; set; }
59+
5760
public void UpdateWperfVersion(WperfVersion wperfVersion)
5861
{
5962
IsWperfInitialized = true;
6063
WperfCurrentVersion = wperfVersion;
6164
}
65+
6266
public void UpdateWperfOptions(WperfVersion wperfVersion, WperfList wperfList)
6367
{
6468
UpdateWperfVersion(wperfVersion);
@@ -68,6 +72,7 @@ public void UpdateWperfOptions(WperfVersion wperfVersion, WperfList wperfList)
6872
}
6973
Save();
7074
}
75+
7176
public void UpdateWperfOptions(WperfVersion wperfVersion, bool hasSPESupport)
7277
{
7378
UpdateWperfVersion(wperfVersion);
@@ -76,8 +81,13 @@ public void UpdateWperfOptions(WperfVersion wperfVersion, bool hasSPESupport)
7681
WperfDefaults.HasSPESupport = hasSPESupport;
7782
Save();
7883
}
84+
7985
#nullable enable
80-
public void UpdateWperfOptions(WperfVersion wperfVersion, WperfList? wperfList, bool? hasSPESupport)
86+
public void UpdateWperfOptions(
87+
WperfVersion wperfVersion,
88+
WperfList? wperfList,
89+
bool? hasSPESupport
90+
)
8191
{
8292
UpdateWperfVersion(wperfVersion);
8393
if (wperfList != null)

WindowsPerfGUI/ToolWindows/CountingSetting/CountingSettingDialog.xaml.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,21 @@ private void RemoveMetricButton_Click(object sender, RoutedEventArgs e)
445445
);
446446
}
447447

448+
private List<string> GenerateWPACommand(List<string> args)
449+
{
450+
List<string> _args = [];
451+
if (
452+
!WPerfOptions.Instance.UseDefaultSearchDirectory
453+
&& !string.IsNullOrEmpty(WPerfOptions.Instance.WPAPluginSearchDirectory)
454+
)
455+
{
456+
_args.Add($"-addsearchdir {WPerfOptions.Instance.WPAPluginSearchDirectory}");
457+
}
458+
459+
_args.AddRange(args);
460+
return _args;
461+
}
462+
448463
volatile bool checkingWPAInstallation = false;
449464

450465
private async Task<bool> CheckWPAInstallationAsync()
@@ -459,7 +474,7 @@ private async Task<bool> CheckWPAInstallationAsync()
459474
checkingWPAInstallation = true;
460475
StringBuilder outputStringBuilder = new();
461476
var request = await Cli.Wrap("wpa")
462-
.WithArguments(["-listplugins"])
477+
.WithArguments(GenerateWPACommand(["-listplugins"]))
463478
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(outputStringBuilder))
464479
.ExecuteAsync();
465480

@@ -500,13 +515,17 @@ private async void OpenInWPA_Click(object sender, RoutedEventArgs e)
500515
OpenInWPAButton.IsEnabled = true;
501516
return;
502517
}
518+
string args = string.Join(
519+
" ",
520+
GenerateWPACommand([$"-i \"{WperfClient.OutputPath}.json\""])
521+
);
503522
Process process = new();
504523
ProcessStartInfo startInfo =
505524
new()
506525
{
507526
WindowStyle = ProcessWindowStyle.Hidden,
508527
FileName = "cmd.exe",
509-
Arguments = $"/C wpa -i \"{WperfClient.OutputPath}.json\"",
528+
Arguments = $"/C wpa {args}",
510529
};
511530

512531
process.EnableRaisingEvents = true;

WindowsPerfGUI/WindowsPerfGUI.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
<Compile Include="Components\TreeListView\TreeListItem.cs" />
7676
<Compile Include="Components\TreeListView\TreeNode.cs" />
7777
<Compile Include="Options\SamplingManager.cs" />
78+
<Compile Include="Options\WPAOptions.xaml.cs">
79+
<DependentUpon>WPAOptions.xaml</DependentUpon>
80+
</Compile>
81+
<Compile Include="Options\WPAOptionsPage.cs">
82+
<SubType>Component</SubType>
83+
</Compile>
7884
<Compile Include="Resources\Locals\CountingSettingsLanguagePack.Designer.cs">
7985
<AutoGen>True</AutoGen>
8086
<DesignTime>True</DesignTime>
@@ -212,6 +218,7 @@
212218
<EmbeddedResource Include="Resources\Locals\OptionsPageLanguagePack.resx">
213219
<Generator>PublicResXFileCodeGenerator</Generator>
214220
<LastGenOutput>OptionsPageLanguagePack.Designer.cs</LastGenOutput>
221+
<SubType>Designer</SubType>
215222
</EmbeddedResource>
216223
<EmbeddedResource Include="Resources\Locals\SamplingExplorerLanguagePack.fr-FR.resx">
217224
<SubType>Designer</SubType>
@@ -243,6 +250,10 @@
243250
<Generator>MSBuild:Compile</Generator>
244251
<SubType>Designer</SubType>
245252
</Page>
253+
<Page Include="Options\WPAOptions.xaml">
254+
<Generator>MSBuild:Compile</Generator>
255+
<SubType>Designer</SubType>
256+
</Page>
246257
<Page Include="Options\WPerfPath.xaml">
247258
<SubType>Designer</SubType>
248259
<Generator>MSBuild:Compile</Generator>

WindowsPerfGUI/WindowsPerfGUIPackage.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030

3131

32-
global using Community.VisualStudio.Toolkit;
33-
global using Microsoft.VisualStudio.Shell;
3432
global using System;
3533
global using System.Diagnostics;
34+
global using Community.VisualStudio.Toolkit;
35+
global using Microsoft.VisualStudio.Shell;
3636
global using Task = System.Threading.Tasks.Task;
3737
using System.Linq;
3838
using System.Runtime.InteropServices;
@@ -78,6 +78,15 @@ namespace WindowsPerfGUI
7878
true,
7979
SupportsProfiles = true
8080
)]
81+
[ProvideOptionPage(
82+
typeof(WPAOptionsPage),
83+
"WindowsPerf",
84+
"WPA Options",
85+
0,
86+
0,
87+
true,
88+
SupportsProfiles = true
89+
)]
8190
public sealed class WindowsPerfGUIPackage : ToolkitPackage
8291
{
8392
public static OutputWindowPane WperfOutputWindow { get; set; }
@@ -106,7 +115,8 @@ protected override async Task OnAfterPackageLoadedAsync(CancellationToken cancel
106115
if (!shouldIgnoreWperfVersion)
107116
{
108117
(WperfVersion versions, string stdVersionError) = wperfClient.GetVersion();
109-
if (!string.IsNullOrEmpty(stdVersionError)) throw new Exception("Unable to get WindowsPerf version");
118+
if (!string.IsNullOrEmpty(stdVersionError))
119+
throw new Exception("Unable to get WindowsPerf version");
110120
bool speSupport = wperfClient.CheckIsSPESupported();
111121
WPerfOptions.Instance.UpdateWperfOptions(versions, speSupport);
112122
string wperfVersion = versions.Components.FirstOrDefault().ComponentVersion;

0 commit comments

Comments
 (0)