forked from microsoft/msquic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog.ps1
116 lines (88 loc) · 3.05 KB
/
log.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
<#
.SYNOPSIS
This script provides helpers for starting, stopping and canceling log collection.
.PARAMETER Start
Starts the logs being collected with the given profile.
.PARAMETER LogProfile
The name of the profile to use for log collection.
.PARAMETER Cancel
Stops the logs from being collected and discards any collected so far.
.PARAMETER Stop
Stops the logs from being collected and saves them to the -Output location.
.PARAMETER Output
The output file name or directory for the logs.
.PARAMETER ConvertToText
Converts the output logs to text.
.PARAMETER InstanceName
A unique name for the logging instance.
.EXAMPLE
logs.ps1 -Start -LogProfile Basic.Light
.EXAMPLE
logs.ps1 -Cancel
.EXAMPLE
logs.ps1 -Stop -Output quic.etl
#>
param (
[Parameter(Mandatory = $false, ParameterSetName='Start')]
[switch]$Start = $false,
[Parameter(Mandatory = $true, ParameterSetName='Start')]
[ValidateSet("Basic.Light", "Basic.Verbose", "Full.Light", "Full.Verbose", "SpinQuic.Light")]
[string]$LogProfile,
[Parameter(Mandatory = $false, ParameterSetName='Cancel')]
[switch]$Cancel = $false,
[Parameter(Mandatory = $false, ParameterSetName='Stop')]
[switch]$Stop = $false,
[Parameter(Mandatory = $true, ParameterSetName='Stop')]
[string]$OutputDirectory = "",
[Parameter(Mandatory = $false, ParameterSetName='Stop')]
[switch]$ConvertToText = $false,
[Parameter(Mandatory = $false, ParameterSetName='Stop')]
[string]$TmfPath = "",
[Parameter(Mandatory = $false)]
[string]$InstanceName = "msquic"
)
Set-StrictMode -Version 'Latest'
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
# Root directory of the project.
$RootDir = Split-Path $PSScriptRoot -Parent
# Path for the WPR profile.
$WprpFile = $RootDir + "\src\manifest\msquic.wprp"
# Start log collection.
function Log-Start {
if ($IsWindows) {
wpr.exe -start "$($WprpFile)!$($LogProfile)" -filemode -instancename $InstanceName
} else {
# TODO
Write-Debug "Logging not supported yet!"
}
}
# Cancels log collection, discarding any logs.
function Log-Cancel {
if ($IsWindows) {
wpr.exe -cancel -instancename $InstanceName
} else {
# TODO
Write-Debug "Logging not supported yet!"
}
}
# Stops log collection, keeping the logs.
function Log-Stop {
if ($IsWindows) {
$EtlPath = Join-Path $OutputDirectory "quic.etl"
wpr.exe -stop $EtlPath -instancename $InstanceName
if ($ConvertToText) {
$LogPath = Join-Path $OutputDirectory "quic.log"
$Command = "netsh trace convert $($EtlPath) output=$($LogPath) overwrite=yes report=no"
Invoke-Expression $Command
}
} else {
# TODO
Write-Debug "Logging not supported yet!"
}
}
##############################################################
# Main Execution #
##############################################################
if ($Start) { Log-Start }
if ($Cancel) { Log-Cancel }
if ($Stop) { Log-Stop }