Skip to content

Commit 7af490a

Browse files
Add more timing logs (#678)
* Add more timing logs * add script name
1 parent c7f397a commit 7af490a

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

scripts/Invoke-CodeGen.ps1

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ function Invoke-ScriptWithLogging {
3232
Write-Host ""
3333
}
3434

35+
36+
$script:startTime = Get-Date
37+
$scriptName = $MyInvocation.MyCommand.Name
38+
39+
function Write-ElapsedTime {
40+
[CmdletBinding()]
41+
param(
42+
[Parameter(Mandatory = $true)]
43+
[string]$Message
44+
)
45+
46+
$elapsedTime = [math]::Round(((Get-Date) - $script:startTime).TotalSeconds, 1)
47+
Write-Host "[${scriptName}] ${Message}. Total elapsed time: $elapsedTime seconds."
48+
Write-Host ""
49+
}
50+
3551
function Get-GitHubApiHeaders {
3652
param(
3753
[Parameter(Mandatory = $false)]
@@ -265,6 +281,8 @@ else {
265281
}
266282
}
267283

284+
Write-ElapsedTime "Spec retrieved"
285+
268286
Push-Location $repoRootPath
269287

270288
try {
@@ -273,10 +291,13 @@ try {
273291
exit $LASTEXITCODE
274292
}
275293

294+
Write-ElapsedTime "npm ci complete"
295+
276296
Invoke-ScriptWithLogging { npm run build -w $codegenFolderPath }
277297
if ($LASTEXITCODE -ne 0) {
278298
exit $LASTEXITCODE
279299
}
300+
Write-ElapsedTime "npm run build complete"
280301

281302
Set-Location $specificationFolderPath
282303
Invoke-ScriptWithLogging { npx tsp compile . --stats --trace @typespec/http-client-csharp }
@@ -285,9 +306,4 @@ finally {
285306
Pop-Location
286307
}
287308

288-
$scriptElapsed = $(Get-Date) - $scriptStartTime
289-
$scriptElapsedSeconds = [math]::Round($scriptElapsed.TotalSeconds, 1)
290-
$scriptName = $MyInvocation.MyCommand.Name
291-
292-
Write-Host "${scriptName} completed. Time: ${scriptElapsedSeconds}s"
293-
Write-Host ""
309+
Write-ElapsedTime "Script completed"

0 commit comments

Comments
 (0)