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++; } }
public static LatencyManager GetInstance() { if (instance == null) { instance = new LatencyManager(); } return(instance); }
protected virtual void Dispose(bool disposing) { if (!isDisposed) { lock ( disposeLocker) { isDisposed = true; if (disposing) { // if( debug) log.Debug("Dispose()"); instance = new LatencyManager(); } } } }
public void TryUpdate(long symbol, long timeStamp) { if (timeStamp == long.MaxValue || timeStamp == 0L) { return; } if (id == int.MinValue) { this.symbol = symbol; this.manager = LatencyManager.Register(this, out id, out metricCount, out previous); if (trace) { log.Trace("Registered " + name + " metric (" + id + ") on tick " + new TimeStamp(timeStamp) + ")"); } } if (verbose) { //manager.Log(id, timeStamp); //Update(timeStamp); //tickCount++; } }