Example #1
0
        public static double GetPreciseElapsedTime(this Instrumentation instrumentation)
        {
            // using reflection to access private member of class at run time
            // The drawbacks of reflection are:
            // 1) It has a performance penalty cost
            // 2) Reflection breaks if type changes
            var fieldInfo = typeof(Instrumentation).GetField("_startedAt", BindingFlags.Instance | BindingFlags.NonPublic);
            var startedAt = (DateTime)fieldInfo.GetValue(instrumentation);

            return(new TimeSpan(DateTime.Now.Ticks - startedAt.Ticks).TotalSeconds);
        }
Example #2
0
 public static long getReallyPreciseElapsedTime(this Instrumentation instrumentation)
 {
     return(_Stopwatches[instrumentation.Id].ElapsedMilliseconds);
 }
Example #3
0
 public static void StartWithPrecision(this Instrumentation instrumentation)
 {
     _Stopwatches[instrumentation.Id] = Stopwatch.StartNew();
 }