added docs
This commit is contained in:
parent
0ad73b982e
commit
9c20a7ff0e
@ -43,7 +43,7 @@ type BPS struct {
|
|||||||
|
|
||||||
// New Returns a populated and ready to launch BPS. dts is
|
// New Returns a populated and ready to launch BPS. dts is
|
||||||
// a slice of multiples of dt on which to report (e.g. 1x, 10x, 60x dt). dt is
|
// a slice of multiples of dt on which to report (e.g. 1x, 10x, 60x dt). dt is
|
||||||
// also how often the values used to send to Rx and Tx are updated.
|
// also how often the values used to send out in Cur are updated.
|
||||||
func New(dts []int, dt time.Duration) (*BPS, error) {
|
func New(dts []int, dt time.Duration) (*BPS, error) {
|
||||||
if len(dts) < 1 {
|
if len(dts) < 1 {
|
||||||
return nil, errors.New("must specify at least one interval lenght")
|
return nil, errors.New("must specify at least one interval lenght")
|
||||||
@ -116,12 +116,14 @@ func (b *BPS) averages(state []int64) []float64 {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write implements io.Writer so that one can simply write bytes to the struct.
|
||||||
func (b *BPS) Write(p []byte) (int, error) {
|
func (b *BPS) Write(p []byte) (int, error) {
|
||||||
n, err := ioutil.Discard.Write(p)
|
n, err := ioutil.Discard.Write(p)
|
||||||
b.Add(int64(n))
|
b.Add(int64(n))
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add adds i to the current time bucket.
|
||||||
func (b *BPS) Add(i int64) {
|
func (b *BPS) Add(i int64) {
|
||||||
b.Lock()
|
b.Lock()
|
||||||
b.curBs += i
|
b.curBs += i
|
||||||
@ -130,6 +132,7 @@ func (b *BPS) Add(i int64) {
|
|||||||
b.Unlock()
|
b.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cur returns a slice containing the currenly tracked rates.
|
||||||
func (b *BPS) Cur() []float64 {
|
func (b *BPS) Cur() []float64 {
|
||||||
r := make([]float64, len(b.dts))
|
r := make([]float64, len(b.dts))
|
||||||
b.Lock()
|
b.Lock()
|
||||||
@ -140,6 +143,7 @@ func (b *BPS) Cur() []float64 {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close cleans up and shuts down a BPS.
|
||||||
func (b *BPS) Close() {
|
func (b *BPS) Close() {
|
||||||
close(b.quit)
|
close(b.quit)
|
||||||
<-b.closed
|
<-b.closed
|
||||||
|
Loading…
Reference in New Issue
Block a user