diff --git a/db.go b/db.go index 9a125ee..d7037f9 100644 --- a/db.go +++ b/db.go @@ -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 diff --git a/db_test.go b/db_test.go index b5c943e..0fc286b 100644 --- a/db_test.go +++ b/db_test.go @@ -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") }) } diff --git a/freelist.go b/freelist.go index 3551113..6f05ac5 100644 --- a/freelist.go +++ b/freelist.go @@ -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) } diff --git a/tx.go b/tx.go index ac034ec..09077de 100644 --- a/tx.go +++ b/tx.go @@ -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()