mirror of https://github.com/waku-org/nwaku.git
chore: Improving liteprotocolteseter stats (#2750)
This commit is contained in:
parent
dfc979a8ef
commit
4c7c8a1521
|
@ -17,6 +17,7 @@ type
|
||||||
prevArrivedAt: Moment
|
prevArrivedAt: Moment
|
||||||
lostIndices: HashSet[uint32]
|
lostIndices: HashSet[uint32]
|
||||||
seenIndices: HashSet[uint32]
|
seenIndices: HashSet[uint32]
|
||||||
|
maxIndex: uint32
|
||||||
|
|
||||||
Statistics* = object
|
Statistics* = object
|
||||||
allMessageCount*: uint32
|
allMessageCount*: uint32
|
||||||
|
@ -42,6 +43,7 @@ func `$`*(a: Duration): string {.inline.} =
|
||||||
|
|
||||||
proc init*(T: type Statistics, expectedMessageCount: int = 1000): T =
|
proc init*(T: type Statistics, expectedMessageCount: int = 1000): T =
|
||||||
result.helper.prevIndex = 0
|
result.helper.prevIndex = 0
|
||||||
|
result.helper.maxIndex = 0
|
||||||
result.helper.seenIndices.init(expectedMessageCount)
|
result.helper.seenIndices.init(expectedMessageCount)
|
||||||
result.minLatency = nanos(0)
|
result.minLatency = nanos(0)
|
||||||
result.maxLatency = nanos(0)
|
result.maxLatency = nanos(0)
|
||||||
|
@ -100,6 +102,7 @@ proc addMessage*(self: var Statistics, msg: ProtocolTesterMessage) =
|
||||||
warn "Negative latency detected",
|
warn "Negative latency detected",
|
||||||
index = msg.index, expected = expectedDelay, actual = delaySincePrevArrived
|
index = msg.index, expected = expectedDelay, actual = delaySincePrevArrived
|
||||||
|
|
||||||
|
self.helper.maxIndex = max(self.helper.maxIndex, msg.index)
|
||||||
self.helper.prevIndex = msg.index
|
self.helper.prevIndex = msg.index
|
||||||
self.helper.prevArrivedAt = currentArrivedAt
|
self.helper.prevArrivedAt = currentArrivedAt
|
||||||
inc(self.receivedMessages)
|
inc(self.receivedMessages)
|
||||||
|
@ -114,7 +117,7 @@ proc addMessage*(
|
||||||
self[peerId].addMessage(msg)
|
self[peerId].addMessage(msg)
|
||||||
|
|
||||||
proc lossCount*(self: Statistics): uint32 =
|
proc lossCount*(self: Statistics): uint32 =
|
||||||
self.allMessageCount - self.receivedMessages
|
self.helper.maxIndex - self.receivedMessages
|
||||||
|
|
||||||
proc averageLatency*(self: Statistics): Duration =
|
proc averageLatency*(self: Statistics): Duration =
|
||||||
if self.receivedMessages == 0:
|
if self.receivedMessages == 0:
|
||||||
|
@ -123,15 +126,15 @@ proc averageLatency*(self: Statistics): Duration =
|
||||||
|
|
||||||
proc echoStat*(self: Statistics) =
|
proc echoStat*(self: Statistics) =
|
||||||
let printable = catch:
|
let printable = catch:
|
||||||
"""*-----------------------------------------------------------------------------*
|
"""*------------------------------------------------------------------------------------------*
|
||||||
| Expected | Reveived | Loss | Misorder | Late | Duplicate |
|
| Expected | Received | Target | Loss | Misorder | Late | Duplicate |
|
||||||
|{self.allMessageCount:>11} |{self.receivedMessages:>11} |{self.lossCount():>11} |{self.misorderCount:>11} |{self.lateCount:>11} |{self.duplicateCount:>11} |
|
|{self.helper.maxIndex:>11} |{self.receivedMessages:>11} |{self.allMessageCount:>11} |{self.lossCount():>11} |{self.misorderCount:>11} |{self.lateCount:>11} |{self.duplicateCount:>11} |
|
||||||
*-----------------------------------------------------------------------------*
|
*------------------------------------------------------------------------------------------*
|
||||||
| Latency stat: |
|
| Latency stat: |
|
||||||
| avg latency: {$self.averageLatency():<60}|
|
| avg latency: {$self.averageLatency():<73}|
|
||||||
| min latency: {$self.maxLatency:<60}|
|
| min latency: {$self.maxLatency:<73}|
|
||||||
| max latency: {$self.minLatency:<60}|
|
| max latency: {$self.minLatency:<73}|
|
||||||
*-----------------------------------------------------------------------------*""".fmt()
|
*------------------------------------------------------------------------------------------*""".fmt()
|
||||||
|
|
||||||
if printable.isErr():
|
if printable.isErr():
|
||||||
echo "Error while printing statistics: " & printable.error().msg
|
echo "Error while printing statistics: " & printable.error().msg
|
||||||
|
@ -140,8 +143,9 @@ proc echoStat*(self: Statistics) =
|
||||||
|
|
||||||
proc jsonStat*(self: Statistics): string =
|
proc jsonStat*(self: Statistics): string =
|
||||||
let json = catch:
|
let json = catch:
|
||||||
"""{{"expected":{self.allMessageCount},
|
"""{{"expected":{self.helper.maxIndex},
|
||||||
"received": {self.receivedMessages},
|
"received": {self.receivedMessages},
|
||||||
|
"target": {self.allMessageCount},
|
||||||
"loss": {self.lossCount()},
|
"loss": {self.lossCount()},
|
||||||
"misorder": {self.misorderCount},
|
"misorder": {self.misorderCount},
|
||||||
"late": {self.lateCount},
|
"late": {self.lateCount},
|
||||||
|
|
Loading…
Reference in New Issue