Skip to content

Commit

Permalink
internal/debug: add memStats and gcStats to API
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl committed Apr 13, 2016
1 parent bcd8aee commit bea56d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/debug/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"os/user"
"path/filepath"
"runtime"
"runtime/debug"
"runtime/pprof"
"strings"
"sync"
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions rpc/javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,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',
Expand Down

0 comments on commit bea56d8

Please sign in to comment.