Skip to content

Commit cd06839

Browse files
committed
Revert changes to the BenchmarkProfiling tool.
1 parent 58214f5 commit cd06839

1 file changed

Lines changed: 1 addition & 57 deletions

File tree

bench/Autofac.BenchmarkProfiling/Program.cs

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using System.Diagnostics;
2-
using System.Reflection;
3-
using BenchmarkDotNet.Running;
1+
using BenchmarkDotNet.Running;
42
using BenchmarkDotNet.Toolchains.InProcess.NoEmit;
5-
using Autofac.Core;
63

74
namespace Autofac.BenchmarkProfiling;
85

@@ -13,11 +10,6 @@ class Program
1310
{
1411
static void Main(string[] args)
1512
{
16-
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AUTOFAC_SCOPE_DIAGNOSTICS")))
17-
{
18-
AppContext.SetSwitch("Autofac.ScopeIsolatedDiagnostics", true);
19-
}
20-
2113
// Pick a benchmark.
2214
var availableBenchmarks = Benchmarks.BenchmarkSet.All;
2315

@@ -106,20 +98,6 @@ void workloadAction(int repeat)
10698
// Warmup.
10799
workloadAction(100);
108100

109-
if (int.TryParse(Environment.GetEnvironmentVariable("AUTOFAC_MEASURE_ITERATIONS"), out var measurementIterations) &&
110-
measurementIterations > 0)
111-
{
112-
var sw = Stopwatch.StartNew();
113-
workloadAction(measurementIterations);
114-
sw.Stop();
115-
var perIteration = sw.Elapsed.TotalMilliseconds / measurementIterations;
116-
Console.WriteLine(
117-
"[Profiling] Duration: {0} iterations took {1:F2} ms (avg {2:F4} ms)",
118-
measurementIterations,
119-
sw.Elapsed.TotalMilliseconds,
120-
perIteration);
121-
}
122-
123101
// Now start a new thread.
124102
var runThread = new Thread(new ThreadStart(() =>
125103
{
@@ -134,8 +112,6 @@ void workloadAction(int repeat)
134112
runThread.Join();
135113

136114
cleanupAction.InvokeSingle();
137-
138-
LogScopeDiagnosticsIfEnabled();
139115
}
140116

141117
private static void PrintBenchmarks(Type[] availableBenchmarks)
@@ -161,36 +137,4 @@ private static void PrintCases(BenchmarkRunInfo benchRunInfo)
161137
}
162138
}
163139
}
164-
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-
}
196140
}

0 commit comments

Comments
 (0)