Monday, June 25, 2018

.net core perf profiler via code

Leave a Comment

I developed a middleware that starts a Stopwatch before invoking next and stops when the response is available, I do log the elapsed time after that.

This is all good. But it doesnt provide me breakdown, ie: within the call which method invocations took how much? for example: if I have 4 method calls in a request, I would like to know each one's duration.

I assume, middleware is not enough for this purpose, without having to put decorators all over the place, how can i get this done?

Thanks.

1 Answers

Answers 1

Probably, you have to manually instrument most interesting pieces of code.

Although, there are solutions for IL injection (see MSIL Injection page on PostSharp website), I don't think that it is possible to inject code in arbitrary places without changing existing code base. However, in many cases it is relatively easy to instrument large portion of existing code (given it is reasonably well separated into modules) using decorators. For example add custom profiling DelegatingHandler to HttpClient or use profiling SqlConnection factory.

In order to inspect call hierarchy and latency you can utilize MiniProfiler, it's built-in decorators and RenderPlainText() method. Or you can utilize Metrics.NET library to inspect throughput related metrics such as histogram and counter.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment