3
3
4
4
using System ;
5
5
using System . Collections . Concurrent ;
6
+ using System . Diagnostics ;
6
7
using System . Linq ;
7
8
using System . Text . Encodings . Web ;
8
9
using System . Threading ;
9
10
using System . Threading . Tasks ;
10
11
using Microsoft . AspNetCore . Components . Rendering ;
11
12
using Microsoft . AspNetCore . Components . Server . Circuits ;
12
13
using Microsoft . AspNetCore . SignalR ;
14
+ using Microsoft . Extensions . Internal ;
13
15
using Microsoft . Extensions . Logging ;
14
16
using Microsoft . JSInterop ;
15
17
@@ -138,7 +140,8 @@ protected override Task UpdateDisplayAsync(in RenderBatch batch)
138
140
pendingRender = new UnacknowledgedRenderBatch (
139
141
renderId ,
140
142
arrayBuilder ,
141
- new TaskCompletionSource < object > ( ) ) ;
143
+ new TaskCompletionSource < object > ( ) ,
144
+ ValueStopwatch . StartNew ( ) ) ;
142
145
143
146
// Buffer the rendered batches no matter what. We'll send it down immediately when the client
144
147
// is connected or right after the client reconnects.
@@ -256,13 +259,14 @@ public void OnRenderCompleted(long incomingBatchId, string errorMessageOrNull)
256
259
257
260
private void ProcessPendingBatch ( string errorMessageOrNull , UnacknowledgedRenderBatch entry )
258
261
{
262
+ var elapsedTime = entry . ValueStopwatch . GetElapsedTime ( ) ;
259
263
if ( errorMessageOrNull == null )
260
264
{
261
- Log . CompletingBatchWithoutError ( _logger , entry . BatchId ) ;
265
+ Log . CompletingBatchWithoutError ( _logger , entry . BatchId , elapsedTime ) ;
262
266
}
263
267
else
264
268
{
265
- Log . CompletingBatchWithError ( _logger , entry . BatchId , errorMessageOrNull ) ;
269
+ Log . CompletingBatchWithError ( _logger , entry . BatchId , errorMessageOrNull , elapsedTime ) ;
266
270
}
267
271
268
272
entry . Data . Dispose ( ) ;
@@ -283,16 +287,18 @@ private void CompleteRender(TaskCompletionSource<object> pendingRenderInfo, stri
283
287
284
288
internal readonly struct UnacknowledgedRenderBatch
285
289
{
286
- public UnacknowledgedRenderBatch ( long batchId , ArrayBuilder < byte > data , TaskCompletionSource < object > completionSource )
290
+ public UnacknowledgedRenderBatch ( long batchId , ArrayBuilder < byte > data , TaskCompletionSource < object > completionSource , ValueStopwatch valueStopwatch )
287
291
{
288
292
BatchId = batchId ;
289
293
Data = data ;
290
294
CompletionSource = completionSource ;
295
+ ValueStopwatch = valueStopwatch ;
291
296
}
292
297
293
298
public long BatchId { get ; }
294
299
public ArrayBuilder < byte > Data { get ; }
295
300
public TaskCompletionSource < object > CompletionSource { get ; }
301
+ public ValueStopwatch ValueStopwatch { get ; }
296
302
}
297
303
298
304
private void CaptureAsyncExceptions ( Task task )
@@ -312,8 +318,8 @@ private static class Log
312
318
private static readonly Action < ILogger , long , int , string , Exception > _beginUpdateDisplayAsync ;
313
319
private static readonly Action < ILogger , string , Exception > _bufferingRenderDisconnectedClient ;
314
320
private static readonly Action < ILogger , string , Exception > _sendBatchDataFailed ;
315
- private static readonly Action < ILogger , long , string , Exception > _completingBatchWithError ;
316
- private static readonly Action < ILogger , long , Exception > _completingBatchWithoutError ;
321
+ private static readonly Action < ILogger , long , string , double , Exception > _completingBatchWithError ;
322
+ private static readonly Action < ILogger , long , double , Exception > _completingBatchWithoutError ;
317
323
private static readonly Action < ILogger , long , Exception > _receivedDuplicateBatchAcknowledgement ;
318
324
319
325
private static class EventIds
@@ -349,15 +355,15 @@ static Log()
349
355
EventIds . SendBatchDataFailed ,
350
356
"Sending data for batch failed: {Message}" ) ;
351
357
352
- _completingBatchWithError = LoggerMessage . Define < long , string > (
358
+ _completingBatchWithError = LoggerMessage . Define < long , string , double > (
353
359
LogLevel . Debug ,
354
360
EventIds . CompletingBatchWithError ,
355
- "Completing batch {BatchId} with error: {ErrorMessage}" ) ;
361
+ "Completing batch {BatchId} with error: {ErrorMessage} in {ElapsedMilliseconds}ms. " ) ;
356
362
357
- _completingBatchWithoutError = LoggerMessage . Define < long > (
363
+ _completingBatchWithoutError = LoggerMessage . Define < long , double > (
358
364
LogLevel . Debug ,
359
365
EventIds . CompletingBatchWithoutError ,
360
- "Completing batch {BatchId} without error" ) ;
366
+ "Completing batch {BatchId} without error in {ElapsedMilliseconds}ms. " ) ;
361
367
362
368
_receivedDuplicateBatchAcknowledgement = LoggerMessage . Define < long > (
363
369
LogLevel . Debug ,
@@ -396,20 +402,22 @@ public static void BufferingRenderDisconnectedClient(ILogger logger, string conn
396
402
null ) ;
397
403
}
398
404
399
- public static void CompletingBatchWithError ( ILogger logger , long batchId , string errorMessage )
405
+ public static void CompletingBatchWithError ( ILogger logger , long batchId , string errorMessage , TimeSpan elapsedTime )
400
406
{
401
407
_completingBatchWithError (
402
408
logger ,
403
409
batchId ,
404
410
errorMessage ,
411
+ elapsedTime . TotalMilliseconds ,
405
412
null ) ;
406
413
}
407
414
408
- public static void CompletingBatchWithoutError ( ILogger logger , long batchId )
415
+ public static void CompletingBatchWithoutError ( ILogger logger , long batchId , TimeSpan elapsedTime )
409
416
{
410
417
_completingBatchWithoutError (
411
418
logger ,
412
419
batchId ,
420
+ elapsedTime . TotalMilliseconds ,
413
421
null ) ;
414
422
}
415
423
0 commit comments