-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTracePeek.psm1
46 lines (43 loc) · 1.88 KB
/
TracePeek.psm1
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
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
Add-Type -Path (Join-Path $psscriptRoot 'TracePeek.dll') -ErrorAction Stop
function Start-TracePeek
{
[CmdletBinding(PositionalBinding=$true)]
param(
[Parameter(Mandatory=$true)]
[string[]]$Providers,
[TracePeek.TracePeekProjectionStyle]$ProjectionStyle,
[string]$SessionName
)
$tpc = New-Object -TypeName TracePeek.TracePeekController -ArgumentList $SessionName
$providersList = New-Object -TypeName System.Collections.Generic.List`[string]
foreach($provider in $providers){
$providersList.Add($provider)
}
$tpc.EnableProviders($providersList)
$eventSubscriberJob = Register-ObjectEvent -InputObject $tpc -EventName OnTracePeekEvent -SourceIdentifier $SessionName
Write-Host "TracePeek starting up..."
if($null -eq $ProjectionStyle){$null = $tpc.StartPeek()}
else{$null = $tpc.StartPeek($ProjectionStyle)}
Write-Host "TracePeek running."
Write-Host '!!! Press ALT+s when done to stop session and clean up resources !!!'
$consoleCancellationRequested = $false
while($consoleCancellationRequested -eq $false)
{
Wait-Event -SourceIdentifier $SessionName -Timeout 1 -ErrorAction SilentlyContinue |
ForEach-Object{ Write-Output $_.SourceArgs[0] ; Remove-Event -EventIdentifier $_.EventIdentifier}
while([Console]::KeyAvailable)
{
$keyPress = [Console]::ReadKey($true)
if ($keyPress.Modifiers.HasFlag([System.ConsoleModifiers]::Alt) -and $keyPress.KeyChar -eq 's')
{
Write-Host "TracePeek stopping and cleaning up."
$consoleCancellationRequested = $true
$tpc.StopPeek()
}
}
}
Unregister-Event -SourceIdentifier $SessionName
if($null -ne $eventSubscriberJob){Remove-Job -Id $eventSubscriberJob.Id -Force}
}