2020-05-13 05:08:05 +03:00
|
|
|
<#
|
|
|
|
|
|
|
|
.SYNOPSIS
|
|
|
|
This script provides helpers for starting, stopping and canceling log collection.
|
|
|
|
|
|
|
|
.PARAMETER Start
|
|
|
|
Starts the logs being collected with the given profile.
|
|
|
|
|
2020-08-10 22:37:19 +03:00
|
|
|
.PARAMETER Profile
|
2020-05-13 05:08:05 +03:00
|
|
|
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.
|
|
|
|
|
2020-08-10 22:37:19 +03:00
|
|
|
.PARAMETER RawLogOnly
|
|
|
|
Does not convert the output logs to text. Only keeps raw files.
|
2020-05-13 05:08:05 +03:00
|
|
|
|
|
|
|
.PARAMETER InstanceName
|
|
|
|
A unique name for the logging instance.
|
|
|
|
|
2021-04-22 02:30:51 +03:00
|
|
|
.PARAMETER ProfileInScriptDirectory
|
|
|
|
Flag for if the MsQuic wprp file is in the same directory as the script.
|
|
|
|
|
2020-05-13 05:08:05 +03:00
|
|
|
.EXAMPLE
|
2020-08-10 22:37:19 +03:00
|
|
|
logs.ps1 -Start -Profile Basic.Light
|
2020-05-13 05:08:05 +03:00
|
|
|
|
|
|
|
.EXAMPLE
|
|
|
|
logs.ps1 -Cancel
|
|
|
|
|
|
|
|
.EXAMPLE
|
2020-08-10 22:37:19 +03:00
|
|
|
logs.ps1 -Stop -Output .\quic
|
2020-05-13 05:08:05 +03:00
|
|
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
param (
|
|
|
|
[Parameter(Mandatory = $false, ParameterSetName='Start')]
|
|
|
|
[switch]$Start = $false,
|
|
|
|
|
2020-08-03 21:45:48 +03:00
|
|
|
[Parameter(Mandatory = $false, ParameterSetName='Start')]
|
|
|
|
[switch]$Stream = $false,
|
|
|
|
|
2020-08-10 22:37:19 +03:00
|
|
|
[Parameter(Mandatory = $false, ParameterSetName='Start')]
|
2022-06-16 01:16:17 +03:00
|
|
|
[ValidateSet("Basic.Light", "Datapath.Light", "Datapath.Verbose", "Stacks.Light", "RPS.Light", "RPS.Verbose", "Performance.Light", "Basic.Verbose", "Performance.Light", "Performance.Verbose", "Full.Light", "Full.Verbose", "SpinQuic.Light")]
|
2020-08-10 22:37:19 +03:00
|
|
|
[string]$Profile = "Full.Light",
|
2020-05-13 05:08:05 +03:00
|
|
|
|
|
|
|
[Parameter(Mandatory = $false, ParameterSetName='Cancel')]
|
|
|
|
[switch]$Cancel = $false,
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $false, ParameterSetName='Stop')]
|
|
|
|
[switch]$Stop = $false,
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName='Stop')]
|
2020-12-04 01:43:09 +03:00
|
|
|
[string]$OutputPath = "",
|
2020-05-13 05:08:05 +03:00
|
|
|
|
|
|
|
[Parameter(Mandatory = $false, ParameterSetName='Stop')]
|
2020-08-10 22:37:19 +03:00
|
|
|
[switch]$RawLogOnly = $false,
|
2020-05-13 05:08:05 +03:00
|
|
|
|
|
|
|
[Parameter(Mandatory = $false, ParameterSetName='Stop')]
|
|
|
|
[string]$TmfPath = "",
|
|
|
|
|
2020-08-03 21:45:48 +03:00
|
|
|
[Parameter(Mandatory = $false, ParameterSetName='Decode')]
|
|
|
|
[switch]$Decode = $false,
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName='Decode')]
|
|
|
|
[string]$LogFile,
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $true, ParameterSetName='Decode')]
|
|
|
|
[string]$WorkingDirectory,
|
|
|
|
|
2020-05-13 05:08:05 +03:00
|
|
|
[Parameter(Mandatory = $false)]
|
2021-04-22 02:30:51 +03:00
|
|
|
[string]$InstanceName = "msquic",
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
|
|
[switch]$ProfileInScriptDirectory = $false
|
2020-05-13 05:08:05 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
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"
|
2021-04-22 02:30:51 +03:00
|
|
|
if ($ProfileInScriptDirectory) {
|
|
|
|
$WprpFile = Join-Path $PSScriptRoot MsQuic.wprp
|
|
|
|
}
|
2020-08-03 21:45:48 +03:00
|
|
|
$SideCar = Join-Path $RootDir "src/manifest/clog.sidecar"
|
|
|
|
$Clog2Text_lttng = "$HOME/.dotnet/tools/clog2text_lttng"
|
|
|
|
|
|
|
|
$TempDir = $null
|
|
|
|
if ($IsLinux) {
|
|
|
|
$InstanceName = $InstanceName.Replace(".", "_")
|
|
|
|
$TempDir = Join-Path $HOME "QUICLogs" $InstanceName
|
|
|
|
}
|
2020-05-13 05:08:05 +03:00
|
|
|
|
|
|
|
# Start log collection.
|
|
|
|
function Log-Start {
|
|
|
|
if ($IsWindows) {
|
2020-08-26 02:01:48 +03:00
|
|
|
wpr.exe -start "$($WprpFile)!$($Profile)" -filemode -instancename $InstanceName 2>&1
|
2021-02-12 21:58:41 +03:00
|
|
|
} elseif ($IsMacOS) {
|
2020-05-13 05:08:05 +03:00
|
|
|
} else {
|
2020-08-03 21:45:48 +03:00
|
|
|
if (Test-Path $TempDir) {
|
|
|
|
Write-Error "LTTng session ($InstanceName) already running! ($TempDir)"
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if ($Stream) {
|
|
|
|
lttng -q create msquiclive --live
|
|
|
|
} else {
|
|
|
|
New-Item -Path $TempDir -ItemType Directory -Force | Out-Null
|
|
|
|
$Command = "lttng create $InstanceName -o=$TempDir"
|
|
|
|
Invoke-Expression $Command | Write-Debug
|
|
|
|
}
|
|
|
|
lttng enable-event --userspace CLOG_* | Write-Debug
|
2020-08-31 21:33:13 +03:00
|
|
|
lttng add-context --userspace --type=vpid --type=vtid | Write-Debug
|
2020-08-03 21:45:48 +03:00
|
|
|
lttng start | Write-Debug
|
|
|
|
|
|
|
|
if ($Stream) {
|
|
|
|
lttng list | Write-Debug
|
|
|
|
babeltrace -i lttng-live net://localhost | Write-Debug
|
2022-01-04 18:11:46 +03:00
|
|
|
$myHostName = hostname
|
|
|
|
Write-Host "Now decoding LTTng events in realtime on host=$myHostName...`n"
|
|
|
|
$args = "babeltrace --names all -i lttng-live net://localhost/host/$myHostName/msquiclive | $Clog2Text_lttng -s $SideCar --showTimestamp --showCpuInfo"
|
2020-08-03 21:45:48 +03:00
|
|
|
Write-Host $args
|
|
|
|
Invoke-Expression $args
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if ($Stream) {
|
|
|
|
Invoke-Expression "lttng destroy msquiclive" | Write-Debug
|
|
|
|
}
|
|
|
|
}
|
2020-05-13 05:08:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Cancels log collection, discarding any logs.
|
|
|
|
function Log-Cancel {
|
|
|
|
if ($IsWindows) {
|
2020-08-26 02:01:48 +03:00
|
|
|
try {
|
|
|
|
wpr.exe -cancel -instancename $InstanceName 2>&1
|
|
|
|
} catch {
|
|
|
|
}
|
2021-11-24 01:12:08 +03:00
|
|
|
$global:LASTEXITCODE = 0
|
2021-02-12 21:58:41 +03:00
|
|
|
} elseif ($IsMacOS) {
|
2020-05-13 05:08:05 +03:00
|
|
|
} else {
|
2020-08-03 21:45:48 +03:00
|
|
|
if (!(Test-Path $TempDir)) {
|
2020-08-26 02:01:48 +03:00
|
|
|
Write-Debug "LTTng session ($InstanceName) not currently running"
|
|
|
|
} else {
|
2021-02-25 18:46:39 +03:00
|
|
|
Invoke-Expression "lttng destroy -n $InstanceName" | Write-Debug
|
2020-08-26 02:01:48 +03:00
|
|
|
Remove-Item -Path $TempDir -Recurse -Force | Out-Null
|
|
|
|
Write-Debug "Destroyed LTTng session ($InstanceName) and deleted $TempDir"
|
2020-08-03 21:45:48 +03:00
|
|
|
}
|
2020-05-13 05:08:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Stops log collection, keeping the logs.
|
|
|
|
function Log-Stop {
|
|
|
|
if ($IsWindows) {
|
2020-12-04 01:43:09 +03:00
|
|
|
$EtlPath = $OutputPath + ".etl"
|
2020-08-26 02:01:48 +03:00
|
|
|
wpr.exe -stop $EtlPath -instancename $InstanceName 2>&1
|
2020-08-10 22:37:19 +03:00
|
|
|
if (!$RawLogOnly) {
|
2020-12-04 01:43:09 +03:00
|
|
|
$LogPath = $OutputPath + ".log"
|
2020-05-13 05:08:05 +03:00
|
|
|
$Command = "netsh trace convert $($EtlPath) output=$($LogPath) overwrite=yes report=no"
|
2020-08-13 17:25:14 +03:00
|
|
|
if ($TmfPath -ne "" -and (Test-Path $TmfPath)) {
|
2020-08-08 00:04:07 +03:00
|
|
|
$Command += " tmfpath=$TmfPath"
|
|
|
|
}
|
2020-05-13 05:08:05 +03:00
|
|
|
Invoke-Expression $Command
|
|
|
|
}
|
2021-02-12 21:58:41 +03:00
|
|
|
} elseif ($IsMacOS) {
|
2020-05-13 05:08:05 +03:00
|
|
|
} else {
|
2020-12-04 01:43:09 +03:00
|
|
|
$ClogOutputDecodeFile = $OutputPath + ".log"
|
2020-08-03 21:45:48 +03:00
|
|
|
|
2020-12-04 01:43:09 +03:00
|
|
|
if (!(Test-Path $OutputPath)) {
|
|
|
|
New-Item -Path $OutputPath -ItemType Directory -Force | Out-Null
|
2020-08-03 21:45:48 +03:00
|
|
|
}
|
2020-08-10 22:37:19 +03:00
|
|
|
|
2020-08-03 21:45:48 +03:00
|
|
|
if (!(Test-Path $TempDir)) {
|
|
|
|
Write-Error "LTTng session ($InstanceName) not currently running!"
|
|
|
|
}
|
|
|
|
|
|
|
|
Invoke-Expression "lttng stop $InstanceName" | Write-Debug
|
|
|
|
|
2020-12-04 01:43:09 +03:00
|
|
|
$LTTNGTarFile = $OutputPath + ".tgz"
|
|
|
|
$BableTraceFile = $OutputPath + ".babel.txt"
|
2020-08-03 21:45:48 +03:00
|
|
|
|
|
|
|
Write-Host "tar/gzip LTTng log files: $LTTNGTarFile"
|
|
|
|
tar -cvzf $LTTNGTarFile $TempDir | Write-Debug
|
|
|
|
|
2020-08-10 22:37:19 +03:00
|
|
|
if (!$RawLogOnly) {
|
2020-08-03 21:45:48 +03:00
|
|
|
Write-Debug "Decoding LTTng into BabelTrace format ($BableTraceFile)"
|
|
|
|
babeltrace --names all $TempDir/* > $BableTraceFile
|
2022-03-27 02:27:26 +03:00
|
|
|
Write-Host "Decoding into human-readable text: $ClogOutputDecodeFile"
|
|
|
|
$Command = "$Clog2Text_lttng -i $BableTraceFile -s $SideCar -o $ClogOutputDecodeFile --showTimestamp --showCpuInfo"
|
|
|
|
Write-Host $Command
|
2020-08-03 21:45:48 +03:00
|
|
|
|
2022-03-27 02:27:26 +03:00
|
|
|
try {
|
|
|
|
Invoke-Expression $Command | Write-Debug
|
|
|
|
} catch {
|
|
|
|
$err = $_
|
|
|
|
Write-Host "Failed to decode logs."
|
|
|
|
Write-Host "Babeltrace ran. Run `"prepare-machine.ps1 -InstallClog2Text`" and run the following command"
|
|
|
|
$Command
|
|
|
|
Write-Host $err
|
|
|
|
}
|
2020-08-03 21:45:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Invoke-Expression "lttng destroy $InstanceName" | Write-Debug
|
|
|
|
Remove-Item -Path $TempDir -Recurse -Force | Out-Null
|
|
|
|
Write-Debug "Destroyed LTTng session ($InstanceName) and deleted $TempDir"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# Decodes a log file.
|
|
|
|
function Log-Decode {
|
|
|
|
|
|
|
|
if (!(Test-Path $WorkingDirectory)) {
|
|
|
|
New-Item -Path $WorkingDirectory -ItemType Directory -Force | Out-Null
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($IsWindows) {
|
|
|
|
Write-Error "Not supported on Windows"
|
2021-02-12 21:58:41 +03:00
|
|
|
} elseif ($IsMacOS) {
|
2020-08-03 21:45:48 +03:00
|
|
|
} else {
|
|
|
|
Write-Host $LogFile
|
|
|
|
|
|
|
|
$DecompressedLogs = Join-Path $WorkingDirectory "DecompressedLogs"
|
|
|
|
$ClogOutputDecodeFile = Join-Path $WorkingDirectory "clog_decode.txt"
|
|
|
|
$BableTraceFile = Join-Path $WorkingDirectory "decoded_babeltrace.txt"
|
|
|
|
|
|
|
|
mkdir $WorkingDirectory
|
|
|
|
mkdir $DecompressedLogs
|
|
|
|
|
|
|
|
Write-Host "Decompressing $Logfile into $DecompressedLogs"
|
|
|
|
tar xvfz $Logfile -C $DecompressedLogs
|
|
|
|
|
|
|
|
Write-Host "Decoding LTTng into BabelTrace format ($BableTraceFile)"
|
|
|
|
babeltrace --names all $DecompressedLogs/* > $BableTraceFile
|
2022-03-27 02:27:26 +03:00
|
|
|
Write-Host "Decoding Babeltrace into human text using CLOG"
|
|
|
|
$Command = "$Clog2Text_lttng -i $BableTraceFile -s $SideCar -o $ClogOutputDecodeFile"
|
|
|
|
Write-Host $Command
|
2020-08-03 21:45:48 +03:00
|
|
|
|
2022-03-27 02:27:26 +03:00
|
|
|
try {
|
|
|
|
Invoke-Expression $Command
|
|
|
|
} catch {
|
|
|
|
$err = $_
|
|
|
|
Write-Host "Failed to decode logs."
|
|
|
|
Write-Host "Babeltrace ran. Run `"prepare-machine.ps1 -InstallClog2Text`" and run the following command"
|
|
|
|
$Command
|
|
|
|
Write-Host $err
|
|
|
|
}
|
2020-05-13 05:08:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
##############################################################
|
|
|
|
# Main Execution #
|
|
|
|
##############################################################
|
|
|
|
|
|
|
|
if ($Start) { Log-Start }
|
|
|
|
if ($Cancel) { Log-Cancel }
|
|
|
|
if ($Stop) { Log-Stop }
|
2020-08-03 21:45:48 +03:00
|
|
|
if ($Decode) { Log-Decode }
|