From 8d98ecac3b44078524efe8f9ba048dfb789b0ec5 Mon Sep 17 00:00:00 2001 From: KevinMarquette Date: Sun, 5 Feb 2017 00:58:49 -0800 Subject: [PATCH] Added help comments to Format command --- Chronometer/Private/Write-ScriptLine.ps1 | 29 +++++++++++++ Chronometer/Public/Format-Chronometer.ps1 | 50 ++++++++++++++++++++++ Chronometer/chronometer.psd1 | Bin 4294 -> 4342 bytes ScratchFiles/example.ps1 | 5 ++- 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 Chronometer/Private/Write-ScriptLine.ps1 create mode 100644 Chronometer/Public/Format-Chronometer.ps1 diff --git a/Chronometer/Private/Write-ScriptLine.ps1 b/Chronometer/Private/Write-ScriptLine.ps1 new file mode 100644 index 0000000..217728c --- /dev/null +++ b/Chronometer/Private/Write-ScriptLine.ps1 @@ -0,0 +1,29 @@ + +function Write-ScriptLine +{ + param( + [scriptline] + $line, + $WarningAt = [int]::MaxValue, + $ErrorAt = [int]::MaxValue + ) + + if($line) + { + $Color = 'Green' + if($line.HitCount -eq 0) + { + $Color = 'Gray' + } + elseif($line.Average -ge $ErrorAt) + { + $Color = 'Red' + } + elseif($line.Average -ge $WarningAt) + { + $Color = 'Yellow' + } + + Write-Host $line.toString() -ForegroundColor $Color + } +} \ No newline at end of file diff --git a/Chronometer/Public/Format-Chronometer.ps1 b/Chronometer/Public/Format-Chronometer.ps1 new file mode 100644 index 0000000..f12be7e --- /dev/null +++ b/Chronometer/Public/Format-Chronometer.ps1 @@ -0,0 +1,50 @@ +function Format-Chronometer +{ + <# + .Description + Generates a report from a Chronometer + + .Example + $script = ls C:\workspace\PSGraph\PSGraph -Recurse -Filter *.ps1 + $resultes = Get-Chronometer -Path $script.fullname -ScriptBlock {Invoke-Pester C:\workspace\PSGraph} + $results | Format-Chronometer -WarnAt 20 -ErrorAt 200 + #> + [cmdletbinding()] + param( + # This is a MonitoredScript object from Get-Chronometer + [Parameter( + ValueFromPipeline=$true + )] + [MonitoredScript[]] + $InputObject, + + # If the average time of a command is more than this, the output is yellow + [int] + $WarningAt = 20, + + #If the average time of a comamand is more than this, the output is red + [int] + $ErrorAt = 200 + ) + + begin { + $green = @{ForgroundColor='green'} + $grey = @{ForgroundColor='grey'} + $yellow = @{ForgroundColor='grey'} + $yellow = @{ForgroundColor='grey'} + $yellow = @{ForgroundColor='grey'} + } + process + { + foreach($script in $InputObject) + { + Write-Host '' + Write-Host "Script: $($script.Path)" -ForegroundColor Green + Write-Host "Execution Time: $($script.ExecutionTime)" -ForegroundColor Green + foreach($line in $script.line) + { + Write-ScriptLine $line -WarningAt $WarningAt -ErrorAt $ErrorAt + } + } + } +} diff --git a/Chronometer/chronometer.psd1 b/Chronometer/chronometer.psd1 index 73e6e5c7cb7bfff09f4920bf33ab5c02e2c4ed25..066b559315876a25acd09ca1c2bc4bcb8fcf6027 100644 GIT binary patch delta 53 zcmX@6_)T$x0u!UrW<{n#R%QnVjmZ<)l?8Pe)EV3u@)?R4av2gCN*Ht}zvmNYR%g)M JyqR5?698!i42A#z delta 27 jcmeyScuaAF0u!U*W<{n#*2&Y@l_tjtaBP0V&cz7;fKCWw diff --git a/ScratchFiles/example.ps1 b/ScratchFiles/example.ps1 index fab56a3..47b3502 100644 --- a/ScratchFiles/example.ps1 +++ b/ScratchFiles/example.ps1 @@ -10,7 +10,8 @@ foreach($n in 1..10) "test string" sleep -Milliseconds 3 } + sleep -Milliseconds 12 -sleep -Milliseconds 5 +sleep -Milliseconds 120 +$test = 1+1 $test = 1+1 -$test = 1+1 \ No newline at end of file