Everything is stable again. Some refactoring work is still in progress !deploy
This commit is contained in:
@@ -35,9 +35,15 @@ class Chronometer
|
|||||||
$script = $Execution.Breakpoint.Script
|
$script = $Execution.Breakpoint.Script
|
||||||
if($this.FileMap.ContainsKey($script))
|
if($this.FileMap.ContainsKey($script))
|
||||||
{
|
{
|
||||||
|
# Each script tracks it's own execution times
|
||||||
$this.FileMap[$script].AddExecution($Execution)
|
$this.FileMap[$script].AddExecution($Execution)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MonitoredScript[]] GetResults()
|
||||||
|
{
|
||||||
|
return $this.FileMap.Values
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MonitoredScript
|
class MonitoredScript
|
||||||
@@ -45,8 +51,8 @@ class MonitoredScript
|
|||||||
[string]$Path
|
[string]$Path
|
||||||
[System.Collections.ArrayList]$Line
|
[System.Collections.ArrayList]$Line
|
||||||
|
|
||||||
$lastNode = $null
|
hidden $lastNode = $null
|
||||||
$lastRecord = $null
|
hidden $lastRecord = $null
|
||||||
|
|
||||||
MonitoredScript()
|
MonitoredScript()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,23 +22,29 @@ function Get-Chronometer
|
|||||||
)
|
)
|
||||||
|
|
||||||
$Chronometer = [Chronometer]::New()
|
$Chronometer = [Chronometer]::New()
|
||||||
$breakPoint = $Chronometer.AddBreakpoint($Path)
|
|
||||||
|
|
||||||
[ScriptProfiler]::Start()
|
Write-Verbose "Setting breapoints"
|
||||||
[void] $ScriptBlock.Invoke()
|
$Chronometer.AddBreakpoint($Path)
|
||||||
|
|
||||||
$Chronometer.ClearBreakpoint()
|
if($Chronometer.breakPoint -ne $null)
|
||||||
|
|
||||||
foreach($node in [ScriptProfiler]::Queue.GetEnumerator())
|
|
||||||
{
|
{
|
||||||
$Chronometer.AddExecution($node)
|
Write-Verbose "Executing Script"
|
||||||
}
|
[ScriptProfiler]::Start()
|
||||||
|
[void] $ScriptBlock.Invoke()
|
||||||
|
|
||||||
foreach($script in $fileMap.Keys)
|
Write-Verbose "Clearing Breapoints"
|
||||||
{
|
$Chronometer.ClearBreakpoint()
|
||||||
foreach($line in $fileMap[$script])
|
|
||||||
|
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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ Provide a script file and a command to execute.
|
|||||||
|
|
||||||
$path = myscript.ps1
|
$path = myscript.ps1
|
||||||
Get-Chronometer -Path $path -Script {. .\myscript.ps1} -OutVariable report
|
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.
|
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
|
## Things to know
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ $moduleRoot = Split-Path (Resolve-Path "$projectRoot\*\*.psd1")
|
|||||||
$moduleName = Split-Path $moduleRoot -Leaf
|
$moduleName = Split-Path $moduleRoot -Leaf
|
||||||
|
|
||||||
Describe "Basic unit tests" -Tags Build {
|
Describe "Basic unit tests" -Tags Build {
|
||||||
|
|
||||||
Import-Module (Join-Path $moduleRoot "$moduleName.psm1") -force
|
Import-Module (Join-Path $moduleRoot "$moduleName.psm1") -force
|
||||||
|
|
||||||
Context "Function: Get-Chronometer" {
|
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 ScratchFiles\example.ps1 -Script {"Test"}
|
||||||
{Get-Chronometer -Path $PSScriptRoot\..\ScratchFiles\example.ps1 -Script {"Test"} } | Should Not Throw
|
{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 {
|
InModuleScope $moduleName {
|
||||||
|
|||||||
Reference in New Issue
Block a user