Merge pull request #206 from Shopify/pending_page_stats

Split the freelist page count stats to free and pending
master
Ben Johnson 2014-06-20 09:03:24 -06:00
commit 0a59a75472
4 changed files with 20 additions and 6 deletions

3
db.go
View File

@ -559,7 +559,8 @@ func (db *DB) allocate(count int) (*page, error) {
// Stats represents statistics about the database.
type Stats struct {
// 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
FreelistInuse int // total bytes used by the freelist

View File

@ -254,7 +254,8 @@ func TestDB_Stats(t *testing.T) {
})
stats := db.Stats()
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")
})
}

View File

@ -27,7 +27,17 @@ func (f *freelist) size() int {
// count returns count of pages on the freelist
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 {
count += len(list)
}

8
tx.go
View File

@ -233,7 +233,8 @@ func (tx *Tx) rollback() {
func (tx *Tx) close() {
if tx.writable {
// 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()
// Remove writer lock.
@ -241,8 +242,9 @@ func (tx *Tx) close() {
// Merge statistics.
tx.db.statlock.Lock()
tx.db.stats.FreePageN = freelistN
tx.db.stats.FreeAlloc = freelistN * tx.db.pageSize
tx.db.stats.FreePageN = freelistFreeN
tx.db.stats.PendingPageN = freelistPendingN
tx.db.stats.FreeAlloc = (freelistFreeN + freelistPendingN) * tx.db.pageSize
tx.db.stats.FreelistInuse = freelistAlloc
tx.db.stats.TxStats.add(&tx.stats)
tx.db.statlock.Unlock()