code: func (db *DB) Stats(s *DBStats) error {
  	err := db.ok()
  	if err != nil {
  		return err
  	}
  
  	s.IORead = db.s.stor.reads()
  	s.IOWrite = db.s.stor.writes()
  	s.WriteDelayCount = atomic.LoadInt32(&db.cWriteDelayN)
  	s.WriteDelayDuration = time.Duration(atomic.LoadInt64(&db.cWriteDelay))
  	s.WritePaused = atomic.LoadInt32(&db.inWritePaused) == 1
  
  	s.OpenedTablesCount = db.s.tops.cache.Size()
  	if db.s.tops.bcache != nil {
  		s.BlockCacheSize = db.s.tops.bcache.Size()
  	} else {
  		s.BlockCacheSize = 0
  	}
  
  	s.AliveIterators = atomic.LoadInt32(&db.aliveIters)
  	s.AliveSnapshots = atomic.LoadInt32(&db.aliveSnaps)
  
  	s.LevelDurations = s.LevelDurations[:0]
  	s.LevelRead = s.LevelRead[:0]
  	s.LevelWrite = s.LevelWrite[:0]
  	s.LevelSizes = s.LevelSizes[:0]
  	s.LevelTablesCounts = s.LevelTablesCounts[:0]
  
  	v := db.s.version()
  	defer v.release()
  
  	for level, tables := range v.levels {
  		duration, read, write := db.compStats.getStat(level)
  		if len(tables) == 0 && duration == 0 {
  			continue
  		}
  		s.LevelDurations = append(s.LevelDurations, duration)
  		s.LevelRead = append(s.LevelRead, read)
  		s.LevelWrite = append(s.LevelWrite, write)
  		s.LevelSizes = append(s.LevelSizes, tables.size())
  		s.LevelTablesCounts = append(s.LevelTablesCounts, len(tables))
  	}
  
  	return nil
  }
docs: // Stats populates s with database statistics.