public long?GetAverageLatency(NodeLatencyStatType latencyType) { switch (latencyType) { case NodeLatencyStatType.P2PPingPong: return((long?)_pingPongAverageLatency); case NodeLatencyStatType.BlockHeaders: return((long?)_headersAverageLatency); case NodeLatencyStatType.BlockBodies: return((long?)_bodiesAverageLatency); default: throw new ArgumentOutOfRangeException(nameof(latencyType), latencyType, null); } }
public void AddLatencyCaptureEvent(NodeLatencyStatType latencyType, long milliseconds) { lock (_latencyLock) { switch (latencyType) { case NodeLatencyStatType.P2PPingPong: _pingPongAverageLatency = ((_pingPongLatencyEventCount * (_pingPongAverageLatency ?? 0)) + milliseconds) / (++_pingPongLatencyEventCount); break; case NodeLatencyStatType.BlockHeaders: _headersAverageLatency = ((_headersLatencyEventCount * (_headersAverageLatency ?? 0)) + milliseconds) / (++_headersLatencyEventCount); break; case NodeLatencyStatType.BlockBodies: _bodiesAverageLatency = ((_bodiesLatencyEventCount * (_bodiesAverageLatency ?? 0)) + milliseconds) / (++_bodiesLatencyEventCount); break; default: throw new ArgumentOutOfRangeException(nameof(latencyType), latencyType, null); } } }
public void ReportLatencyCaptureEvent(Node node, NodeLatencyStatType latencyType, long value) { INodeStats stats = GetOrAdd(node); stats.AddLatencyCaptureEvent(latencyType, value); }