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 (
"context"
"errors"
"time"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
)
var (
@ -69,13 +70,16 @@ READ:
case <-ctx.Done():
return
case x := <-q:
log.Trace("priority.queue f(x)", "p", p, "len(Queues[p])", len(pq.Queues[p]))
f(x)
val := x.(struct {
v interface{}
t time.Time
})
f(val.v)
metrics.GetOrRegisterResettingTimer("pq.run", nil).UpdateSince(val.t)
p = top
default:
if p > 0 {
p--
log.Trace("priority.queue p > 0", "p", p)
continue READ
}
p = top
@ -83,7 +87,6 @@ READ:
case <-ctx.Done():
return
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) {
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 {
case pq.Queues[p] <- x:
case pq.Queues[p] <- val:
default:
return ErrContention
}