Repository navigation
Add support for hooking in additional instrumentation around Timings - #650
Conversation
|
Hey there! I'm not opposed to this if we make it opt-in. Even if we don't have an activity source, we eat 2x the creation time at a base level for
void Main()
{
Util.AutoScrollResults = true;
BenchmarkRunner.Run<ActivityBenchmarks>();
}
[ShortRunJob]
[MemoryDiagnoser]
public class ActivityBenchmarks
{
private static ActivitySource _noListener = new ActivitySource("NoListener.MiniProfiler.Timing", "1.0.0.0");
private static ActivitySource _listener = new ActivitySource("Listener.MiniProfiler.Timing", "1.0.0.0");
[GlobalSetup]
public void Setup()
{
ActivitySource.AddActivityListener(new ActivityListener()
{
ShouldListenTo = s => s.Name == "Listener.MiniProfiler.Timing",
Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllData,
});
}
[Benchmark]
public Activity ActivityNoListener() => _noListener.CreateActivity("Test", ActivityKind.Internal);
[Benchmark]
public Activity ActivityWithListener() => _listener.CreateActivity("Test", ActivityKind.Internal);
[Benchmark]
public Timing TimingNew() => new Timing();
[Benchmark]
public Timing TimingWithNoListener()
{
var a = _noListener.CreateActivity("Test", ActivityKind.Internal);
GC.KeepAlive(a);
return new Timing();
}
}Thoughts about making it cheaper for everyone else not opting in? (also: please sanity check quick benchmarks above) |
|
@NickCraver we don't use ActivitySource / Listener by default either, and doing having to use a Listener just to forward it to something else is indeed an overkill. I think this more minimal approach would be more flexible for folks to hook in whatever they need, while also being more lightweight. |
|
@m0sa I dig it, because later this could be a one-liner to set to a static Func that could hook Activity the same way and we could bundle that in-box too if no additional dependencies. Let's get this in :) |
Most of the code of a project that I'm working on is instrumented via MiniProfiler's extension methods. In order to get the MiniProfiler instrumented sections/traces into 3rd party APM tools, we'd either need to hijack all the MiniProfiler extension method combinations, or add yet another
usingaround everything we instrument via MiniProfiler. The latter is particularly impractical for the.Inline(() => ....)extension methods etc.This is just a little something to get a discussion going. How opposed would you be to something like this?