reworked some files skip ci
This commit is contained in:
@@ -46,45 +46,3 @@ class Chronometer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MonitoredScript
|
|
||||||
{
|
|
||||||
[string]$Path
|
|
||||||
[System.Collections.ArrayList]$Line
|
|
||||||
|
|
||||||
hidden $lastNode = $null
|
|
||||||
hidden $lastRecord = $null
|
|
||||||
|
|
||||||
MonitoredScript()
|
|
||||||
{
|
|
||||||
$this.Line = [System.Collections.ArrayList]::New()
|
|
||||||
}
|
|
||||||
|
|
||||||
[int] SetScript([string]$Path)
|
|
||||||
{
|
|
||||||
Get-Content -Path $Path | %{ $this.Line.Add( [ScriptLine]@{text=$_})}
|
|
||||||
return $this.Line.Count
|
|
||||||
}
|
|
||||||
|
|
||||||
[void] AddExecution([hashtable]$node)
|
|
||||||
{
|
|
||||||
$record = $this.Line[$node.Breakpoint.Line-1]
|
|
||||||
$record.LineNumber = $node.Breakpoint.Line - 1
|
|
||||||
|
|
||||||
if($this.lastNode)
|
|
||||||
{
|
|
||||||
$duration = $node.ElapsedMilliseconds - $this.lastNode.ElapsedMilliseconds
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$duration = $node.ElapsedMilliseconds
|
|
||||||
}
|
|
||||||
|
|
||||||
if($this.lastRecord)
|
|
||||||
{
|
|
||||||
$this.lastRecord.AddExecutionTime($duration)
|
|
||||||
}
|
|
||||||
|
|
||||||
$this.lastRecord = $record
|
|
||||||
$this.lastNode = $node
|
|
||||||
}
|
|
||||||
}
|
|
||||||
49
Chronometer/Classes/MonitoredScript.ps1
Normal file
49
Chronometer/Classes/MonitoredScript.ps1
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
class MonitoredScript
|
||||||
|
{
|
||||||
|
[string]$Path
|
||||||
|
[System.Collections.Generic.List[ScriptLine]]$Line
|
||||||
|
|
||||||
|
hidden $lastNode = $null
|
||||||
|
hidden $lastRecord = $null
|
||||||
|
|
||||||
|
[float]$ExecutionTime = 0
|
||||||
|
[int]$LinesOfCode = 0
|
||||||
|
|
||||||
|
MonitoredScript()
|
||||||
|
{
|
||||||
|
$this.Line =New-Object 'System.Collections.Generic.List[ScriptLine]'
|
||||||
|
}
|
||||||
|
|
||||||
|
[int] SetScript([string]$Path)
|
||||||
|
{
|
||||||
|
Get-Content -Path $Path | %{ $this.Line.Add( [ScriptLine]@{text=$_;path=$path})}
|
||||||
|
$this.LinesOfCode = $this.Line.Count
|
||||||
|
return $this.LinesOfCode
|
||||||
|
}
|
||||||
|
|
||||||
|
[void] AddExecution([hashtable]$node)
|
||||||
|
{
|
||||||
|
# Line numbers start at 1 but the array starts at 0
|
||||||
|
$lineNumber = $node.Breakpoint.Line - 1
|
||||||
|
$record = $this.Line[$lineNumber]
|
||||||
|
$record.LineNumber = $lineNumber
|
||||||
|
|
||||||
|
if($this.lastNode)
|
||||||
|
{
|
||||||
|
$duration = $node.ElapsedMilliseconds - $this.lastNode.ElapsedMilliseconds
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$duration = $node.ElapsedMilliseconds
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this.lastRecord)
|
||||||
|
{
|
||||||
|
$this.lastRecord.AddExecutionTime($duration)
|
||||||
|
$this.ExecutionTime += $duration
|
||||||
|
}
|
||||||
|
|
||||||
|
$this.lastRecord = $record
|
||||||
|
$this.lastNode = $node
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ Write-Verbose 'Import Classes in order because of dependencies'
|
|||||||
$classList = @(
|
$classList = @(
|
||||||
'ScriptLine',
|
'ScriptLine',
|
||||||
'ScriptProfiler',
|
'ScriptProfiler',
|
||||||
|
'MonitoredScript',
|
||||||
'Chronometer'
|
'Chronometer'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -42,5 +42,13 @@ Describe "Basic unit tests" -Tags Build {
|
|||||||
{[ScriptProfiler]::Start()} | Should Not Throw
|
{[ScriptProfiler]::Start()} | Should Not Throw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Context "Class: MonitoredScript" {
|
||||||
|
{[MonitoredScript]::New()} | Should Not Throw
|
||||||
|
}
|
||||||
|
|
||||||
|
Context "Class: MonitoredScript" {
|
||||||
|
{[MonitoredScript]::SetScript("$projectRoot\scratchfiles\example.ps1")} | Should Not Throw
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user