mirror of
https://github.com/jech/galene.git
synced 2024-11-10 02:35:58 +01:00
Keep track of total numbers sent.
This commit is contained in:
parent
8fb8f7b7d5
commit
a6db6b105d
2 changed files with 21 additions and 3 deletions
|
@ -11,6 +11,8 @@ type Estimator struct {
|
||||||
count uint32
|
count uint32
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
|
totalBytes uint32
|
||||||
|
totalPackets uint32
|
||||||
rate uint32
|
rate uint32
|
||||||
time time.Time
|
time time.Time
|
||||||
}
|
}
|
||||||
|
@ -34,6 +36,8 @@ func (e *Estimator) swap(now time.Time) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Estimator) Accumulate(count uint32) {
|
func (e *Estimator) Accumulate(count uint32) {
|
||||||
|
atomic.AddUint32(&e.totalBytes, count)
|
||||||
|
atomic.AddUint32(&e.totalPackets, 1)
|
||||||
atomic.AddUint32(&e.count, count)
|
atomic.AddUint32(&e.count, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,3 +56,9 @@ func (e *Estimator) Estimate() uint32 {
|
||||||
defer e.mu.Unlock()
|
defer e.mu.Unlock()
|
||||||
return e.estimate(now)
|
return e.estimate(now)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Estimator) Totals() (uint32, uint32) {
|
||||||
|
b := atomic.LoadUint32(&e.totalBytes)
|
||||||
|
p := atomic.LoadUint32(&e.totalPackets)
|
||||||
|
return p, b
|
||||||
|
}
|
||||||
|
|
|
@ -18,4 +18,12 @@ func TestEstimator(t *testing.T) {
|
||||||
if rate != 42+128 {
|
if rate != 42+128 {
|
||||||
t.Errorf("Expected %v, got %v", 42+128, rate)
|
t.Errorf("Expected %v, got %v", 42+128, rate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
totalP, totalB := e.Totals()
|
||||||
|
if totalP != 2 {
|
||||||
|
t.Errorf("Expected 2, got %v", totalP)
|
||||||
|
}
|
||||||
|
if totalB != 42+128 {
|
||||||
|
t.Errorf("Expected %v, got %v", 42+128, totalB)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue