Skip to content

Commit

Permalink
Adding new method on BucketedBytes to expose used memory (thanos-io#7137
Browse files Browse the repository at this point in the history
)

* Adding new method on bucketed bytes to expose used

Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>

* Removing interface, using RWMutex

Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>

---------

Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
  • Loading branch information
pedro-stanaka authored Feb 14, 2024
1 parent e78d867 commit 4a82ba7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type BucketedBytes struct {
sizes []int
maxTotal uint64
usedTotal uint64
mtx sync.Mutex
mtx sync.RWMutex

new func(s int) *[]byte
}
Expand Down Expand Up @@ -137,3 +137,10 @@ func (p *BucketedBytes) Put(b *[]byte) {
p.usedTotal -= uint64(sz)
}
}

func (p *BucketedBytes) UsedBytes() uint64 {
p.mtx.RLock()
defer p.mtx.RUnlock()

return p.usedTotal
}

0 comments on commit 4a82ba7

Please sign in to comment.