Skip to content

Instantly share code, notes, and snippets.

@nootn
Created July 9, 2012 12:15
Show Gist options
  • Save nootn/3076142 to your computer and use it in GitHub Desktop.
Save nootn/3076142 to your computer and use it in GitHub Desktop.
MiniProfiler.Windows Samples
using (StackExchange.Profiling.MiniProfiler.Current.Step("Call Methods"))
{
//Some work to be done here
}
PM> Install-Package MiniProfiler.Windows
using (StackExchange.Profiling.MiniProfiler.Current.Step("Call Methods"))
{
//Do some work, E.g. call methods..
}
using System;
using System.Threading;
using MiniProfiler.Windows;
using StackExchange.Profiling;
namespace ConsoleApplicationSimpleExample
{
internal class Program
{
private static void Main()
{
//Start profiling
ConsoleProfiling.Start();
Console.WriteLine("Starting to call methods..");
using (StackExchange.Profiling.MiniProfiler.Current.Step("Call Methods"))
{
DoTheQuickWork();
DoTheSlowWork();
}
//Stop profiling and show results
Console.WriteLine(ConsoleProfiling.StopAndGetConsoleFriendlyOutputStringWithSqlTimings());
//Allow viewing of results
Console.WriteLine("... press 'Enter' to exit process ...");
Console.ReadLine();
}
private static void DoTheQuickWork()
{
using (StackExchange.Profiling.MiniProfiler.Current.Step("DoTheQuickWork"))
{
Thread.Sleep(100);
Console.WriteLine(" ... done quick work ... ");
}
}
private static void DoTheSlowWork()
{
using (StackExchange.Profiling.MiniProfiler.Current.Step("DoTheSlowWork"))
{
Thread.Sleep(5000);
Console.WriteLine(" ... done slow work ... ");
}
}
}
}
ConsoleProfiling.Start();
var friendlyString = ConsoleProfiling.StopAndGetConsoleFriendlyOutputStringWithSqlTimings();
Console.WriteLine(friendlyString);
Debug.WriteLine(friendlyString);
var result = ConsoleProfiling.StopAndGetProfiler();
//You can now check the MiniProfiler result, such as these useful properties:
result.HasSqlTimings;
result.DurationMilliseconds;
result.DurationMillisecondsInSql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment