Skip to content

Commit

Permalink
Update parse log to handle Read/WrteMessageAsyncAdd progress percenta…
Browse files Browse the repository at this point in the history
…ge to parse command.Add textDocument/completion to ValidaeSet of MesssageNameparam on Get-PsesRpcMessageResponseTime command. (#943)
  • Loading branch information
rkeithhill authored Apr 19, 2019
1 parent 0ba7868 commit 6ea39f3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions tools/PsesLogAnalyzer/Analyze.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function Get-PsesRpcMessageResponseTime {
[ValidateSet(
"textDocument/codeAction",
"textDocument/codeLens",
"textDocument/completion",
"textDocument/documentSymbol",
"textDocument/foldingRange",
"textDocument/formatting",
Expand Down
31 changes: 25 additions & 6 deletions tools/PsesLogAnalyzer/Parse-PsesLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,25 @@ function Parse-PsesLog {
[System.IO.FileShare]::ReadWrite,
4096,
[System.IO.FileOptions]::SequentialScan)
$streamReader = [System.IO.StreamReader]::new($filestream, [System.Text.Encoding]::UTF8)

# Count number of lines so we can provide % progress while parsing
$numLines = 0
while ($null -ne $streamReader.ReadLine()) {
$numLines++
}

# Recreate the stream & reader. Tried seeking to 0 on the stream and having the
# reader discard buffered data but still wound up with in an invalid $log[0] entry.
$streamReader.Dispose()
$filestream =
[System.IO.FileStream]::new(
$Path,
[System.IO.FileMode]:: Open,
[System.IO.FileAccess]::Read,
[System.IO.FileShare]::ReadWrite,
4096,
[System.IO.FileOptions]::SequentialScan)
$streamReader = [System.IO.StreamReader]::new($filestream, [System.Text.Encoding]::UTF8)

function nextLine() {
Expand Down Expand Up @@ -105,8 +123,9 @@ function Parse-PsesLog {
$line = nextLine
}

if (!$HideProgress -and ($script:logEntryIndex % 50 -eq 0)) {
Write-Progress "Processing log entry ${script:logEntryIndex} on line: ${script:currentLineNum}"
if (!$HideProgress -and ($script:logEntryIndex % 100 -eq 0)) {
Write-Progress "Processing log entry ${script:logEntryIndex} on line: ${script:currentLineNum}" `
-PercentComplete (100 * $script:currentLineNum / $numLines)
}

[string]$timestampStr = $matches["ts"]
Expand Down Expand Up @@ -144,30 +163,30 @@ function Parse-PsesLog {
return $result
}

if (($Method -eq 'ReadMessage') -and
if (($Method -eq 'ReadMessageAsync' -or $Method -eq 'ReadMessage') -and
($line -match '^\s+Received Request ''(?<msg>[^'']+)'' with id (?<id>\d+)')) {
$result.LogMessageType = [PsesLogMessageType]::Request
$msg = $matches["msg"]
$id = $matches["id"]
$json = parseLogMessageBodyAsJson
$result.LogMessage = [PsesJsonRpcMessage]::new($msg, $id, $json.Data, $json.DataSize)
}
elseif (($Method -eq 'ReadMessage') -and
elseif (($Method -eq 'ReadMessageAsync' -or $Method -eq 'ReadMessage') -and
($line -match '^\s+Received event ''(?<msg>[^'']+)''')) {
$result.LogMessageType = [PsesLogMessageType]::Notification
$msg = $matches["msg"]
$json = parseLogMessageBodyAsJson
$result.LogMessage = [PsesNotificationMessage]::new($msg, [PsesNotificationSource]::Client, $json.Data, $json.DataSize)
}
elseif (($Method -eq 'WriteMessage') -and
elseif (($Method -eq 'WriteMessageAsync' -or $Method -eq 'WriteMessage') -and
($line -match '^\s+Writing Response ''(?<msg>[^'']+)'' with id (?<id>\d+)')) {
$result.LogMessageType = [PsesLogMessageType]::Response
$msg = $matches["msg"]
$id = $matches["id"]
$json = parseLogMessageBodyAsJson
$result.LogMessage = [PsesJsonRpcMessage]::new($msg, $id, $json.Data, $json.DataSize)
}
elseif (($Method -eq 'WriteMessage') -and
elseif (($Method -eq 'WriteMessageAsync' -or $Method -eq 'WriteMessage') -and
($line -match '^\s+Writing event ''(?<msg>[^'']+)''')) {
$result.LogMessageType = [PsesLogMessageType]::Notification
$msg = $matches["msg"]
Expand Down

0 comments on commit 6ea39f3

Please sign in to comment.