test fetcher: add more stats

Change-Id: Iad880544174c812a49640939b8fb2922da738b28
This commit is contained in:
Brad Fitzpatrick 2014-08-11 15:38:53 -07:00
parent f896ae934c
commit 3d058eca20
1 changed files with 21 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import (
"sort"
"strings"
"sync"
"sync/atomic"
"camlistore.org/pkg/blob"
"camlistore.org/pkg/blobserver"
@ -39,6 +40,9 @@ type Fetcher struct {
m map[string]*Blob // keyed by blobref string
sorted []string // blobrefs sorted
blobsFetched int64
bytesFetched int64
// ReceiveErr optionally returns the error to return on receive.
ReceiveErr error
@ -82,6 +86,9 @@ func (tf *Fetcher) Fetch(ref blob.Ref) (file io.ReadCloser, size uint32, err err
return
}
size = uint32(len(tb.Contents))
atomic.AddInt64(&tf.blobsFetched, 1)
atomic.AddInt64(&tf.bytesFetched, int64(len(tb.Contents)))
return struct {
*io.SectionReader
io.Closer
@ -143,6 +150,20 @@ func (tf *Fetcher) NumBlobs() int {
return len(tf.m)
}
func (tf *Fetcher) SumBlobSize() int64 {
tf.mu.RLock()
defer tf.mu.RUnlock()
var n int64
for _, b := range tf.m {
n += int64(len(b.Contents))
}
return n
}
func (tf *Fetcher) Stats() (blobsFetched, bytesFetched int64) {
return atomic.LoadInt64(&tf.blobsFetched), atomic.LoadInt64(&tf.bytesFetched)
}
// BlobrefStrings returns the sorted stringified blobrefs stored in this fetcher.
func (tf *Fetcher) BlobrefStrings() []string {
tf.mu.RLock()