-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathLaunchWpaPerfToolsLinuxAndroid.ps1
117 lines (99 loc) · 3.67 KB
/
LaunchWpaPerfToolsLinuxAndroid.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
<#
.Synopsis
Launches WPA UI with the Microsoft-Performance-Tools-Linux-Android plugins
#>
Param(
[parameter(Mandatory=$false)]
[alias("i")]
$InputFile,
[parameter(Mandatory=$false)]
[alias("p")]
$WpaProfile,
[parameter(Mandatory=$false)]
[alias("l")]
$LinuxPerfToolsPluginFolder
)
$MinStoreWPAVersion = New-Object -TypeName System.Version -ArgumentList "10.0.22500.0"
$WPAPreviewStoreLink = "https://www.microsoft.com/en-us/p/windows-performance-analyzer-preview/9n58qrw40dfw"
Write-Host "Please see https://aka.ms/linuxperftools for help"
if (-not $LinuxPerfToolsPluginFolder -or -not (Test-Path -Path $LinuxPerfToolsPluginFolder -ErrorAction Ignore | Out-Null))
{
$scriptPath = Get-Item (Split-Path $MyInvocation.MyCommand.Path -Parent)
$LinuxPerfToolsPluginFolder = $scriptPath.Parent.Parent.FullName
}
Write-Host "Using root folder as:" $LinuxPerfToolsPluginFolder
if ($LinuxPerfToolsPluginFolder)
{
$localLinuxPerfWpaAddins = Join-Path -Path $LinuxPerfToolsPluginFolder -ChildPath "MicrosoftPerfToolkitAddins"
}
Write-Host "Using plugins folder as:" $localLinuxPerfWpaAddins
if ($LinuxPerfToolsPluginFolder -and -not (Test-Path -Path $localLinuxPerfWpaAddins))
{
Write-Host "Please download the latest release from https://github.com/microsoft/Microsoft-Performance-Tools-Linux-Android/releases"
Start-Process "https://github.com/microsoft/Microsoft-Performance-Tools-Linux-Android/releases"
Pause
Exit
}
$wpaPreviewStorePkg = Get-AppPackage -Name Microsoft.WindowsPerformanceAnalyzerPreview
if (-not $wpaPreviewStorePkg -or $wpaPreviewStorePkg.Status -ne "Ok")
{
Write-Error -Category NotInstalled -Message "REQUIRED PREREQUISITE Store Windows Performance Analyzer (Preview) is not installed. Please install it from the Store. Launching $WPAPreviewStoreLink"
Start-Process "$WPAPreviewStoreLink"
Pause
Exit
}
$v = New-Object -TypeName System.Version -ArgumentList $wpaPreviewStorePkg.Version
# Is MinStoreWPAVersion same, later, or earlier than current WPA version?
$WpaVersionComparison = $MinStoreWPAVersion.CompareTo($v);
switch ($WpaVersionComparison )
{
# MinStoreWPAVersion the same as current WPA
0 { break }
# MinStoreWPAVersion later than current WPA
1
{
Write-Error -Category NotInstalled -Message "Current WPA version is $v. Need minimum of WPA $MinStoreWPAVersion. Redirecting to Store WPA so that you can update...";
Start-Process "$WPAPreviewStoreLink"
Pause
Exit
}
# MinStoreWPAVersion earlier than current WPA. That's ok
-1 { break }
}
$wpaProcess = "$env:LOCALAPPDATA\Microsoft\WindowsApps\wpa.exe"
$startInfo = New-Object System.Diagnostics.ProcessStartInfo
$startInfo.FileName = $wpaProcess
if ($InputFile)
{
$paramFile = Get-Item $InputFile -ErrorAction Continue
if ($paramFile.Exists)
{
if ($WpaProfile)
{
$startInfo.Arguments = "-i `"$InputFile`" -profile `"$WpaProfile`" -addsearchdir `"$localLinuxPerfWpaAddins`""
}
else
{
$startInfo.Arguments = "-i `"$InputFile`" -addsearchdir `"$localLinuxPerfWpaAddins`""
}
}
}
else
{
$startInfo.Arguments = "-addsearchdir `"$localLinuxPerfWpaAddins`""
}
Write-Host "Launching" $wpaProcess $startInfo.Arguments
$startInfo.RedirectStandardOutput = $true
$startInfo.UseShellExecute = $false
$startInfo.CreateNoWindow = $false
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $startInfo
$process.Start()
sleep 1
if ($process.HasExited)
{
Write-Host "Process StdOut:"
Write-Host $process.StandardOutput.ReadToEnd()
}