Skip to content

Commit

Permalink
add performance messurement functions
Browse files Browse the repository at this point in the history
  • Loading branch information
GER-Space committed Nov 15, 2016
1 parent 3c061b0 commit 79d577e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Utilities/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace KerbalKonstructs.Utilities
{
internal class Log
{
internal static Dictionary<string, Stopwatch> alltimers = new Dictionary<string, Stopwatch>();
internal static Stopwatch myWatch = null;

/// <summary>
/// log a normal message, if dbug is aktivated
/// </summary>
Expand Down Expand Up @@ -60,5 +63,50 @@ internal static void Trace()
{
StackTrace t = new StackTrace(); Log.Normal(t.ToString());
}

/// <summary>
/// Starts a Stopwatch timer with the id = string
/// </summary>
/// <param name="id"></param>
internal static void PerfStart(string id = "default")
{
myWatch = new Stopwatch();
alltimers.Add(id, myWatch);
myWatch.Start();
}

/// <summary>
/// resets the Stopwatchtimer with the (string)id and prints the result.
/// </summary>
/// <param name="id"></param>
internal static void PerfStop(string id = "default")
{
alltimers.TryGetValue(id, out myWatch);
myWatch.Stop();
Log.Normal("Stopwatch: \"" + id + "\" elapsed time: " + myWatch.Elapsed );
myWatch.Reset();
alltimers.Remove(id);
}

/// <summary>
/// Pauses the timer with the id
/// </summary>
/// <param name="id"></param>
internal static void PerfPause(string id = "default")
{
alltimers.TryGetValue(id, out myWatch);
myWatch.Stop();
}

/// <summary>
/// resumes the timer
/// </summary>
/// <param name="id"></param>
internal static void PerfContinue(string id = "default")
{
alltimers.TryGetValue(id, out myWatch);
myWatch.Start();
}

}
}

0 comments on commit 79d577e

Please sign in to comment.