1. oakio
  2. Devme.Diagnostics

Wiki

Clone wiki

Devme.Diagnostics / Home

Welcome

Here's an example of some code:

Example 1 (Simple)

using (StopwatchManager.Start(elapsed => Console.WriteLine("Elapsed: {0}", elapsed)))
{
    Thread.Sleep(2345);
}

Console output:
Elapsed: 00:00:02.345

Example 2 (Named regions)

using (StopwatchManager.Start("region1", elapsed => Console.WriteLine("First. Elapsed: {0}", elapsed.Current)))
{
    Thread.Sleep(1000);
}
using (StopwatchManager.Start("region1", elapsed => Console.WriteLine("Second. Elapsed: {0}", elapsed.Current)))
{
    Thread.Sleep(2000);
}
using (StopwatchManager.Start("region1", elapsed => Console.WriteLine("Third. " +
								  "Elapsed: {0}, " +
								  "Total: {1}, " +
								  "Count: {2}, " +
								  "Min: {3}, " +
								  "Max: {4}, " +
								  "Avg: {5}",
								  elapsed.Current,
								  elapsed.Total,
								  elapsed.Count,
								  elapsed.Min,
								  elapsed.Max,
								  elapsed.Avg
					)))
{
    Thread.Sleep(500);
}

Console output:
First. Elapsed: 00:00:01
Second. Elapsed: 00:00:02
Third. Elapsed: 00:00:00.500, Total: 00:00:03.500, Count: 3, Min: 00:00:00.500, Max: 00:00:02.000, Avg: 00:00:01.166

Example 3 (Hierarchy)

using (StopwatchManager.Start(elapsed => Console.WriteLine("Total: {0}", elapsed)))
{
    using (StopwatchManager.Start(elapsed => Console.WriteLine("Operation1: {0}", elapsed)))
    {
        Thread.Sleep(700); // Operation1
    }

    Thread.Sleep(200); // Operation2

    using (StopwatchManager.Start(elapsed => Console.WriteLine("Operation3: {0}", elapsed)))
    {
        Thread.Sleep(500); // Operation3
        using (StopwatchManager.Start(elapsed => Console.WriteLine("Operation4: {0}", elapsed)))
        {
            Thread.Sleep(100); // Operation3
        }
    }
}

Console output:
Operation1: 00:00:00.700
Operation3: 00:00:00.500
Operation4: 00:00:00.100
Total: 00:00:01.500

Have fun!

Updated