Skip to content

Commit

Permalink
compress KM trace file.
Browse files Browse the repository at this point in the history
  • Loading branch information
shankarseal committed Nov 4, 2024
1 parent 118dcb6 commit 80834ad
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 48 deletions.
7 changes: 1 addition & 6 deletions scripts/cleanup_ebpf_cicd_tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ $Job = Start-Job -ScriptBlock {

if ($DumpFound -eq $True) {
Write-Log "Post-crash reboot detected on VM $VMName"
} else {
# Stop eBPF Components on the test VM. (Un-install is not necessary.)
# We *MUST* be able to stop all drivers cleanly after a test. Failure to do so indicates a fatal bug in
# one/some of the ebpf driver-set.
Stop-eBPFComponentsOnVM -VMName $VMname -ErrorAction Stop
}
}

Expand Down Expand Up @@ -89,7 +84,7 @@ while ($Job.State -eq 'Running') {

if ($TimeElapsed -gt $TestJobTimeout) {
if ($Job.State -eq "Running") {
$VMList = $Config.VMMap.$SelfHostedRunnerName
$VMList = $TestExecutionConfig.VMMap.$SelfHostedRunnerName
# currently one VM is used per runner.
$TestVMName = $VMList[0].Name
Write-Host "Cleaning up VM $TestVMName for Kernel Tests has timed out after one hour" -ForegroundColor Yellow
Expand Down
31 changes: 31 additions & 0 deletions scripts/common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,34 @@ function New-Credential
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($UserName, $AdminPassword)
return $Credential
}


function Compress-File
{
param ([Parameter(Mandatory = $True)] [string] $SourcePath,
[Parameter(Mandatory = $True)] [string] $DestinationPath
)

Write-Log "Compressing $SourcePath -> $DestinationPath"

# Retry 3 times to ensure compression operation succeeds.
# To mitigate error message: "The process cannot access the file <filename> because it is being used by another process."
$retryCount = 1
while ($retryCount -lt 4) {
$error.clear()
Compress-Archive `
-Path $SourcePath `
-DestinationPath $DestinationPath `
-CompressionLevel Fastest `
-Force
if ($error[0] -ne $null) {
$ErrorMessage = "*** ERROR *** Failed to compress kernel mode dump files: $error. Retrying $retryCount"
Write-Output $ErrorMessage
Start-Sleep -seconds (5 * $retryCount)
$retryCount++
} else {
# Compression succeeded.
break;
}
}
}
64 changes: 22 additions & 42 deletions scripts/config_test_vm.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -302,80 +302,59 @@ function Stop-eBPFComponentsOnVM
Write-Log "eBPF components stopped on $VMName" -ForegroundColor Green
}

function ArchiveKernelModeDumpOnVM
function Compress-KernelModeDumpOnVM
{
param (
[Parameter(Mandatory = $True)] [System.Management.Automation.Runspaces.PSSession] $Session
)

Invoke-Command -Session $Session -ScriptBlock {
param([Parameter(Mandatory=$True)] [string] $WorkingDirectory)

Import-Module $env:SystemDrive\$WorkingDirectory\common.psm1 -ArgumentList ($LogFileName) -Force -WarningAction SilentlyContinue

$KernelModeDumpFileSourcePath = "$Env:WinDir"
$KernelModeDumpFileDestinationPath = "$Env:SystemDrive\KernelDumps"

# Create the compressed dump folder if doesn't exist.
if (!(Test-Path $KernelModeDumpFileDestinationPath)) {
Write-Output "Creating $KernelModeDumpFileDestinationPath directory."
Write-Log "Creating $KernelModeDumpFileDestinationPath directory."
New-Item -ItemType Directory -Path $KernelModeDumpFileDestinationPath | Out-Null

# Make sure it was created
if (!(Test-Path $KernelModeDumpFileDestinationPath)) {
$ErrorMessage = `
"*** ERROR *** Create compressed dump file directory failed: $KernelModeDumpFileDestinationPath`n"
Write-Output $ErrorMessage
Start-Sleep -seconds 3
Write-Log $ErrorMessage
Throw $ErrorMessage
}
}

if (Test-Path $KernelModeDumpFileSourcePath\*.dmp -PathType Leaf) {
Write-Output "Found kernel mode dump(s) in $($KernelModeDumpFileSourcePath):"
Write-Log "Found kernel mode dump(s) in $($KernelModeDumpFileSourcePath):"
$DumpFiles = get-childitem -Path $KernelModeDumpFileSourcePath\*.dmp
foreach ($DumpFile in $DumpFiles) {
Write-Output "`tName:$($DumpFile.Name), Size:$((($DumpFile.Length) / 1MB).ToString("F2")) MB"
Write-Log "`tName:$($DumpFile.Name), Size:$((($DumpFile.Length) / 1MB).ToString("F2")) MB"
}
Write-Output "`n"

Write-Output `
Write-Log `
"Compressing kernel dump files: $KernelModeDumpFileSourcePath -> $KernelModeDumpFileDestinationPath"

# Retry 3 times to ensure compression operation succeeds.
# To mitigate error message: "The process cannot access the file 'C:\Windows\MEMORY.DMP' because it is being used by another process."
$retryCount = 1
while ($retryCount -lt 4) {
$error.clear()
Compress-Archive `
-Path "$KernelModeDumpFileSourcePath\*.dmp" `
-DestinationPath "$KernelModeDumpFileDestinationPath\km_dumps.zip" `
-CompressionLevel Fastest `
-Force
if ($error[0] -ne $null) {
$ErrorMessage = "*** ERROR *** Failed to compress kernel mode dump files: $error. Retrying $retryCount"
Write-Output $ErrorMessage
Start-Sleep -seconds (5 * $retryCount)
$retryCount++
} else {
# Compression succeeded.
break;
}
}

Compress-File -SourcePath $KernelModeDumpFileSourcePath\*.dmp -DestinationPath $KernelModeDumpFileDestinationPath\km_dumps.zip
if (Test-Path $KernelModeDumpFileDestinationPath\km_dumps.zip -PathType Leaf) {
$CompressedDumpFile = get-childitem -Path $KernelModeDumpFileDestinationPath\km_dumps.zip
Write-Output "Found compressed kernel mode dump file in $($KernelModeDumpFileDestinationPath):"
Write-Output `
Write-Log "Found compressed kernel mode dump file in $($KernelModeDumpFileDestinationPath):"
Write-Log `
"`tName:$($CompressedDumpFile.Name), Size:$((($CompressedDumpFile.Length) / 1MB).ToString("F2")) MB"
} else {
$ErrorMessage = "*** ERROR *** kernel mode dump compressed file not found.`n`n"
Write-Output $ErrorMessage
Start-Sleep -seconds 3
Write-Log $ErrorMessage
throw $ErrorMessage
}
} else {
Write-Output "`n"
Write-Output "No kernel mode dump(s) in $($KernelModeDumpFileSourcePath)."
Write-Log "No kernel mode dump(s) in $($KernelModeDumpFileSourcePath)."
}
}
} -ArgumentList ("eBPF") -ErrorAction Ignore
}

#
Expand Down Expand Up @@ -405,7 +384,7 @@ function Import-ResultsFromVM

# Archive and copy kernel crash dumps, if any.
Write-Log "Processing kernel mode dump (if any) on VM $VMName"
ArchiveKernelModeDumpOnVM -Session $VMSession
Compress-KernelModeDumpOnVM -Session $VMSession

$LocalKernelArchiveLocation = ".\TestLogs\$VMName\KernelDumps"
Copy-Item `
Expand All @@ -418,11 +397,9 @@ function Import-ResultsFromVM

if (Test-Path $LocalKernelArchiveLocation\km_dumps.zip -PathType Leaf) {
$LocalFile = get-childitem -Path $LocalKernelArchiveLocation\km_dumps.zip
Write-Log "`n"
Write-Log "Local copy of kernel mode dump archive in $($LocalKernelArchiveLocation) for VM $($VMName):"
Write-Log "`tName:$($LocalFile.Name), Size:$((($LocalFile.Length) / 1MB).ToString("F2")) MB"
} else {
Write-Log "`n"
Write-Log "No local copy of kernel mode dump archive in $($LocalKernelArchiveLocation) for VM $VMName."
}

Expand Down Expand Up @@ -489,13 +466,16 @@ function Import-ResultsFromVM

$EtlFileSize = (Get-ChildItem $WorkingDirectory\$EtlFile).Length/1MB
Write-Log "ETL file Size: $EtlFileSize MB"

Write-Log "Compressing $WorkingDirectory\$EtlFile ..."
Compress-File -SourcePath "$WorkingDirectory\$EtlFile" -DestinationPath "$WorkingDirectory\$EtlFile.zip"
} -ArgumentList ("eBPF", $LogFileName, $EtlFile) -ErrorAction Ignore

# Copy ETL from Test VM.
Write-Log ("Copy $WorkingDirectory\$EtlFile on $VMName to $pwd\TestLogs\$VMName\Logs")
Write-Log ("Copy $VMSystemDrive\eBPF\$EtlFile.zip on $VMName to $pwd\TestLogs\$VMName\Logs")
Copy-Item `
-FromSession $VMSession `
-Path "$VMSystemDrive\eBPF\$EtlFile" `
-Path "$VMSystemDrive\eBPF\$EtlFile.zip" `
-Destination ".\TestLogs\$VMName\Logs" `
-Recurse `
-Force `
Expand Down
3 changes: 3 additions & 0 deletions scripts/execute_ebpf_cicd_tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ while ($Job.State -eq 'Running') {

if ($TimeElapsed -gt $TestJobTimeout) {
if ($Job.State -eq "Running") {
$VMList = $Config.VMMap.$SelfHostedRunnerName
# currently one VM runs per runner.
$TestVMName = $VMList[0].Name
Write-Host "Running kernel tests on $TestVMName has timed out after one hour" -ForegroundColor Yellow
$Timestamp = Get-Date -Format 'yyyy-MM-dd_HH-mm-ss'
$CheckpointName = "Execution-Hang-$TestVMName-Checkpoint-$Timestamp"
Expand Down
1 change: 1 addition & 0 deletions scripts/install_ebpf.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function Stop-eBPFComponents {
$EbpfDrivers.GetEnumerator() | ForEach-Object {
try {
if ($_.Value.IsDriver) {
Write-Log "Stopping $($_.Key) driver..."
Stop-Service $_.Name -ErrorAction Stop 2>&1 | Write-Log
Write-Log "$($_.Key) driver stopped." -ForegroundColor Green
}
Expand Down

0 comments on commit 80834ad

Please sign in to comment.