17
17
prevArrivedAt: Moment
18
18
lostIndices: HashSet [uint32 ]
19
19
seenIndices: HashSet [uint32 ]
20
+ maxIndex: uint32
20
21
21
22
Statistics * = object
22
23
allMessageCount* : uint32
@@ -42,6 +43,7 @@ func `$`*(a: Duration): string {.inline.} =
42
43
43
44
proc init * (T: type Statistics , expectedMessageCount: int = 1000 ): T =
44
45
result .helper.prevIndex = 0
46
+ result .helper.maxIndex = 0
45
47
result .helper.seenIndices.init (expectedMessageCount)
46
48
result .minLatency = nanos (0 )
47
49
result .maxLatency = nanos (0 )
@@ -100,6 +102,7 @@ proc addMessage*(self: var Statistics, msg: ProtocolTesterMessage) =
100
102
warn " Negative latency detected" ,
101
103
index = msg.index, expected = expectedDelay, actual = delaySincePrevArrived
102
104
105
+ self.helper.maxIndex = max (self.helper.maxIndex, msg.index)
103
106
self.helper.prevIndex = msg.index
104
107
self.helper.prevArrivedAt = currentArrivedAt
105
108
inc (self.receivedMessages)
@@ -114,7 +117,7 @@ proc addMessage*(
114
117
self[peerId].addMessage (msg)
115
118
116
119
proc lossCount * (self: Statistics ): uint32 =
117
- self.allMessageCount - self.receivedMessages
120
+ self.helper.maxIndex - self.receivedMessages
118
121
119
122
proc averageLatency * (self: Statistics ): Duration =
120
123
if self.receivedMessages == 0 :
@@ -123,15 +126,15 @@ proc averageLatency*(self: Statistics): Duration =
123
126
124
127
proc echoStat * (self: Statistics ) =
125
128
let printable = catch:
126
- """ *-----------------------------------------------------------------------------*
127
- | Expected | Reveived | Loss | Misorder | Late | Duplicate |
128
- |{self.allMessageCount :>11} |{self.receivedMessages:>11} |{self.lossCount():>11} |{self.misorderCount:>11} |{self.lateCount:>11} |{self.duplicateCount:>11} |
129
- *-----------------------------------------------------------------------------*
130
- | Latency stat: |
131
- | avg latency: {$self.averageLatency():<60 }|
132
- | min latency: {$self.maxLatency:<60 }|
133
- | max latency: {$self.minLatency:<60 }|
134
- *-----------------------------------------------------------------------------* """ .fmt ()
129
+ """ *------------------------------------------------------------------------------------------ *
130
+ | Expected | Received | Target | Loss | Misorder | Late | Duplicate |
131
+ |{self.helper.maxIndex :>11} |{self.receivedMessages:>11} |{self.allMessageCount :>11} |{self.lossCount():>11} |{self.misorderCount:>11} |{self.lateCount:>11} |{self.duplicateCount:>11} |
132
+ *------------------------------------------------------------------------------------------ *
133
+ | Latency stat: |
134
+ | avg latency: {$self.averageLatency():<73 }|
135
+ | min latency: {$self.maxLatency:<73 }|
136
+ | max latency: {$self.minLatency:<73 }|
137
+ *------------------------------------------------------------------------------------------ * """ .fmt ()
135
138
136
139
if printable.isErr ():
137
140
echo " Error while printing statistics: " & printable.error ().msg
@@ -140,8 +143,9 @@ proc echoStat*(self: Statistics) =
140
143
141
144
proc jsonStat * (self: Statistics ): string =
142
145
let json = catch:
143
- """ {{"expected":{self.allMessageCount },
146
+ """ {{"expected":{self.helper.maxIndex },
144
147
"received": {self.receivedMessages},
148
+ "target": {self.allMessageCount},
145
149
"loss": {self.lossCount()},
146
150
"misorder": {self.misorderCount},
147
151
"late": {self.lateCount},
0 commit comments