Skip to content

Commit 1199c7f

Browse files
committed
Add more elapsed time log messages for dispatching
1 parent 7a04bba commit 1199c7f

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/PowerShellEditorServices.Protocol/MessageProtocol/ProtocolEndpoint.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ private async Task DequeueAndDispatchMessagesAsync(CancellationToken cancellatio
478478

479479
try
480480
{
481+
Logger.Write(LogLevel.Diagnostic, $"{_logCategory} Waiting for message to dequeue");
482+
481483
// TODO: Do we need to worry about the low priority queue never getting any service?
482484
if (_messageQueue.IsEmpty && !_lowPriorityMessageQueue.IsEmpty)
483485
{
@@ -489,14 +491,13 @@ private async Task DequeueAndDispatchMessagesAsync(CancellationToken cancellatio
489491
dequeuedMessage = await _messageQueue.DequeueAsync(cancellationToken);
490492
}
491493

492-
493-
// The message could be null if there was an error parsing the
494-
// previous message. In this case, do not try to dispatch it.
494+
// The message could be null if there was an error parsing the
495+
// previous message. In this case, do not try to dispatch it.
495496
if (dequeuedMessage?.Message == null)
496497
{
497498
Logger.Write(
498499
LogLevel.Warning,
499-
$"{_logCategory} Dequeued empty message, seq:{dequeuedMessage.SequenceNumber} ");
500+
$"{_logCategory} Dequeued empty message, seq:{dequeuedMessage.SequenceNumber}");
500501
}
501502
else
502503
{
@@ -527,13 +528,25 @@ private async Task DequeueAndDispatchMessagesAsync(CancellationToken cancellatio
527528
$"seq:{dequeuedMessage.SequenceNumber} cancel-seq:{queuedCancelMessage.SequenceNumber} " +
528529
$"#queued:{_messageQueue.Count} #pending:{_pendingCancelMessage.Count}");
529530

530-
await this.protocolChannel.MessageWriter.WriteMessageAsync(responseMessage);
531+
using (Logger.LogExecutionTime($"{_logCategory} Time to write cancellation response for seq:{dequeuedMessage.SequenceNumber}"))
532+
{
533+
await this.protocolChannel.MessageWriter.WriteMessageAsync(responseMessage);
534+
}
531535
}
532536
else
533537
{
534538
if (newMessage.MessageType == MessageType.Response)
535539
{
536-
this.HandleResponse(newMessage);
540+
Logger.Write(
541+
LogLevel.Diagnostic,
542+
$"{_logCategory} Dequeued and handling response for messsage {newMessage.Method} id:{newMessage.Id}, " +
543+
$"{queueName}queue wait time:{timeOnQueue}ms " +
544+
$"seq:{dequeuedMessage.SequenceNumber} #queued:{_messageQueue.Count}");
545+
546+
using (Logger.LogExecutionTime($"{_logCategory} Time to handle response for {newMessage.Method} id:{newMessage.Id} seq:{dequeuedMessage.SequenceNumber}"))
547+
{
548+
this.HandleResponse(newMessage);
549+
}
537550
}
538551
else
539552
{
@@ -544,7 +557,10 @@ private async Task DequeueAndDispatchMessagesAsync(CancellationToken cancellatio
544557
$"seq:{dequeuedMessage.SequenceNumber} #queued:{_messageQueue.Count}");
545558

546559
// Dispatch the message
547-
await this.messageDispatcher.DispatchMessageAsync(newMessage, this.protocolChannel.MessageWriter);
560+
using (Logger.LogExecutionTime($"{_logCategory} Time to dispatch {newMessage.Method} id:{newMessage.Id} seq:{dequeuedMessage.SequenceNumber}"))
561+
{
562+
await this.messageDispatcher.DispatchMessageAsync(newMessage, this.protocolChannel.MessageWriter);
563+
}
548564
}
549565
}
550566
}

0 commit comments

Comments
 (0)