diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-10-18 19:09:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-18 19:09:02 +0800 |
commit | e8d0538a0013664021d52d289688f6c7d7bf31ff (patch) | |
tree | cfb4f4918886b0980a482ae5d2883686415b2e6f | |
parent | a64b1b4375828a0682d92ae07c90ff1dcb06c50d (diff) | |
parent | a1c63e8be6efbdfd165d569a4ea8c16ad73d5305 (diff) | |
download | go-tangerine-e8d0538a0013664021d52d289688f6c7d7bf31ff.tar go-tangerine-e8d0538a0013664021d52d289688f6c7d7bf31ff.tar.gz go-tangerine-e8d0538a0013664021d52d289688f6c7d7bf31ff.tar.bz2 go-tangerine-e8d0538a0013664021d52d289688f6c7d7bf31ff.tar.lz go-tangerine-e8d0538a0013664021d52d289688f6c7d7bf31ff.tar.xz go-tangerine-e8d0538a0013664021d52d289688f6c7d7bf31ff.tar.zst go-tangerine-e8d0538a0013664021d52d289688f6c7d7bf31ff.zip |
Merge pull request #3160 from karalabe/import-database-stats
cmd/geth: compact and print database stats after an import
-rw-r--r-- | cmd/geth/chaincmd.go | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 553e5367c..5ef278a64 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -31,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/logger/glog" + "github.com/syndtr/goleveldb/leveldb/util" "gopkg.in/urfave/cli.v1" ) @@ -81,13 +82,29 @@ func importChain(ctx *cli.Context) error { } stack := makeFullNode(ctx) chain, chainDb := utils.MakeChain(ctx, stack) + defer chainDb.Close() + + // Import the chain start := time.Now() - err := utils.ImportChain(chain, ctx.Args().First()) - chainDb.Close() - if err != nil { + if err := utils.ImportChain(chain, ctx.Args().First()); err != nil { utils.Fatalf("Import error: %v", err) } - fmt.Printf("Import done in %v", time.Since(start)) + fmt.Printf("Import done in %v, compacting...\n", time.Since(start)) + + // Compact the entire database to more accurately measure disk io and print the stats + if db, ok := chainDb.(*ethdb.LDBDatabase); ok { + start = time.Now() + if err := db.LDB().CompactRange(util.Range{}); err != nil { + utils.Fatalf("Compaction failed: %v", err) + } + fmt.Printf("Compaction done in %v.\n", time.Since(start)) + + stats, err := db.LDB().GetProperty("leveldb.stats") + if err != nil { + utils.Fatalf("Failed to read database stats: %v", err) + } + fmt.Println(stats) + } return nil } |