Example #1
0
        public void MultipleTimers()
        {
            // Create a monitor. Normally this would be handled by dependency injection
            Monitor monitor = new Monitor {
                IsTimingEnabled = true
            };

            // Call the start timer method on the scorecard to start a timer with a
            // correlating name
            ITimer t1 = monitor.StartTimer("Demo");

            // Different named timers roll-up statistics separately
            ITimer t2 = monitor.StartTimer("Test");

            // Stopping a timer totals the number of milliseconds between the start and stop calls
            t1.Stop();

            // Timers can be re-started and stopped as necessary to accrue total time this is helpful when trying to measure only
            //the time spent in methods and not waiting for calls to external systems.
            t1.Start();             // maybe we entered our method
            t1.Stop();              // making a call to an external system not to be included in our time
            Task.Delay(500).Wait(); // pretend it took half a second
            t1.Start();             // start the time back up since we are processing the results
            t1.Stop();              // finally completed our processing and leaving our method.

            // Measure total time spent in this method
            t2.Stop(); // Test timer is stopped only once to give us a total time spent, not just our method processing time

            Debug.WriteLine(t1);
            Debug.WriteLine(t2);

            ITimerMaster master = monitor.RetrieveTimerMaster("Demo");

            Assert.IsNotNull(master);
        }
Example #2
0
        /// <summary>
        /// Removes the timer (master) with the given name.
        /// </summary>
        /// <param name="name">Name of the timer to remove from the monitor</param>
        /// <returns>The removed timer master or null if not timer with that name was found in the monitor.</returns>
        public ITimerMaster RemoveTimer(string name)
        {
            ITimerMaster retval = null;

            lock (masterTimers)
            {
                if (masterTimers.TryGetValue(name, out ITimerMaster master))
                {
                    retval = master;
                }
            }
            return(retval);
        }
Example #3
0
 /// <summary>
 /// Create a new no-op timer with the given master.
 /// </summary>
 /// <param name="TimingMaster"></param>
 /// <param name=""></param>
 public NullTimer(ITimerMaster master) : base(master)
 {
 }
Example #4
0
 protected AbstractTimer(ITimerMaster master)
 {
     Master = master;
 }