Example #1
0
        public void Log(int id, long utcTickTime)
        {
            if (latencyLog == null)
            {
                latencyLog = new LatencyLogEntry[2000000];
            }
            if (id < lastId)
            {
                Interlocked.Increment(ref tickCount);
            }
            lastId = id;
            var currentTime = TimeStamp.UtcNow.Internal;
            var latency     = currentTime - utcTickTime;

            if (latency < 1000)
            {
                alreadyShowedLog = false;
            }
            var showLog        = tickCount > 100 && latency > 20000;
            var selectCount    = Factory.Provider.ManagerTCP.SelectCount;
            var sendCounter    = Factory.Provider.ManagerTCP.SendCounter;
            var receiveCounter = Factory.Provider.ManagerTCP.ReceiveCounter;
            var tryReadCounter = Interlocked.Read(ref TryReadCounter);
            var simulator      = simulatorCount;
            var timerCount     = (int)Factory.Parallel.TimerCount;
            var entry          = new LatencyLogEntry
            {
                Count      = tickCount,
                Id         = id,
                TickTime   = utcTickTime,
                UtcTime    = currentTime,
                Selects    = (int)(selectCount - lastSelectCount),
                TryReceive = (int)(tryReadCounter - lastTryReadCount),
                Receives   = (int)(receiveCounter - lastReceiveCount),
                Sends      = (int)(sendCounter - lastSendCount),
                // - lastEarliestCount),
                Simulator  = (int)(simulator - lastSimulatorCount),
                TimerCount = timerCount,
            };

            lastSelectCount    = selectCount;
            lastTryReadCount   = tryReadCounter;
            lastReceiveCount   = receiveCounter;
            lastSendCount      = sendCounter;
            lastSimulatorCount = simulator;
            latencyLogLocker.Lock();
            AddLatency(ref entry);
            latencyLogLocker.Unlock();
            if (showLog && !alreadyShowedLog)
            {
                alreadyShowedLog = true;
                try { throw new ExceededLatencyException(); }
                catch { }
                log.Info("Latency exceed limit at " + latency + "ms.");
                log.Info("Latency log:\n" + LatencyManager.GetInstance().WriteLog(1000));
                log.Info(LatencyManager.GetInstance().GetStats() + "\n" + Factory.Parallel.GetStats());
                logCount++;
            }
        }
Example #2
0
        private void AddLatency(ref LatencyLogEntry entry)
        {
            var index = Interlocked.Increment(ref latencyLogIndex);

            latencyLog[index - 1] = entry;
        }