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
e50e3bea
Commit
e50e3bea
authored
Apr 13, 2016
by
Felix Lange
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2235 from fjl/chaindb-api-and-console-fixes
eth: add chaindbProperty to debug API (+ console fixes)
parents
b34b130f
bea56d84
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
78 additions
and
14 deletions
+78
-14
api.go
eth/api.go
+18
-0
api.go
internal/debug/api.go
+15
-0
completion.go
jsre/completion.go
+15
-4
completion_test.go
jsre/completion_test.go
+5
-1
jsre.go
jsre/jsre.go
+8
-8
pretty.go
jsre/pretty.go
+1
-1
javascript.go
rpc/javascript.go
+16
-0
No files found.
eth/api.go
View file @
e50e3bea
...
...
@@ -26,6 +26,7 @@ import (
"math/big"
"os"
"runtime"
"strings"
"sync"
"time"
...
...
@@ -46,6 +47,7 @@ import (
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/syndtr/goleveldb/leveldb"
"golang.org/x/net/context"
)
...
...
@@ -1566,6 +1568,22 @@ func NewPrivateDebugAPI(config *core.ChainConfig, eth *Ethereum) *PrivateDebugAP
return
&
PrivateDebugAPI
{
config
:
config
,
eth
:
eth
}
}
// ChaindbProperty returns leveldb properties of the chain database.
func
(
api
*
PrivateDebugAPI
)
ChaindbProperty
(
property
string
)
(
string
,
error
)
{
ldb
,
ok
:=
api
.
eth
.
chainDb
.
(
interface
{
LDB
()
*
leveldb
.
DB
})
if
!
ok
{
return
""
,
fmt
.
Errorf
(
"chaindbProperty does not work for memory databases"
)
}
if
property
==
""
{
property
=
"leveldb.stats"
}
else
if
!
strings
.
HasPrefix
(
property
,
"leveldb."
)
{
property
=
"leveldb."
+
property
}
return
ldb
.
LDB
()
.
GetProperty
(
property
)
}
// BlockTraceResults is the returned value when replaying a block to check for
// consensus results and full VM trace logs for all included transactions.
type
BlockTraceResult
struct
{
...
...
internal/debug/api.go
View file @
e50e3bea
...
...
@@ -27,6 +27,7 @@ import (
"os/user"
"path/filepath"
"runtime"
"runtime/debug"
"runtime/pprof"
"strings"
"sync"
...
...
@@ -69,6 +70,20 @@ func (*HandlerT) BacktraceAt(location string) error {
return
glog
.
GetTraceLocation
()
.
Set
(
location
)
}
// MemStats returns detailed runtime memory statistics.
func
(
*
HandlerT
)
MemStats
()
*
runtime
.
MemStats
{
s
:=
new
(
runtime
.
MemStats
)
runtime
.
ReadMemStats
(
s
)
return
s
}
// GcStats returns GC statistics.
func
(
*
HandlerT
)
GcStats
()
*
debug
.
GCStats
{
s
:=
new
(
debug
.
GCStats
)
debug
.
ReadGCStats
(
s
)
return
s
}
// CpuProfile turns on CPU profiling for nsec seconds and writes
// profile data to file.
func
(
h
*
HandlerT
)
CpuProfile
(
file
string
,
nsec
uint
)
error
{
...
...
jsre/completion.go
View file @
e50e3bea
...
...
@@ -27,7 +27,9 @@ import (
// evaluated, callers need to make sure that evaluating line does not have side effects.
func
(
jsre
*
JSRE
)
CompleteKeywords
(
line
string
)
[]
string
{
var
results
[]
string
jsre
.
do
(
func
(
vm
*
otto
.
Otto
)
{
results
=
getCompletions
(
vm
,
line
)
})
jsre
.
Do
(
func
(
vm
*
otto
.
Otto
)
{
results
=
getCompletions
(
vm
,
line
)
})
return
results
}
...
...
@@ -53,9 +55,18 @@ func getCompletions(vm *otto.Otto, line string) (results []string) {
}
}
})
// e.g. web3<tab><tab> append dot since its an object
if
obj
,
_
=
vm
.
Object
(
line
);
obj
!=
nil
{
results
=
append
(
results
,
line
+
"."
)
// Append opening parenthesis (for functions) or dot (for objects)
// if the line itself is the only completion.
if
len
(
results
)
==
1
&&
results
[
0
]
==
line
{
obj
,
_
:=
vm
.
Object
(
line
)
if
obj
!=
nil
{
if
obj
.
Class
()
==
"Function"
{
results
[
0
]
+=
"("
}
else
{
results
[
0
]
+=
"."
}
}
}
sort
.
Strings
(
results
)
...
...
jsre/completion_test.go
View file @
e50e3bea
...
...
@@ -40,7 +40,11 @@ func TestCompleteKeywords(t *testing.T) {
}{
{
input
:
"x"
,
want
:
[]
string
{
"x"
,
"x."
},
want
:
[]
string
{
"x."
},
},
{
input
:
"x.someMethod"
,
want
:
[]
string
{
"x.someMethod("
},
},
{
input
:
"x."
,
...
...
jsre/jsre.go
View file @
e50e3bea
...
...
@@ -214,8 +214,8 @@ loop:
self
.
loopWg
.
Done
()
}
//
do schedules the given function on the
event loop.
func
(
self
*
JSRE
)
d
o
(
fn
func
(
*
otto
.
Otto
))
{
//
Do executes the given function on the JS
event loop.
func
(
self
*
JSRE
)
D
o
(
fn
func
(
*
otto
.
Otto
))
{
done
:=
make
(
chan
bool
)
req
:=
&
evalReq
{
fn
,
done
}
self
.
evalQueue
<-
req
...
...
@@ -235,7 +235,7 @@ func (self *JSRE) Exec(file string) error {
if
err
!=
nil
{
return
err
}
self
.
d
o
(
func
(
vm
*
otto
.
Otto
)
{
_
,
err
=
vm
.
Run
(
code
)
})
self
.
D
o
(
func
(
vm
*
otto
.
Otto
)
{
_
,
err
=
vm
.
Run
(
code
)
})
return
err
}
...
...
@@ -247,19 +247,19 @@ func (self *JSRE) Bind(name string, v interface{}) error {
// Run runs a piece of JS code.
func
(
self
*
JSRE
)
Run
(
code
string
)
(
v
otto
.
Value
,
err
error
)
{
self
.
d
o
(
func
(
vm
*
otto
.
Otto
)
{
v
,
err
=
vm
.
Run
(
code
)
})
self
.
D
o
(
func
(
vm
*
otto
.
Otto
)
{
v
,
err
=
vm
.
Run
(
code
)
})
return
v
,
err
}
// Get returns the value of a variable in the JS environment.
func
(
self
*
JSRE
)
Get
(
ns
string
)
(
v
otto
.
Value
,
err
error
)
{
self
.
d
o
(
func
(
vm
*
otto
.
Otto
)
{
v
,
err
=
vm
.
Get
(
ns
)
})
self
.
D
o
(
func
(
vm
*
otto
.
Otto
)
{
v
,
err
=
vm
.
Get
(
ns
)
})
return
v
,
err
}
// Set assigns value v to a variable in the JS environment.
func
(
self
*
JSRE
)
Set
(
ns
string
,
v
interface
{})
(
err
error
)
{
self
.
d
o
(
func
(
vm
*
otto
.
Otto
)
{
err
=
vm
.
Set
(
ns
,
v
)
})
self
.
D
o
(
func
(
vm
*
otto
.
Otto
)
{
err
=
vm
.
Set
(
ns
,
v
)
})
return
err
}
...
...
@@ -288,7 +288,7 @@ func (self *JSRE) loadScript(call otto.FunctionCall) otto.Value {
// EvalAndPrettyPrint evaluates code and pretty prints the result to
// standard output.
func
(
self
*
JSRE
)
EvalAndPrettyPrint
(
code
string
)
(
err
error
)
{
self
.
d
o
(
func
(
vm
*
otto
.
Otto
)
{
self
.
D
o
(
func
(
vm
*
otto
.
Otto
)
{
var
val
otto
.
Value
val
,
err
=
vm
.
Run
(
code
)
if
err
!=
nil
{
...
...
@@ -302,7 +302,7 @@ func (self *JSRE) EvalAndPrettyPrint(code string) (err error) {
// Compile compiles and then runs a piece of JS code.
func
(
self
*
JSRE
)
Compile
(
filename
string
,
src
interface
{})
(
err
error
)
{
self
.
d
o
(
func
(
vm
*
otto
.
Otto
)
{
_
,
err
=
compileAndRun
(
vm
,
filename
,
src
)
})
self
.
D
o
(
func
(
vm
*
otto
.
Otto
)
{
_
,
err
=
compileAndRun
(
vm
,
filename
,
src
)
})
return
err
}
...
...
jsre/pretty.go
View file @
e50e3bea
...
...
@@ -177,7 +177,7 @@ func (ctx ppctx) fields(obj *otto.Object) []string {
seen
=
make
(
map
[
string
]
bool
)
)
add
:=
func
(
k
string
)
{
if
seen
[
k
]
||
boringKeys
[
k
]
{
if
seen
[
k
]
||
boringKeys
[
k
]
||
strings
.
HasPrefix
(
k
,
"_"
)
{
return
}
seen
[
k
]
=
true
...
...
rpc/javascript.go
View file @
e50e3bea
...
...
@@ -295,6 +295,12 @@ web3._extend({
call: 'debug_dumpBlock',
params: 1
}),
new web3._extend.Method({
name: 'chaindbProperty',
call: 'debug_chaindbProperty',
params: 1,
outputFormatter: console.log
}),
new web3._extend.Method({
name: 'metrics',
call: 'debug_metrics',
...
...
@@ -321,6 +327,16 @@ web3._extend({
params: 0,
outputFormatter: console.log
}),
new web3._extend.Method({
name: 'memStats',
call: 'debug_memStats',
params: 0,
}),
new web3._extend.Method({
name: 'gcStats',
call: 'debug_gcStats',
params: 0,
}),
new web3._extend.Method({
name: 'cpuProfile',
call: 'debug_cpuProfile',
...
...
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