@@ -483,43 +483,21 @@ private static async Task<bool> WaitAllIgnoreErrorsAsync(string name, Task[] tas
483483 return true ;
484484 }
485485
486- static void LogWithThreadPoolStats ( ILogger ? log , string message )
487- {
488- if ( log ? . IsEnabled ( LogLevel . Information ) != false )
489- {
490- return ;
491- }
492-
493- var busyWorkerCount = 0 ;
494- if ( log is not null )
495- {
496- var sb = new StringBuilder ( ) ;
497- sb . Append ( message ) ;
498- busyWorkerCount = PerfCounterHelper . GetThreadPoolStats ( out string iocp , out string worker , out string ? workItems ) ;
499- sb . Append ( ", IOCP: " ) . Append ( iocp ) . Append ( ", WORKER: " ) . Append ( worker ) ;
500- if ( workItems is not null )
501- {
502- sb . Append ( ", POOL: " ) . Append ( workItems ) ;
503- }
504- log ? . LogInformationThreadPoolStats ( sb . ToString ( ) ) ;
505- }
506- }
507-
508486 var watch = ValueStopwatch . StartNew ( ) ;
509- LogWithThreadPoolStats ( log , $ "Awaiting { tasks . Length } { name } task completion(s) for { timeoutMilliseconds } ms") ;
487+ log . LogWithThreadPoolStats ( $ "Awaiting { tasks . Length } { name } task completion(s) for { timeoutMilliseconds } ms") ;
510488 try
511489 {
512490 // if none error, great
513491 var remaining = timeoutMilliseconds - watch . ElapsedMilliseconds ;
514492 if ( remaining <= 0 )
515493 {
516- LogWithThreadPoolStats ( log , "Timeout before awaiting for tasks" ) ;
494+ log . LogWithThreadPoolStats ( "Timeout before awaiting for tasks" ) ;
517495 return false ;
518496 }
519497
520498 var allTasks = Task . WhenAll ( tasks ) . ObserveErrors ( ) ;
521499 bool all = await allTasks . TimeoutAfter ( timeoutMs : remaining ) . ObserveErrors ( ) . ForAwait ( ) ;
522- LogWithThreadPoolStats ( log , all ? $ "All { tasks . Length } { name } tasks completed cleanly" : $ "Not all { name } tasks completed cleanly (from { caller } #{ callerLineNumber } , timeout { timeoutMilliseconds } ms)") ;
500+ log . LogWithThreadPoolStats ( all ? $ "All { tasks . Length } { name } tasks completed cleanly" : $ "Not all { name } tasks completed cleanly (from { caller } #{ callerLineNumber } , timeout { timeoutMilliseconds } ms)") ;
523501 return all ;
524502 }
525503 catch
@@ -535,7 +513,7 @@ static void LogWithThreadPoolStats(ILogger? log, string message)
535513 var remaining = timeoutMilliseconds - watch . ElapsedMilliseconds ;
536514 if ( remaining <= 0 )
537515 {
538- LogWithThreadPoolStats ( log , "Timeout awaiting tasks" ) ;
516+ log . LogWithThreadPoolStats ( "Timeout awaiting tasks" ) ;
539517 return false ;
540518 }
541519 try
@@ -546,7 +524,7 @@ static void LogWithThreadPoolStats(ILogger? log, string message)
546524 { }
547525 }
548526 }
549- LogWithThreadPoolStats ( log , "Finished awaiting tasks" ) ;
527+ log . LogWithThreadPoolStats ( "Finished awaiting tasks" ) ;
550528 return false ;
551529 }
552530
0 commit comments