mirror of
https://github.com/actions/runner-images.git
synced 2025-12-14 22:05:17 +00:00
Measure and output installing and downloading durations (#4104)
This commit is contained in:
@@ -51,23 +51,27 @@ function Install-Binary
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
$installStartTime = Get-Date
|
||||||
Write-Host "Starting Install $Name..."
|
Write-Host "Starting Install $Name..."
|
||||||
$process = Start-Process -FilePath $filePath -ArgumentList $ArgumentList -Wait -PassThru
|
$process = Start-Process -FilePath $filePath -ArgumentList $ArgumentList -Wait -PassThru
|
||||||
|
|
||||||
$exitCode = $process.ExitCode
|
$exitCode = $process.ExitCode
|
||||||
|
$installCompleteTime = [math]::Round(($(Get-Date) - $installStartTime).TotalSeconds, 2)
|
||||||
if ($exitCode -eq 0 -or $exitCode -eq 3010)
|
if ($exitCode -eq 0 -or $exitCode -eq 3010)
|
||||||
{
|
{
|
||||||
Write-Host "Installation successful"
|
Write-Host "Installation successful in $installCompleteTime seconds"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Write-Host "Non zero exit code returned by the installation process: $exitCode"
|
Write-Host "Non zero exit code returned by the installation process: $exitCode"
|
||||||
|
Write-Host "Total time elapsed: $installCompleteTime seconds"
|
||||||
exit $exitCode
|
exit $exitCode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
$installCompleteTime = [math]::Round(($(Get-Date) - $installStartTime).TotalSeconds, 2)
|
||||||
Write-Host "Failed to install the $fileExtension ${Name}: $($_.Exception.Message)"
|
Write-Host "Failed to install the $fileExtension ${Name}: $($_.Exception.Message)"
|
||||||
|
Write-Host "Installation failed after $installCompleteTime seconds"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,24 +182,29 @@ function Start-DownloadWithRetry
|
|||||||
}
|
}
|
||||||
|
|
||||||
$filePath = Join-Path -Path $DownloadPath -ChildPath $Name
|
$filePath = Join-Path -Path $DownloadPath -ChildPath $Name
|
||||||
|
$downloadStartTime = Get-Date
|
||||||
|
|
||||||
#Default retry logic for the package.
|
# Default retry logic for the package.
|
||||||
while ($Retries -gt 0)
|
while ($Retries -gt 0)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
$downloadAttemptStartTime = Get-Date
|
||||||
Write-Host "Downloading package from: $Url to path $filePath ."
|
Write-Host "Downloading package from: $Url to path $filePath ."
|
||||||
(New-Object System.Net.WebClient).DownloadFile($Url, $filePath)
|
(New-Object System.Net.WebClient).DownloadFile($Url, $filePath)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Write-Host "There is an error during package downloading:`n $_"
|
$failTime = [math]::Round(($(Get-Date) - $downloadStartTime).TotalSeconds, 2)
|
||||||
|
$attemptTime = [math]::Round(($(Get-Date) - $downloadAttemptStartTime).TotalSeconds, 2)
|
||||||
|
Write-Host "There is an error encounterd after $attemptTime seconds during package downloading:`n $_"
|
||||||
$Retries--
|
$Retries--
|
||||||
|
|
||||||
if ($Retries -eq 0)
|
if ($Retries -eq 0)
|
||||||
{
|
{
|
||||||
Write-Host "File can't be downloaded. Please try later or check that file exists by url: $Url"
|
Write-Host "File can't be downloaded. Please try later or check that file exists by url: $Url"
|
||||||
|
Write-Host "Total time elapsed $failTime"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,6 +213,8 @@ function Start-DownloadWithRetry
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$downloadCompleteTime = [math]::Round(($(Get-Date) - $downloadStartTime).TotalSeconds, 2)
|
||||||
|
Write-Host "Package downloaded successfully in $downloadCompleteTime seconds"
|
||||||
return $filePath
|
return $filePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user