|
| 1 | +function Get-PsesRpcNotificationMessage { |
| 2 | + [CmdletBinding(DefaultParameterSetName = "PsesLogEntry")] |
| 3 | + param( |
| 4 | + # Specifies a path to one or more PSES EditorServices log files. |
| 5 | + [Parameter(Mandatory = $true, Position = 0, ParameterSetName = "Path")] |
| 6 | + [Alias("PSPath")] |
| 7 | + [ValidateNotNullOrEmpty()] |
| 8 | + [string] |
| 9 | + $Path, |
| 10 | + |
| 11 | + # Specifies PsesLogEntry objects to analyze. |
| 12 | + [Parameter(Mandatory = $true, Position = 0, ParameterSetName = "PsesLogEntry", ValueFromPipeline = $true)] |
| 13 | + [ValidateNotNull()] |
| 14 | + [psobject[]] |
| 15 | + $LogEntry, |
| 16 | + |
| 17 | + # Specifies a filter for either client or server sourced notifications. By default both are output. |
| 18 | + [Parameter()] |
| 19 | + [ValidateSet('Client', 'Server')] |
| 20 | + [string] |
| 21 | + $Source |
| 22 | + ) |
| 23 | + |
| 24 | + begin { |
| 25 | + if ($PSCmdlet.ParameterSetName -eq "Path") { |
| 26 | + $logEntries = Parse-PsesLog $Path |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + process { |
| 31 | + if ($PSCmdlet.ParameterSetName -eq "PsesLogEntry") { |
| 32 | + $logEntries = $LogEntry |
| 33 | + } |
| 34 | + |
| 35 | + foreach ($entry in $logEntries) { |
| 36 | + if ($entry.LogMessageType -eq 'Notification') { |
| 37 | + if (!$Source -or ($entry.Message.Source -eq $Source)) { |
| 38 | + $entry |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +function Get-PsesRpcMessageResponseTime { |
| 46 | + [CmdletBinding(DefaultParameterSetName = "PsesLogEntry")] |
| 47 | + param( |
| 48 | + # Specifies a path to one or more PSES EditorServices log files. |
| 49 | + [Parameter(Mandatory=$true, Position=0, ParameterSetName="Path")] |
| 50 | + [Alias("PSPath")] |
| 51 | + [ValidateNotNullOrEmpty()] |
| 52 | + [string] |
| 53 | + $Path, |
| 54 | + |
| 55 | + # Specifies PsesLogEntry objects to analyze. |
| 56 | + [Parameter(Mandatory=$true, Position=0, ParameterSetName="PsesLogEntry", ValueFromPipeline=$true)] |
| 57 | + [ValidateNotNull()] |
| 58 | + [psobject[]] |
| 59 | + $LogEntry |
| 60 | + ) |
| 61 | + |
| 62 | + begin { |
| 63 | + if ($PSCmdlet.ParameterSetName -eq "Path") { |
| 64 | + $logEntries = Parse-PsesLog $Path |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + process { |
| 69 | + if ($PSCmdlet.ParameterSetName -eq "PsesLogEntry") { |
| 70 | + $logEntries += $LogEntry |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + end { |
| 75 | + # Populate $requests hashtable with request timestamps |
| 76 | + $requests = @{} |
| 77 | + $logEntries | |
| 78 | + Where-Object LogMessageType -match Request | |
| 79 | + Foreach-Object { $requests[$_.Message.Id] = $_.Timestamp } |
| 80 | + |
| 81 | + $res = $logEntries | |
| 82 | + Where-Object LogMessageType -match Response | |
| 83 | + Foreach-Object { |
| 84 | + $elapsedMilliseconds = [int]($_.Timestamp - $requests[$_.Message.Id]).TotalMilliseconds |
| 85 | + [PsesLogEntryElapsed]::new($_, $elapsedMilliseconds) |
| 86 | + } |
| 87 | + |
| 88 | + $res |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +function Get-PsesScriptAnalysisCompletionTime { |
| 93 | + [CmdletBinding(DefaultParameterSetName = "PsesLogEntry")] |
| 94 | + param( |
| 95 | + # Specifies a path to one or more PSES EditorServices log files. |
| 96 | + [Parameter(Mandatory = $true, Position = 0, ParameterSetName = "Path")] |
| 97 | + [Alias("PSPath")] |
| 98 | + [ValidateNotNullOrEmpty()] |
| 99 | + [string] |
| 100 | + $Path, |
| 101 | + |
| 102 | + # Specifies PsesLogEntry objects to analyze. |
| 103 | + [Parameter(Mandatory = $true, Position = 0, ParameterSetName = "PsesLogEntry", ValueFromPipeline = $true)] |
| 104 | + [ValidateNotNull()] |
| 105 | + [psobject[]] |
| 106 | + $LogEntry |
| 107 | + ) |
| 108 | + |
| 109 | + begin { |
| 110 | + if ($PSCmdlet.ParameterSetName -eq "Path") { |
| 111 | + $logEntries = Parse-PsesLog $Path |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + process { |
| 116 | + if ($PSCmdlet.ParameterSetName -eq "PsesLogEntry") { |
| 117 | + $logEntries = $LogEntry |
| 118 | + } |
| 119 | + |
| 120 | + foreach ($entry in $logEntries) { |
| 121 | + if (($entry.LogMessageType -eq 'Log') -and ($entry.Message.Data -match '^\s*Script analysis of.*\[(?<ms>\d+)ms\]\s*$')) { |
| 122 | + $elapsedMilliseconds = [int]$matches["ms"] |
| 123 | + [PsesLogEntryElapsed]::new($entry, $elapsedMilliseconds) |
| 124 | + } |
| 125 | + } |
| 126 | + } |
| 127 | +} |
| 128 | + |
| 129 | +function Get-PsesIntelliSenseCompletionTime { |
| 130 | + [CmdletBinding(DefaultParameterSetName = "PsesLogEntry")] |
| 131 | + param( |
| 132 | + # Specifies a path to one or more PSES EditorServices log files. |
| 133 | + [Parameter(Mandatory = $true, Position = 0, ParameterSetName = "Path")] |
| 134 | + [Alias("PSPath")] |
| 135 | + [ValidateNotNullOrEmpty()] |
| 136 | + [string] |
| 137 | + $Path, |
| 138 | + |
| 139 | + # Specifies PsesLogEntry objects to analyze. |
| 140 | + [Parameter(Mandatory = $true, Position = 0, ParameterSetName = "PsesLogEntry", ValueFromPipeline = $true)] |
| 141 | + [ValidateNotNull()] |
| 142 | + [psobject[]] |
| 143 | + $LogEntry |
| 144 | + ) |
| 145 | + |
| 146 | + begin { |
| 147 | + if ($PSCmdlet.ParameterSetName -eq "Path") { |
| 148 | + $logEntries = Parse-PsesLog $Path |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + process { |
| 153 | + if ($PSCmdlet.ParameterSetName -eq "PsesLogEntry") { |
| 154 | + $logEntries = $LogEntry |
| 155 | + } |
| 156 | + |
| 157 | + foreach ($entry in $logEntries) { |
| 158 | + # IntelliSense completed in 320ms. |
| 159 | + if (($entry.LogMessageType -eq 'Log') -and ($entry.Message.Data -match '^\s*IntelliSense completed in\s+(?<ms>\d+)ms.\s*$')) { |
| 160 | + $elapsedMilliseconds = [int]$matches["ms"] |
| 161 | + [PsesLogEntryElapsed]::new($entry, $elapsedMilliseconds) |
| 162 | + } |
| 163 | + } |
| 164 | + } |
| 165 | +} |
| 166 | + |
| 167 | +function Get-PsesMessage { |
| 168 | + [CmdletBinding(DefaultParameterSetName = "PsesLogEntry")] |
| 169 | + param( |
| 170 | + # Specifies a path to one or more PSES EditorServices log files. |
| 171 | + [Parameter(Mandatory = $true, Position = 0, ParameterSetName = "Path")] |
| 172 | + [Alias("PSPath")] |
| 173 | + [ValidateNotNullOrEmpty()] |
| 174 | + [string] |
| 175 | + $Path, |
| 176 | + |
| 177 | + # Specifies PsesLogEntry objects to analyze. |
| 178 | + [Parameter(Mandatory = $true, Position = 0, ParameterSetName = "PsesLogEntry", ValueFromPipeline = $true)] |
| 179 | + [ValidateNotNull()] |
| 180 | + [psobject[]] |
| 181 | + $LogEntry, |
| 182 | + |
| 183 | + # Specifies the log level entries to return. Default returns Normal and above. |
| 184 | + # Use StrictMatch to return only the specified log level entries. |
| 185 | + [Parameter()] |
| 186 | + [PsesLogLevel] |
| 187 | + $LogLevel = $([PsesLogLevel]::Normal), |
| 188 | + |
| 189 | + # Use StrictMatch to return only the specified log level entries. |
| 190 | + [Parameter()] |
| 191 | + [switch] |
| 192 | + $StrictMatch |
| 193 | + ) |
| 194 | + |
| 195 | + begin { |
| 196 | + if ($PSCmdlet.ParameterSetName -eq "Path") { |
| 197 | + $logEntries = Parse-PsesLog $Path |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + process { |
| 202 | + if ($PSCmdlet.ParameterSetName -eq "PsesLogEntry") { |
| 203 | + $logEntries = $LogEntry |
| 204 | + } |
| 205 | + |
| 206 | + foreach ($entry in $logEntries) { |
| 207 | + if (($StrictMatch -and ($entry.LogLevel -eq $LogLevel)) -or |
| 208 | + (!$StrictMatch -and ($entry.LogLevel -ge $LogLevel))) { |
| 209 | + $entry |
| 210 | + } |
| 211 | + } |
| 212 | + } |
| 213 | +} |
0 commit comments