mirror of https://github.com/etcd-io/bbolt.git
split the freelist page count stats to free and pending
parent
42b4cae0fd
commit
571f201672
3
db.go
3
db.go
|
@ -559,7 +559,8 @@ func (db *DB) allocate(count int) (*page, error) {
|
||||||
// Stats represents statistics about the database.
|
// Stats represents statistics about the database.
|
||||||
type Stats struct {
|
type Stats struct {
|
||||||
// Freelist stats
|
// Freelist stats
|
||||||
FreePageN int // total number of free pages
|
FreePageN int // total number of free pages on the freelist
|
||||||
|
PendingPageN int // total number of pending pages on the freelist
|
||||||
FreeAlloc int // total bytes allocated in free pages
|
FreeAlloc int // total bytes allocated in free pages
|
||||||
FreelistInuse int // total bytes used by the freelist
|
FreelistInuse int // total bytes used by the freelist
|
||||||
|
|
||||||
|
|
|
@ -254,7 +254,8 @@ func TestDB_Stats(t *testing.T) {
|
||||||
})
|
})
|
||||||
stats := db.Stats()
|
stats := db.Stats()
|
||||||
assert.Equal(t, 2, stats.TxStats.PageCount, "PageCount")
|
assert.Equal(t, 2, stats.TxStats.PageCount, "PageCount")
|
||||||
assert.Equal(t, 2, stats.FreePageN, "FreelistN")
|
assert.Equal(t, 0, stats.FreePageN, "FreePageN")
|
||||||
|
assert.Equal(t, 2, stats.PendingPageN, "PendingPageN")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
freelist.go
12
freelist.go
|
@ -27,7 +27,17 @@ func (f *freelist) size() int {
|
||||||
|
|
||||||
// count returns count of pages on the freelist
|
// count returns count of pages on the freelist
|
||||||
func (f *freelist) count() int {
|
func (f *freelist) count() int {
|
||||||
var count = len(f.ids)
|
return f.free_count() + f.pending_count()
|
||||||
|
}
|
||||||
|
|
||||||
|
// free_count returns count of free pages
|
||||||
|
func (f *freelist) free_count() int {
|
||||||
|
return len(f.ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
// pending_count returns count of pending pages
|
||||||
|
func (f *freelist) pending_count() int {
|
||||||
|
var count int
|
||||||
for _, list := range f.pending {
|
for _, list := range f.pending {
|
||||||
count += len(list)
|
count += len(list)
|
||||||
}
|
}
|
||||||
|
|
8
tx.go
8
tx.go
|
@ -233,7 +233,8 @@ func (tx *Tx) rollback() {
|
||||||
func (tx *Tx) close() {
|
func (tx *Tx) close() {
|
||||||
if tx.writable {
|
if tx.writable {
|
||||||
// Grab freelist stats.
|
// Grab freelist stats.
|
||||||
var freelistN = tx.db.freelist.count()
|
var freelistFreeN = tx.db.freelist.free_count()
|
||||||
|
var freelistPendingN = tx.db.freelist.pending_count()
|
||||||
var freelistAlloc = tx.db.freelist.size()
|
var freelistAlloc = tx.db.freelist.size()
|
||||||
|
|
||||||
// Remove writer lock.
|
// Remove writer lock.
|
||||||
|
@ -241,8 +242,9 @@ func (tx *Tx) close() {
|
||||||
|
|
||||||
// Merge statistics.
|
// Merge statistics.
|
||||||
tx.db.statlock.Lock()
|
tx.db.statlock.Lock()
|
||||||
tx.db.stats.FreePageN = freelistN
|
tx.db.stats.FreePageN = freelistFreeN
|
||||||
tx.db.stats.FreeAlloc = freelistN * tx.db.pageSize
|
tx.db.stats.PendingPageN = freelistPendingN
|
||||||
|
tx.db.stats.FreeAlloc = (freelistFreeN + freelistPendingN) * tx.db.pageSize
|
||||||
tx.db.stats.FreelistInuse = freelistAlloc
|
tx.db.stats.FreelistInuse = freelistAlloc
|
||||||
tx.db.stats.TxStats.add(&tx.stats)
|
tx.db.stats.TxStats.add(&tx.stats)
|
||||||
tx.db.statlock.Unlock()
|
tx.db.statlock.Unlock()
|
||||||
|
|
Loading…
Reference in New Issue