Example #1
0
        public static double GetPreciseElapsedTime(this Instrumentation instrumentation)
        {
            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
        //There's no garbage collection for this extended state, so it will just grow continually. That's a concern.

        public static double GetPreciseElapsedTime(this Instrumentation instrumentation)
        {
            //var startedAt = instrumentation._startedAt; //can't do this because _startedAt is a private field.
            //try workaround using reflection...
            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 #3
0
 public static long GetReallyPreciseElapsedTime(this Instrumentation instrumentation)
 {
     return(_Stopwatches[instrumentation.Id].ElapsedMilliseconds);
 }
Example #4
0
 //We'll use this method instead of the original start method (on the Instrumentation class)
 public static void StartWithPrecision(this Instrumentation instrumentation)
 {
     _Stopwatches[instrumentation.Id] = Stopwatch.StartNew();
 }