MiniProfiler V4 (currently prerelease) has method RenderPlainText()
. You can use it directly in console or multithreaded asynchronous server application without any additional setup:
public void Foo()
{
MiniProfiler.Start("Interesting subroutine");
using (MiniProfiler.Current.Step("Step1"))
{
using (MiniProfiler.Current.Step(nameof(AccessDb)))
{
AccessDb();
}
Thread.Sleep(100);
}
using (MiniProfiler.Current.Step("Step2"))
{
Thread.Sleep(100);
}
MiniProfiler.Stop();
Console.WriteLine(MiniProfiler.Current.RenderPlainText());
}
This code snippet produces following output:
PCName at 8/2/2017 8:44:36 AM
Interesting subroutine = 309.2ms
> Step1 = 204.8ms
>> AccessDb = 103.8ms (sql = 56.2ms in 2 cmds)
> Step2 = 100.9ms
As you can see output includes short summary of custom timings (sql in this case). You can easily alter this behavior (for example, to include command text) by providing your own version of RenderPlainText()
.
For more information check: