From 1b836300015303cffdd9383117c9d4ff466e46c9 Mon Sep 17 00:00:00 2001 From: KevinMarquette Date: Sat, 4 Feb 2017 23:18:43 -0800 Subject: [PATCH] Everything is stable again. Some refactoring work is still in progress !deploy --- Chronometer/Classes/Chronometer.ps1 | 10 +++++++-- Chronometer/Public/Get-Chronometer.ps1 | 30 +++++++++++++++----------- README.md | 3 ++- Tests/Unit.Tests.ps1 | 8 ++++++- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Chronometer/Classes/Chronometer.ps1 b/Chronometer/Classes/Chronometer.ps1 index 94ad8ed..159ffe2 100644 --- a/Chronometer/Classes/Chronometer.ps1 +++ b/Chronometer/Classes/Chronometer.ps1 @@ -35,9 +35,15 @@ class Chronometer $script = $Execution.Breakpoint.Script if($this.FileMap.ContainsKey($script)) { + # Each script tracks it's own execution times $this.FileMap[$script].AddExecution($Execution) } } + + [MonitoredScript[]] GetResults() + { + return $this.FileMap.Values + } } class MonitoredScript @@ -45,8 +51,8 @@ class MonitoredScript [string]$Path [System.Collections.ArrayList]$Line - $lastNode = $null - $lastRecord = $null + hidden $lastNode = $null + hidden $lastRecord = $null MonitoredScript() { diff --git a/Chronometer/Public/Get-Chronometer.ps1 b/Chronometer/Public/Get-Chronometer.ps1 index b5bcadb..bc95fa2 100644 --- a/Chronometer/Public/Get-Chronometer.ps1 +++ b/Chronometer/Public/Get-Chronometer.ps1 @@ -22,23 +22,29 @@ function Get-Chronometer ) $Chronometer = [Chronometer]::New() - $breakPoint = $Chronometer.AddBreakpoint($Path) - [ScriptProfiler]::Start() - [void] $ScriptBlock.Invoke() + Write-Verbose "Setting breapoints" + $Chronometer.AddBreakpoint($Path) - $Chronometer.ClearBreakpoint() - - foreach($node in [ScriptProfiler]::Queue.GetEnumerator()) + if($Chronometer.breakPoint -ne $null) { - $Chronometer.AddExecution($node) - } + Write-Verbose "Executing Script" + [ScriptProfiler]::Start() + [void] $ScriptBlock.Invoke() - foreach($script in $fileMap.Keys) - { - foreach($line in $fileMap[$script]) + Write-Verbose "Clearing Breapoints" + $Chronometer.ClearBreakpoint() + + Write-Verbose "Processing data" + foreach($node in [ScriptProfiler]::Queue.GetEnumerator()) { - Write-Output $line + $Chronometer.AddExecution($node) } + + Write-Output $Chronometer.GetResults() + } + else + { + Write-Warning "Parsing files did not result in any breakpoints" } } diff --git a/README.md b/README.md index c18dda7..5360d69 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ Provide a script file and a command to execute. $path = myscript.ps1 Get-Chronometer -Path $path -Script {. .\myscript.ps1} -OutVariable report - $report.ToString() + $report.line | % tostring + The user experience is important to me but I am working on the core logic right now. I will loop back to make it more intuitive and simple to use. ## Things to know diff --git a/Tests/Unit.Tests.ps1 b/Tests/Unit.Tests.ps1 index ecb61cc..81d9a4f 100644 --- a/Tests/Unit.Tests.ps1 +++ b/Tests/Unit.Tests.ps1 @@ -3,7 +3,7 @@ $moduleRoot = Split-Path (Resolve-Path "$projectRoot\*\*.psd1") $moduleName = Split-Path $moduleRoot -Leaf Describe "Basic unit tests" -Tags Build { - + Import-Module (Join-Path $moduleRoot "$moduleName.psm1") -force Context "Function: Get-Chronometer" { @@ -11,6 +11,12 @@ Describe "Basic unit tests" -Tags Build { # Get-Chronometer -Path ScratchFiles\example.ps1 -Script {"Test"} {Get-Chronometer -Path $PSScriptRoot\..\ScratchFiles\example.ps1 -Script {"Test"} } | Should Not Throw } + + it "Executes a script and gives results" { + # Get-Chronometer -Path ScratchFiles\example.ps1 -Script {"Test"} + $results = Get-Chronometer -Path $PSScriptRoot\..\ScratchFiles\example.ps1 -Script {. "$PSScriptRoot\..\ScratchFiles\example.ps1"} + $results | Should Not BeNullOrEmpty + } } InModuleScope $moduleName {