/// <summary>
            /// Creates and begins a new measurement.
            /// </summary>
            /// <param name="entity">The entity.</param>
            /// <param name="metric">The metric.</param>
            public MetricMeasurement(IReactiveResource entity, EntityMetric metric)
            {
                _entity = entity;
                _metric = metric;

                entity.BeginMetric(metric);
            }
        /// <summary>
        /// Creates and starts a new measurement.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="metric">The metric.</param>
        /// <returns>A measurement object that should be disposed to end the measurement.</returns>
        internal static MetricMeasurement Measure(this IReactiveResource entity, EntityMetric metric)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(new MetricMeasurement(entity, metric));
        }
        /// <summary>
        /// Stops a timer for a given entity and metric, and store the elapsed time.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="metric">The metric.</param>
        internal static void EndMetric(this IReactiveResource entity, EntityMetric metric)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            if (ShouldTrack)
            {
                Impl.Instance.EndMetric(entity, metric);
            }
        }
        /// <summary>
        /// Set a time span for a given entity and metric.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="metric">The metric.</param>
        /// <param name="elapsed">The time span.</param>
        internal static void SetMetric(this IReactiveResource entity, EntityMetric metric, TimeSpan elapsed)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            if (elapsed < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(elapsed));
            }

            if (ShouldTrack)
            {
                Impl.Instance.SetMetric(entity, metric, elapsed);
            }
        }
            public void EndMetric(IReactiveResource entity, EntityMetric metric)
            {
                var entityMetrics = GetEntityMetrics(entity);
                var idx           = (int)metric;

                var startingTicks = entityMetrics[idx];

                if (startingTicks == EmptyMetric)
                {
                    // End before start
                    return;
                }

                if (startingTicks >= 0)
                {
                    // The metric was already set. We can't do anything else.
                    return;
                }

                entityMetrics[idx] = startingTicks + s_timer.Elapsed.Ticks;
            }
 public void SetMetric(IReactiveResource entity, EntityMetric metric, TimeSpan elapsed)
 {
     GetEntityMetrics(entity)[(int)metric] = elapsed.Ticks;
 }
            public void BeginMetric(IReactiveResource entity, EntityMetric metric)
            {
                var entityMetrics = GetEntityMetrics(entity);

                Interlocked.Exchange(ref entityMetrics[(int)metric], -1 * s_timer.Elapsed.Ticks);
            }
Beispiel #8
0
 private static void Set(IReactiveResource entity, EntityMetric metric, TimeSpan elapsed)
 {
     EntityMetricsTracker.Impl.Instance.SetMetric(entity, metric, elapsed);
 }
Beispiel #9
0
 private static void End(IReactiveResource entity, EntityMetric metric)
 {
     EntityMetricsTracker.Impl.Instance.EndMetric(entity, metric);
 }