Added linenumber support to measure just a section of a script or file.
This commit is contained in:
@@ -3,18 +3,26 @@ class Chronometer
|
||||
[hashtable]$FileMap = @{}
|
||||
$Breakpoint = @()
|
||||
|
||||
[void]AddBreakpoint([string[]]$Path)
|
||||
[void]AddBreakpoint([string[]]$Path, [int[]]$LineNumber)
|
||||
{
|
||||
foreach($file in (Resolve-Path $Path -ea 0))
|
||||
{
|
||||
$script = [MonitoredScript]@{Path=$file.Path}
|
||||
$lines = $script.SetScript($file)
|
||||
if($LineNumber -ne $null)
|
||||
{
|
||||
$bpLine = $LineNumber
|
||||
}
|
||||
else
|
||||
{
|
||||
$bpLine = (1..$lines)
|
||||
}
|
||||
|
||||
$this.fileMap[$file.Path] = $script
|
||||
|
||||
$breakpointParam = @{
|
||||
Script = $file
|
||||
Line = (1..$lines)
|
||||
Line = $bpLine
|
||||
Action = {[ScriptProfiler]::RecordExecution( $_) }
|
||||
}
|
||||
$this.breakPoint += Set-PSBreakpoint @breakpointParam
|
||||
|
||||
@@ -15,6 +15,10 @@ function Get-Chronometer
|
||||
[string[]]
|
||||
$Path,
|
||||
|
||||
# Line numbers within the script file to measure
|
||||
[int[]]
|
||||
$LineNumber = $null,
|
||||
|
||||
# The script to start the scrupt or execute other commands
|
||||
[alias('Script','CommandScript')]
|
||||
[scriptblock]
|
||||
@@ -24,7 +28,7 @@ function Get-Chronometer
|
||||
$Chronometer = [Chronometer]::New()
|
||||
|
||||
Write-Verbose "Setting breapoints"
|
||||
$Chronometer.AddBreakpoint($Path)
|
||||
$Chronometer.AddBreakpoint($Path,$LineNumber)
|
||||
|
||||
if($Chronometer.breakPoint -ne $null)
|
||||
{
|
||||
|
||||
@@ -17,6 +17,17 @@ Describe "Basic unit tests" -Tags Build {
|
||||
$results = Get-Chronometer -Path $PSScriptRoot\..\ScratchFiles\example.ps1 -Script {. "$PSScriptRoot\..\ScratchFiles\example.ps1"}
|
||||
$results | Should Not BeNullOrEmpty
|
||||
}
|
||||
|
||||
it "Executes a script with linenumbers and gives results" {
|
||||
# Get-Chronometer -Path ScratchFiles\example.ps1 -Script {"Test"}
|
||||
$params = @{
|
||||
Path = "$PSScriptRoot\..\ScratchFiles\example.ps1"
|
||||
Script = {. "$PSScriptRoot\..\ScratchFiles\example.ps1"}
|
||||
LineNumber = 2,3,5,6
|
||||
}
|
||||
$results = Get-Chronometer @params
|
||||
$results | Should Not BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
|
||||
Context "Function: Format-Chronometer" {
|
||||
|
||||
Reference in New Issue
Block a user