mirror of
https://github.com/kopia/kopia.git
synced 2026-03-16 05:09:21 -04:00
* Helper package internal/stats
* Use internal/stats for blob gc stats
* Use internal/stats for content list stats
* Refactor gc stats
- Leverages internal/stats package
- Return GC stats
- nit: error message formatting
- Refactor block in gc.Run.
Simplifies and reduces a level of indentation
23 lines
691 B
Go
23 lines
691 B
Go
// Package stats provides helpers for simple stats
|
|
package stats
|
|
|
|
import "sync/atomic"
|
|
|
|
// CountSum holds sum and count values
|
|
type CountSum struct {
|
|
sum int64
|
|
count uint32
|
|
}
|
|
|
|
// Add adds size to s and returns approximate values for the current count
|
|
// and total bytes
|
|
func (s *CountSum) Add(size int64) (count uint32, sum int64) {
|
|
return atomic.AddUint32(&s.count, 1), atomic.AddInt64(&s.sum, size)
|
|
}
|
|
|
|
// Approximate returns an approximation of the current count and sum values.
|
|
// It is approximate because retrieving both values is not an atomic operation.
|
|
func (s *CountSum) Approximate() (count uint32, sum int64) {
|
|
return atomic.LoadUint32(&s.count), atomic.LoadInt64(&s.sum)
|
|
}
|