11using System . Diagnostics ;
2- using System . Reflection ;
32using BenchmarkDotNet . Running ;
43using BenchmarkDotNet . Toolchains . InProcess . NoEmit ;
5- using Autofac . Core ;
64
75namespace Autofac . BenchmarkProfiling ;
86
@@ -13,11 +11,6 @@ class Program
1311{
1412 static void Main ( string [ ] args )
1513 {
16- if ( ! string . IsNullOrEmpty ( Environment . GetEnvironmentVariable ( "AUTOFAC_SCOPE_DIAGNOSTICS" ) ) )
17- {
18- AppContext . SetSwitch ( "Autofac.ScopeIsolatedDiagnostics" , true ) ;
19- }
20-
2114 // Pick a benchmark.
2215 var availableBenchmarks = Benchmarks . BenchmarkSet . All ;
2316
@@ -134,8 +127,6 @@ void workloadAction(int repeat)
134127 runThread . Join ( ) ;
135128
136129 cleanupAction . InvokeSingle ( ) ;
137-
138- LogScopeDiagnosticsIfEnabled ( ) ;
139130 }
140131
141132 private static void PrintBenchmarks ( Type [ ] availableBenchmarks )
@@ -162,35 +153,4 @@ private static void PrintCases(BenchmarkRunInfo benchRunInfo)
162153 }
163154 }
164155
165- private static void LogScopeDiagnosticsIfEnabled ( )
166- {
167- if ( ! AppContext . TryGetSwitch ( "Autofac.ScopeIsolatedDiagnostics" , out var enabled ) || ! enabled )
168- {
169- return ;
170- }
171-
172- var diagnosticsType = typeof ( IComponentRegistry ) . Assembly . GetType ( "Autofac.Core.Registration.ScopeIsolatedServiceDiagnostics" ) ;
173- var snapshotProperty = diagnosticsType ? . GetProperty (
174- "Snapshot" ,
175- BindingFlags . NonPublic | BindingFlags . Public | BindingFlags . Static ) ;
176-
177- if ( snapshotProperty ? . GetValue ( null ) is object snapshot )
178- {
179- var cacheHits = ( long ) ( snapshot . GetType ( ) . GetProperty ( "CacheHits" ) ? . GetValue ( snapshot ) ?? 0L ) ;
180- var cacheMisses = ( long ) ( snapshot . GetType ( ) . GetProperty ( "CacheMisses" ) ? . GetValue ( snapshot ) ?? 0L ) ;
181- var cacheAdds = ( long ) ( snapshot . GetType ( ) . GetProperty ( "CacheAdds" ) ? . GetValue ( snapshot ) ?? 0L ) ;
182- var cacheRemovals = ( long ) ( snapshot . GetType ( ) . GetProperty ( "CacheRemovals" ) ? . GetValue ( snapshot ) ?? 0L ) ;
183- var cachedInitializations = ( long ) ( snapshot . GetType ( ) . GetProperty ( "CachedInitializations" ) ? . GetValue ( snapshot ) ?? 0L ) ;
184- var discardedInfos = ( long ) ( snapshot . GetType ( ) . GetProperty ( "ServiceInfoDiscarded" ) ? . GetValue ( snapshot ) ?? 0L ) ;
185-
186- Console . WriteLine (
187- "[Profiling] Scope cache stats -> Hits={0}, Misses={1}, Adds={2}, Removes={3}, CachedInit={4}, Discarded={5}" ,
188- cacheHits ,
189- cacheMisses ,
190- cacheAdds ,
191- cacheRemovals ,
192- cachedInitializations ,
193- discardedInfos ) ;
194- }
195- }
196156}
0 commit comments