forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounters.go
69 lines (61 loc) · 1.72 KB
/
counters.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package tgproducer
import (
"fmt"
"strconv"
)
// PatternCounters contains per-pattern counters.
type PatternCounters struct {
NInterests uint64 `json:"nInterests"`
PerReply []uint64 `json:"perReply"`
}
func (cnt PatternCounters) String() string {
var b []byte
for i, n := range cnt.PerReply {
if i > 0 {
b = append(b, '+')
}
b = strconv.AppendUint(b, n, 10)
}
b = append(b, '=')
b = strconv.AppendUint(b, cnt.NInterests, 10)
b = append(b, 'I')
return string(b)
}
// Counters contains producer counters.
type Counters struct {
PerPattern []PatternCounters `json:"perPattern"`
NInterests uint64 `json:"nInterests"`
NNoMatch uint64 `json:"nNoMatch"`
NAllocError uint64 `json:"nAllocError"`
}
func (cnt Counters) String() string {
s := fmt.Sprintf("%dI %dno-match %dalloc-error", cnt.NInterests, cnt.NNoMatch, cnt.NAllocError)
for i, pcnt := range cnt.PerPattern {
s += fmt.Sprintf(", pattern(%d) %s", i, pcnt)
}
return s
}
func (w *worker) accumulateCounters(cnt *Counters) {
for i := range cnt.PerPattern {
patternC, pcnt := w.c.pattern[i], &cnt.PerPattern[i]
for j := range pcnt.PerReply {
replyC := patternC.reply[j]
pcnt.PerReply[j] += uint64(replyC.nInterests)
pcnt.NInterests += uint64(replyC.nInterests)
}
cnt.NInterests += pcnt.NInterests
}
cnt.NNoMatch += uint64(w.c.nNoMatch)
cnt.NAllocError += uint64(w.c.nAllocError)
}
// Counters retrieves counters.
func (p Producer) Counters() (cnt Counters) {
cnt.PerPattern = make([]PatternCounters, len(p.cfg.Patterns))
for i, pattern := range p.cfg.Patterns {
cnt.PerPattern[i].PerReply = make([]uint64, len(pattern.Replies))
}
for _, w := range p.workers {
w.accumulateCounters(&cnt)
}
return cnt
}