Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
2bb5ec1e
Unverified
Commit
2bb5ec1e
authored
Oct 18, 2016
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/geth, trie: track and report trie cache misses
parent
c9471e77
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
4 deletions
+28
-4
chaincmd.go
cmd/geth/chaincmd.go
+14
-4
trie.go
trie/trie.go
+14
-0
No files found.
cmd/geth/chaincmd.go
View file @
2bb5ec1e
...
...
@@ -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/ethereum/go-ethereum/trie"
"github.com/syndtr/goleveldb/leveldb/util"
"gopkg.in/urfave/cli.v1"
)
...
...
@@ -89,21 +90,30 @@ func importChain(ctx *cli.Context) error {
if
err
:=
utils
.
ImportChain
(
chain
,
ctx
.
Args
()
.
First
());
err
!=
nil
{
utils
.
Fatalf
(
"Import error: %v"
,
err
)
}
fmt
.
Printf
(
"Import done in %v
, compacting..
.
\n
"
,
time
.
Since
(
start
))
fmt
.
Printf
(
"Import done in %v.
\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
{
// Output pre-compaction stats mostly to see the import trashing
stats
,
err
:=
db
.
LDB
()
.
GetProperty
(
"leveldb.stats"
)
if
err
!=
nil
{
utils
.
Fatalf
(
"Failed to read database stats: %v"
,
err
)
}
fmt
.
Println
(
stats
)
// Compact the entire database to more accurately measure disk io and print the stats
start
=
time
.
Now
()
if
err
:=
db
.
LDB
()
.
CompactRange
(
util
.
Range
{});
err
!=
nil
{
fmt
.
Println
(
"Compacting entire database..."
)
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"
)
stats
,
err
=
db
.
LDB
()
.
GetProperty
(
"leveldb.stats"
)
if
err
!=
nil
{
utils
.
Fatalf
(
"Failed to read database stats: %v"
,
err
)
}
fmt
.
Println
(
stats
)
fmt
.
Println
(
"Trie cache misses:"
,
trie
.
CacheMisses
())
}
return
nil
}
...
...
trie/trie.go
View file @
2bb5ec1e
...
...
@@ -20,6 +20,7 @@ package trie
import
(
"bytes"
"fmt"
"sync/atomic"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/sha3"
...
...
@@ -34,6 +35,17 @@ var (
emptyState
common
.
Hash
)
// cacheMisses maintains the number of times a trie node was loaded from disk.
// Always use atomic operations when accessing this global variable.
var
cacheMisses
uint64
// CacheMisses retrieves a global counter measuring the number of cache misses
// the trie did since process startup. This isn't useful for anything apart from
// trie debugging purposes.
func
CacheMisses
()
uint64
{
return
atomic
.
LoadUint64
(
&
cacheMisses
)
}
func
init
()
{
sha3
.
NewKeccak256
()
.
Sum
(
emptyState
[
:
0
])
}
...
...
@@ -419,6 +431,8 @@ func (t *Trie) resolve(n node, prefix, suffix []byte) (node, error) {
}
func
(
t
*
Trie
)
resolveHash
(
n
hashNode
,
prefix
,
suffix
[]
byte
)
(
node
,
error
)
{
atomic
.
AddUint64
(
&
cacheMisses
,
1
)
enc
,
err
:=
t
.
db
.
Get
(
n
)
if
err
!=
nil
||
enc
==
nil
{
return
nil
,
&
MissingNodeError
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment