@@ -22,7 +22,6 @@ package leveldb
2222
2323import (
2424 "fmt"
25- "strings"
2625 "sync"
2726 "time"
2827
@@ -244,14 +243,53 @@ func (db *Database) NewSnapshot() (ethdb.Snapshot, error) {
244243 return & snapshot {db : snap }, nil
245244}
246245
247- // Stat returns a particular internal stat of the database.
248- func (db * Database ) Stat (property string ) (string , error ) {
249- if property == "" {
250- property = "leveldb.stats"
251- } else if ! strings .HasPrefix (property , "leveldb." ) {
252- property = "leveldb." + property
246+ // Stat returns the statistic data of the database.
247+ func (db * Database ) Stat () (string , error ) {
248+ var stats leveldb.DBStats
249+ if err := db .db .Stats (& stats ); err != nil {
250+ return "" , err
253251 }
254- return db .db .GetProperty (property )
252+ var (
253+ message string
254+ totalRead int64
255+ totalWrite int64
256+ totalSize int64
257+ totalTables int
258+ totalDuration time.Duration
259+ )
260+ if len (stats .LevelSizes ) > 0 {
261+ message += " Level | Tables | Size(MB) | Time(sec) | Read(MB) | Write(MB)\n " +
262+ "-------+------------+---------------+---------------+---------------+---------------\n "
263+ for level , size := range stats .LevelSizes {
264+ read := stats .LevelRead [level ]
265+ write := stats .LevelWrite [level ]
266+ duration := stats .LevelDurations [level ]
267+ tables := stats .LevelTablesCounts [level ]
268+
269+ if tables == 0 && duration == 0 {
270+ continue
271+ }
272+ totalTables += tables
273+ totalSize += size
274+ totalRead += read
275+ totalWrite += write
276+ totalDuration += duration
277+ message += fmt .Sprintf (" %3d | %10d | %13.5f | %13.5f | %13.5f | %13.5f\n " ,
278+ level , tables , float64 (size )/ 1048576.0 , duration .Seconds (),
279+ float64 (read )/ 1048576.0 , float64 (write )/ 1048576.0 )
280+ }
281+ message += "-------+------------+---------------+---------------+---------------+---------------\n "
282+ message += fmt .Sprintf (" Total | %10d | %13.5f | %13.5f | %13.5f | %13.5f\n " ,
283+ totalTables , float64 (totalSize )/ 1048576.0 , totalDuration .Seconds (),
284+ float64 (totalRead )/ 1048576.0 , float64 (totalWrite )/ 1048576.0 )
285+ message += "-------+------------+---------------+---------------+---------------+---------------\n \n "
286+ }
287+ message += fmt .Sprintf ("Read(MB):%.5f Write(MB):%.5f\n " , float64 (stats .IORead )/ 1048576.0 , float64 (stats .IOWrite )/ 1048576.0 )
288+ message += fmt .Sprintf ("BlockCache(MB):%.5f FileCache:%d\n " , float64 (stats .BlockCacheSize )/ 1048576.0 , stats .OpenedTablesCount )
289+ message += fmt .Sprintf ("MemoryCompaction:%d Level0Compaction:%d NonLevel0Compaction:%d SeekCompaction:%d\n " , stats .MemComp , stats .Level0Comp , stats .NonLevel0Comp , stats .SeekComp )
290+ message += fmt .Sprintf ("WriteDelayCount:%d WriteDelayDuration:%s Paused:%t\n " , stats .WriteDelayCount , common .PrettyDuration (stats .WriteDelayDuration ), stats .WritePaused )
291+ message += fmt .Sprintf ("Snapshots:%d Iterators:%d\n " , stats .AliveSnapshots , stats .AliveIterators )
292+ return message , nil
255293}
256294
257295// Compact flattens the underlying data store for the given key range. In essence,
0 commit comments