58 lines
1.9 KiB
PowerShell
58 lines
1.9 KiB
PowerShell
function Trace-ActionStart {
|
|
<#
|
|
.SYNOPSIS
|
|
End tracing the action. This is useful for gathering duration of runtime.
|
|
|
|
.PARAMETER ParentTraceAction
|
|
Passed in TraceAction from prior method
|
|
|
|
.PARAMETER ActionName
|
|
Name of the specific action being traced
|
|
#>
|
|
param (
|
|
[Parameter(Mandatory = $false)]
|
|
$ParentTraceAction = $null,
|
|
[Parameter(Mandatory = $false)]
|
|
[string]$ActionName = "Method Invocation"
|
|
)
|
|
|
|
process {
|
|
$callstack = Get-PSCallstack
|
|
$currentMethod = $callstack[0]
|
|
$parentMethod = $callstack[1]
|
|
|
|
$currentMethodName = $currentMethod.FunctionName
|
|
$parentMethodName = $parentMethod.FunctionName
|
|
|
|
$currentMethodSource = ""
|
|
$parentMethodSource = ""
|
|
|
|
if (-not (Test-StringIsNullOrWhitespace -Value $currentMethod.ScriptName)) {
|
|
$currentMethodSource = [System.IO.Path]::GetFileNameWithoutExtension($currentMethod.ScriptName)
|
|
}
|
|
|
|
if (-not (Test-StringIsNullOrWhitespace -Value $parentMethod.ScriptName)) {
|
|
$parentMethodSource = [System.IO.Path]::GetFileNameWithoutExtension($parentMethod.ScriptName)
|
|
}
|
|
|
|
$traceAction = New-Object PSCustomObject -Property @{
|
|
StartTime = [System.DateTime]::Now
|
|
EndTime = $null
|
|
StopWatch = [System.Diagnostics.Stopwatch]::StartNew()
|
|
Duration = $null
|
|
Command = $currentMethodName
|
|
ModuleName = $currentMethodSource
|
|
CalledBy = @{
|
|
Command = $parentMethodName
|
|
ModuleName = $parentMethodSource
|
|
# Arguments = $parentMethod.InvocationInfo.BoundParameters
|
|
}
|
|
ActionName = $ActionName
|
|
# ParentTraceAction = $ParentTraceAction
|
|
# Arguments = $currentMethod.InvocationInfo.BoundParameters
|
|
}
|
|
|
|
return $traceAction
|
|
}
|
|
}
|