Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update parse log to handle Read/WrteMessageAsync #943

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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