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

Commit a026015

Browse files
chore: [WPERF-953] WPA and WPA plugin detection
See merge request Linaro/WindowsPerf/vs-extension!105 === ChangeLog === * chore: wpa detection chore: handle win32 exception chore: remove cliwrap and opt to use onmouseup event instead chore: revert cliwrap for now to avoid messagebox issues
1 parent 0468785 commit a026015

File tree

6 files changed

+98
-7
lines changed

6 files changed

+98
-7
lines changed

WindowsPerfGUI/Resources/Locals/ErrorLanguagePack.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WindowsPerfGUI/Resources/Locals/ErrorLanguagePack.fr-FR.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,10 @@ Par exemple, r10 est un événement avec l'index 0x10</value>
167167
<data name="RunningCountingOverlapLine2" xml:space="preserve">
168168
<value>Veuillez attendre la fin du comptage en cours avant de redémarrer une autre instance</value>
169169
</data>
170+
<data name="WPANotInstalled" xml:space="preserve">
171+
<value>WPA n'est pas installé. Veuillez vous assurer qu'il est correctement installé et ajouté à la variable d'environnement PATH.</value>
172+
</data>
173+
<data name="WPAPluginNotInstalled" xml:space="preserve">
174+
<value>Impossible de détecter le plug-in WindowsPerf WPA. Veuillez vous assurer que le plugin est correctement installé.</value>
175+
</data>
170176
</root>

WindowsPerfGUI/Resources/Locals/ErrorLanguagePack.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,10 @@ For example r10 is event with index 0x10</value>
167167
<data name="RunningCountingOverlapLine2" xml:space="preserve">
168168
<value>Please wait for the current counting to finish before starting another counting instance</value>
169169
</data>
170+
<data name="WPANotInstalled" xml:space="preserve">
171+
<value>WPA is not installed. Please make sure it's installed correctly and added to the PATH environment variable.</value>
172+
</data>
173+
<data name="WPAPluginNotInstalled" xml:space="preserve">
174+
<value>Could not detect WindowsPerf WPA Plugin. Please make sure the plugin is installed correctly.</value>
175+
</data>
170176
</root>

WindowsPerfGUI/ToolWindows/CountingSetting/CountingSettingDialog.xaml.cs

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

3131
using System.Collections.Generic;
32-
using System.IO;
32+
using System.ComponentModel;
3333
using System.Linq;
34+
using System.Text;
3435
using System.Text.RegularExpressions;
3536
using System.Threading;
3637
using System.Threading.Tasks;
3738
using System.Windows;
3839
using System.Windows.Controls;
40+
using CliWrap;
3941
using Microsoft.VisualStudio.PlatformUI;
4042
using Microsoft.Win32;
4143
using WindowsPerfGUI.Options;
@@ -443,8 +445,61 @@ private void RemoveMetricButton_Click(object sender, RoutedEventArgs e)
443445
);
444446
}
445447

446-
private void OpenInWPA_Click(object sender, RoutedEventArgs e)
448+
volatile bool checkingWPAInstallation = false;
449+
450+
private async Task<bool> CheckWPAInstallationAsync()
451+
{
452+
if (checkingWPAInstallation)
453+
{
454+
return false;
455+
}
456+
457+
try
458+
{
459+
checkingWPAInstallation = true;
460+
StringBuilder outputStringBuilder = new();
461+
var request = await Cli.Wrap("wpa")
462+
.WithArguments(["-listplugins"])
463+
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(outputStringBuilder))
464+
.ExecuteAsync();
465+
466+
checkingWPAInstallation = false;
467+
string output = outputStringBuilder.ToString();
468+
469+
if (request.ExitCode != 0)
470+
{
471+
await VS.MessageBox.ShowErrorAsync(ErrorLanguagePack.WPANotInstalled);
472+
return false;
473+
}
474+
475+
bool isWPAPluginInstalled =
476+
!string.IsNullOrEmpty(output) && output.Contains("WindowsPerf WPA Plugin");
477+
if (!isWPAPluginInstalled)
478+
{
479+
await VS.MessageBox.ShowErrorAsync(ErrorLanguagePack.WPAPluginNotInstalled);
480+
}
481+
482+
return isWPAPluginInstalled;
483+
}
484+
catch (Win32Exception error)
485+
{
486+
Trace.WriteLine($"[ERROR]: {error.Message}");
487+
checkingWPAInstallation = false;
488+
await VS.MessageBox.ShowErrorAsync(ErrorLanguagePack.WPANotInstalled);
489+
return false;
490+
}
491+
}
492+
493+
private async void OpenInWPA_Click(object sender, RoutedEventArgs e)
447494
{
495+
OpenInWPAButton.IsEnabled = false;
496+
bool wpaInstalled = await CheckWPAInstallationAsync();
497+
498+
if (!wpaInstalled)
499+
{
500+
OpenInWPAButton.IsEnabled = true;
501+
return;
502+
}
448503
Process process = new();
449504
ProcessStartInfo startInfo =
450505
new()
@@ -458,6 +513,7 @@ private void OpenInWPA_Click(object sender, RoutedEventArgs e)
458513
process.StartInfo = startInfo;
459514
process.Start();
460515
process.Exited += new EventHandler(WPAProcessExited);
516+
461517
OpenInWPAButton.IsEnabled = false;
462518
}
463519

@@ -512,22 +568,24 @@ private void LoadFromJSONButton_Click(object sender, RoutedEventArgs e)
512568
fileDialog.Filter = "JSON files (*.json)|*.json";
513569

514570
bool? result = fileDialog.ShowDialog();
515-
if (result != true) return;
571+
if (result != true)
572+
return;
516573

517574
string filename = fileDialog.FileName;
518575
try
519576
{
520-
List<CountingEvent> wperfSampling = WperfClient.GetCountingEventsFromJSONFile(filename);
577+
List<CountingEvent> wperfSampling = WperfClient.GetCountingEventsFromJSONFile(
578+
filename
579+
);
521580
CountingSettings.countingSettingsForm.IsCountCollected = true;
522581
CountingSettings.countingSettingsForm.CountingResult = wperfSampling;
523-
524582
}
525583
catch (Exception err)
526584
{
527585
VS.MessageBox.ShowError("Error loading JSON file", err.Message);
528586
}
529587
}
530-
588+
531589
private void OpenSaveAsDialog(string extension)
532590
{
533591
SaveFileDialog SaveFileDialog =

WindowsPerfGUI/Utils/SDK/ProcessRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void StopProcess(bool force = false)
142142
SetConsoleCtrlHandler(null, false);
143143
}
144144

145-
public (string stdError, string stdOutput) StartAwaitedProcess(string[] args)
145+
public (string stdOutput, string stdError) StartAwaitedProcess(string[] args)
146146
{
147147
InitProcess(args);
148148
try

WindowsPerfGUI/WindowsPerfGUI.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@
298298
<PackageReference Include="AutoCompleteTextBox">
299299
<Version>1.7.2</Version>
300300
</PackageReference>
301+
<PackageReference Include="CliWrap">
302+
<Version>3.6.6</Version>
303+
</PackageReference>
301304
<PackageReference Include="Community.VisualStudio.VSCT" Version="16.0.29.6" PrivateAssets="all" />
302305
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.507" ExcludeAssets="Runtime">
303306
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

0 commit comments

Comments
 (0)