Пример #1
0
 public static LatencyManager Register(LatencyMetric metric, out int id, out int count, out LatencyMetric previous)
 {
     GetInstance().Register(metric, out previous);
     id    = instance.GetNextId();
     count = instance.Count;
     return(instance);
 }
Пример #2
0
        private void Register(LatencyMetric metric, out LatencyMetric previous)
        {
            ActiveList <LatencyMetric> list;

            lock ( listMapLocker) {
                if (!listMap.TryGetValue(metric.Symbol, out list))
                {
                    list = new ActiveList <LatencyMetric>();
                    listMap[metric.Symbol] = list;
                }
                previous = list.Count > 0 ? list.Last.Value : null;
                list.AddLast(metric);
            }
        }
Пример #3
0
        public string GetStats(LatencyMetric previous)
        {
            using (locker.Using()) {
                var sb = new StringBuilder();
                sb.Append(name);
                sb.Append(" (");
                sb.Append(id);
                sb.Append("): ");
                sb.Append("tick count ");
                sb.Append(tickCount);
                sb.Append(", count ");
                sb.Append(count);
                sb.Append(", total ");
                sb.Append(total);
                if (previous != null)
                {
                    sb.Append(" (self ");
                    sb.Append(totalSelf);
                    sb.Append(")");
                }
                sb.Append(", last ");
                sb.Append(latencies[0]);
                if (previous != null)
                {
                    sb.Append(" (self ");
                    sb.Append(lastSelf);
                    sb.Append(")");
                }
                sb.Append(", average ");
                var average = Average;
                if (average != 0 && previous.Average != 0)
                {
                    sb.Append(Average);
                    sb.Append(" (self ");
                    sb.Append(AverageSelf);
                    sb.Append(")");
                }
                else
                {
                    sb.Append("Initializing...");
                }
                if (lastSelf > 1000 || AverageSelf > 1000 || (id == 0 && Average > 1000))
                {
                    sb.AppendLine();
                    sb.Append("Latencies: ");
                    for (var i = 0; i < latencies.Count; i++)
                    {
                        if (i != 0)
                        {
                            sb.Append(", ");
                        }
                        var prevIndex = (int)(previous.count - count) + i;
                        if (prevIndex >= 0 && prevIndex < previous.latencies.Count)
                        {
                            var latencySelf = id == 0 ? latencies[i] : latencies[i] - previous.latencies[prevIndex];
                            sb.Append(latencySelf);
                        }
                    }
                }

                return(sb.ToString());
            }
        }