Ejemplo n.º 1
0
        public void EndEvent(object eventHandle)
        {
            if (eventHandle == null)
            {
                throw new ArgumentNullException(nameof(eventHandle));
            }

            SystemMetricEvent evt = eventHandle as SystemMetricEvent;

            if (evt != null)
            {
                long latencyMS = 0;
                evt.StopWatch.Stop();
                if (evt.StopWatch != null)
                {
                    evt.Duration = evt.StopWatch.Elapsed;
                    latencyMS    = evt.StopWatch.ElapsedMilliseconds;
                }
                else
                {
                    evt.Duration = DateTime.UtcNow - evt.Timestamp;
                    latencyMS    = (long)evt.Duration.TotalMilliseconds;
                }

                // event aggregation is based on this key
                // for each unique key, there will be only 1
                // queued event that we aggregate into
                string key = GetAggregateKey(evt.EventName, evt.FunctionName);

                QueuedEvents.AddOrUpdate(key,
                                         (name) =>
                {
                    // create the default event that will be added
                    // if an event isn't already queued for this key
                    return(new SystemMetricEvent
                    {
                        FunctionName = evt.FunctionName,
                        EventName = evt.EventName,
                        Minimum = latencyMS,
                        Maximum = latencyMS,
                        Average = latencyMS,
                        Count = 1,
                        Data = evt.Data
                    });
                },
                                         (name, evtToUpdate) =>
                {
                    // Aggregate into the existing event
                    // While we'll be performing an aggregation later,
                    // we retain the count so weighted averages can be performed
                    evtToUpdate.Maximum  = Math.Max(evtToUpdate.Maximum, latencyMS);
                    evtToUpdate.Minimum  = Math.Min(evtToUpdate.Minimum, latencyMS);
                    evtToUpdate.Average += latencyMS;      // the average is calculated later - for now we sum
                    evtToUpdate.Count++;

                    return(evtToUpdate);
                });
            }
        }
Ejemplo n.º 2
0
        public void EndEvent(object eventHandle)
        {
            if (eventHandle == null)
            {
                throw new ArgumentNullException(nameof(eventHandle));
            }

            SystemMetricEvent evt = eventHandle as SystemMetricEvent;

            if (evt != null)
            {
                evt.Duration = DateTime.UtcNow - evt.Timestamp;
                long latencyMS = (long)evt.Duration.TotalMilliseconds;

                QueuedEvents.AddOrUpdate(evt.EventName,
                                         (name) =>
                {
                    // create the default event that will be added
                    // if an event isn't already queued for this event name
                    return(new SystemMetricEvent
                    {
                        EventName = evt.EventName,
                        Minimum = latencyMS,
                        Maximum = latencyMS,
                        Average = latencyMS,
                        Count = 1
                    });
                },
                                         (name, evtToUpdate) =>
                {
                    // Aggregate into the existing event
                    // While we'll be performing an aggregation later,
                    // we retain the count so weighted averages can be performed
                    evtToUpdate.Maximum  = Math.Max(evtToUpdate.Maximum, latencyMS);
                    evtToUpdate.Minimum  = Math.Min(evtToUpdate.Minimum, latencyMS);
                    evtToUpdate.Average += latencyMS;      // the average is calculated later - for now we sum
                    evtToUpdate.Count++;

                    return(evtToUpdate);
                });
            }
        }