swarm/network: measure time of message in pq

This commit is contained in:
Anton Evangelatov 2019-03-11 13:55:03 +01:00
parent fb458280d1
commit 35f34edced

View file

@ -28,8 +28,9 @@ package priorityqueue
import ( import (
"context" "context"
"errors" "errors"
"time"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics"
) )
var ( var (
@ -69,13 +70,16 @@ READ:
case <-ctx.Done(): case <-ctx.Done():
return return
case x := <-q: case x := <-q:
log.Trace("priority.queue f(x)", "p", p, "len(Queues[p])", len(pq.Queues[p])) val := x.(struct {
f(x) v interface{}
t time.Time
})
f(val.v)
metrics.GetOrRegisterResettingTimer("pq.run", nil).UpdateSince(val.t)
p = top p = top
default: default:
if p > 0 { if p > 0 {
p-- p--
log.Trace("priority.queue p > 0", "p", p)
continue READ continue READ
} }
p = top p = top
@ -83,7 +87,6 @@ READ:
case <-ctx.Done(): case <-ctx.Done():
return return
case <-pq.wakeup: case <-pq.wakeup:
log.Trace("priority.queue wakeup", "p", p)
} }
} }
} }
@ -95,9 +98,15 @@ func (pq *PriorityQueue) Push(x interface{}, p int) error {
if p < 0 || p >= len(pq.Queues) { if p < 0 || p >= len(pq.Queues) {
return errBadPriority return errBadPriority
} }
log.Trace("priority.queue push", "p", p, "len(Queues[p])", len(pq.Queues[p])) val := struct {
v interface{}
t time.Time
}{
x,
time.Now(),
}
select { select {
case pq.Queues[p] <- x: case pq.Queues[p] <- val:
default: default:
return ErrContention return ErrContention
} }