Skip to content

Commit

Permalink
Address PR feedback, adjust string builder size based on log file data
Browse files Browse the repository at this point in the history
  • Loading branch information
rkeithhill committed Nov 30, 2018
1 parent ef04cd6 commit e35b7d2
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ public async Task<Message> ReadMessage()
Message parsedMessage = this.messageSerializer.DeserializeMessage(messageObject);

// Log message info - initial capacity for StringBuilder varies depending on whether
// the log level is Diagnostic where JsonRpc message payloads are logged and
// vary from 1K up edited file size chars. When not logging message payloads the
// typical request log message is under 250 chars.
// the log level is Diagnostic where JsonRpc message payloads are logged and vary in size
// from 1K up to the edited file size. When not logging message payloads, the typical
// request log message size is under 256 chars.
var logStrBld =
new StringBuilder(this.logger.MinimumConfiguredLogLevel == LogLevel.Diagnostic ? 4096 : 250)
new StringBuilder(this.logger.MinimumConfiguredLogLevel == LogLevel.Diagnostic ? 4096 : 256)
.Append("Received ")
.Append(parsedMessage.MessageType)
.Append(" '").Append(parsedMessage.Method).Append("'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public async Task WriteMessage(Message messageToWrite)
messageToWrite);

// Log message info - initial capacity for StringBuilder varies depending on whether
// the log level is Diagnostic where JsonRpc message payloads are logged and
// vary from 1K up 225K chars. When not logging message payloads the typical response
// log message is under 250 chars.
// the log level is Diagnostic where JsonRpc message payloads are logged and vary
// in size from 1K up to 225K chars. When not logging message payloads, the typical
// response log message size is under 256 chars.
var logStrBld =
new StringBuilder(this.logger.MinimumConfiguredLogLevel == LogLevel.Diagnostic ? 4096 : 250)
new StringBuilder(this.logger.MinimumConfiguredLogLevel == LogLevel.Diagnostic ? 4096 : 256)
.Append("Writing ")
.Append(messageToWrite.MessageType)
.Append(" '").Append(messageToWrite.Method).Append("'");
Expand Down
50 changes: 49 additions & 1 deletion tools/PsesLogAnalyzer/Analyze.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,59 @@ function Get-PsesIntelliSenseCompletionTime {
}

foreach ($entry in $logEntries) {
# IntelliSense completed in 320ms.
# IntelliSense completed in 320ms.
if (($entry.LogMessageType -eq 'Log') -and ($entry.Message.Data -match '^\s*IntelliSense completed in\s+(?<ms>\d+)ms.\s*$')) {
$elapsedMilliseconds = [int]$matches["ms"]
[PsesLogEntryElapsed]::new($entry, $elapsedMilliseconds)
}
}
}
}

function Get-PsesMessage {
[CmdletBinding(DefaultParameterSetName = "PsesLogEntry")]
param(
# Specifies a path to one or more PSES EditorServices log files.
[Parameter(Mandatory = $true, Position = 0, ParameterSetName = "Path")]
[Alias("PSPath")]
[ValidateNotNullOrEmpty()]
[string]
$Path,

# Specifies PsesLogEntry objects to analyze.
[Parameter(Mandatory = $true, Position = 0, ParameterSetName = "PsesLogEntry", ValueFromPipeline = $true)]
[ValidateNotNull()]
[psobject[]]
$LogEntry,

# Specifies the log level entries to return. Default returns Normal and above.
# Use StrictMatch to return only the specified log level entries.
[Parameter()]
[PsesLogLevel]
$LogLevel = $([PsesLogLevel]::Normal),

# Use StrictMatch to return only the specified log level entries.
[Parameter()]
[switch]
$StrictMatch
)

begin {
if ($PSCmdlet.ParameterSetName -eq "Path") {
$logEntries = Parse-PsesLog $Path
}
}

process {
if ($PSCmdlet.ParameterSetName -eq "PsesLogEntry") {
$logEntries = $LogEntry
}

foreach ($entry in $logEntries) {
if (($StrictMatch -and ($entry.LogLevel -eq $LogLevel)) -or
(!$StrictMatch -and ($entry.LogLevel -ge $LogLevel))) {
$entry
}
}
}
}
10 changes: 9 additions & 1 deletion tools/PsesLogAnalyzer/PsesLogAnalyzer.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<Width>15</Width>
<Alignment>left</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>LogLevel</Label>
<Width>11</Width>
<Alignment>left</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>Message</Label>
<Alignment>left</Alignment>
Expand All @@ -37,7 +42,7 @@
<TableColumnItems>
<TableColumnItem>
<PropertyName>Index</PropertyName>
</TableColumnItem>
</TableColumnItem>
<TableColumnItem>
<PropertyName>TimestampStr</PropertyName>
</TableColumnItem>
Expand All @@ -47,6 +52,9 @@
<TableColumnItem>
<PropertyName>LogMessageType</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>LogLevel</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>($_.Message -split "`r`n")[0]</ScriptBlock>
</TableColumnItem>
Expand Down
9 changes: 5 additions & 4 deletions tools/PsesLogAnalyzer/PsesLogAnalyzer.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ Author = 'Microsoft'
CompanyName = 'Microsoft'

# Copyright statement for this module
Copyright = '(c) 2017 Microsoft. All rights reserved.'
Copyright = '(c) 2018 Microsoft. All rights reserved.'

# Description of the functionality provided by this module
# Description = ''
Description = 'PowerShellEditorServices log file parser and analysis commands.'

# Minimum version of the PowerShell engine required by this module
# PowerShellVersion = ''
PowerShellVersion = '5.1'

# Name of the PowerShell host required by this module
# PowerShellHostName = ''
Expand Down Expand Up @@ -74,7 +74,8 @@ FunctionsToExport = @(
'Get-PsesRpcMessageResponseTime',
'Get-PsesRpcNotificationMessage',
'Get-PsesScriptAnalysisCompletionTime',
'Get-PsesIntelliSenseCompletionTime'
'Get-PsesIntelliSenseCompletionTime',
'Get-PsesMessage'
)

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
Expand Down
2 changes: 0 additions & 2 deletions tools/PsesLogAnalyzer/PsesLogAnalyzer.psm1
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
. $PSScriptRoot\Types.ps1
. $PSScriptRoot\Parse-PsesLog.ps1
. $PSScriptRoot\Analyze.ps1

Export-ModuleMember -Function *-*
30 changes: 16 additions & 14 deletions tools/PsesLogAnalyzer/Types.ps1
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
enum PsesLogLevel {
Diagnostic;
Verbose;
Normal;
Warning;
Error;
Diagnostic
Verbose
Normal
Warning
Error
}

enum PsesLogMessageType {
Log;
Exception;
HandledException;
Request;
Response;
Notification;
Log
Exception
HandledException
Request
Response
Notification
}

enum PsesNotificationSource {
Unknown;
Client;
Server;
Unknown
Client
Server
}

class PsesLogMessage {
[string]$Data
[int]$DataSize

PsesLogMessage([string]$Data) {
$this.Data = $Data
$this.DataSize = $Data.Length
}

[string] ToString() {
Expand Down

0 comments on commit e35b7d2

Please sign in to comment.