From 5596b664c4ca5be199bb93f87155fa2c1fa7eab2 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 11 Sep 2017 09:33:18 +0200 Subject: [PATCH] internal/debug: add debug_freeOSMemory (#15122) --- internal/debug/api.go | 5 ++ internal/web3ext/web3ext.go | 132 +++++++++++++++++------------------- 2 files changed, 67 insertions(+), 70 deletions(-) diff --git a/internal/debug/api.go b/internal/debug/api.go index 8b7693f6a4..7583878ed5 100644 --- a/internal/debug/api.go +++ b/internal/debug/api.go @@ -176,6 +176,11 @@ func (*HandlerT) Stacks() string { return string(buf) } +// FreeOSMemory returns unused memory to the OS. +func (*HandlerT) FreeOSMemory() { + debug.FreeOSMemory() +} + func writeProfile(name, file string) error { p := pprof.Lookup(name) log.Info("Writing profile records", "count", p.Count(), "type", name, "dump", file) diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index bf1db88196..927085b441 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -34,58 +34,56 @@ var Modules = map[string]string{ const Chequebook_JS = ` web3._extend({ - property: 'chequebook', - methods: - [ - new web3._extend.Method({ - name: 'deposit', - call: 'chequebook_deposit', - params: 1, - inputFormatter: [null] - }), - new web3._extend.Property({ + property: 'chequebook', + methods: [ + new web3._extend.Method({ + name: 'deposit', + call: 'chequebook_deposit', + params: 1, + inputFormatter: [null] + }), + new web3._extend.Property({ name: 'balance', getter: 'chequebook_balance', - outputFormatter: web3._extend.utils.toDecimal + outputFormatter: web3._extend.utils.toDecimal }), - new web3._extend.Method({ - name: 'cash', - call: 'chequebook_cash', - params: 1, - inputFormatter: [null] - }), - new web3._extend.Method({ - name: 'issue', - call: 'chequebook_issue', - params: 2, - inputFormatter: [null, null] - }), - ] + new web3._extend.Method({ + name: 'cash', + call: 'chequebook_cash', + params: 1, + inputFormatter: [null] + }), + new web3._extend.Method({ + name: 'issue', + call: 'chequebook_issue', + params: 2, + inputFormatter: [null, null] + }), + ] }); ` const Clique_JS = ` web3._extend({ - property: 'clique', - methods: - [ + property: 'clique', + methods: [ new web3._extend.Method({ name: 'getSnapshot', call: 'clique_getSnapshot', params: 1, - inputFormatter: [null] + inputFormatter: [null] }), new web3._extend.Method({ name: 'getSnapshotAtHash', call: 'clique_getSnapshotAtHash', params: 1 }), - new web3._extend.Method({ - name: 'getSigners', - call: 'clique_getSigners', - params: 1, - inputFormatter: [null] - }), + new web3._extend.Method({ + name: 'getSigners', + call: 'clique_getSigners', + params: 1, + inputFormatter: [null] + }), new web3._extend.Method({ name: 'getSignersAtHash', call: 'clique_getSignersAtHash', @@ -100,10 +98,9 @@ web3._extend({ name: 'discard', call: 'clique_discard', params: 1 - }) - ], - properties: - [ + }), + ], + properties: [ new web3._extend.Property({ name: 'proposals', getter: 'clique_proposals' @@ -115,8 +112,7 @@ web3._extend({ const Admin_JS = ` web3._extend({ property: 'admin', - methods: - [ + methods: [ new web3._extend.Method({ name: 'addPeer', call: 'admin_addPeer', @@ -162,10 +158,9 @@ web3._extend({ new web3._extend.Method({ name: 'stopWS', call: 'admin_stopWS' - }) + }), ], - properties: - [ + properties: [ new web3._extend.Property({ name: 'nodeInfo', getter: 'admin_nodeInfo' @@ -177,7 +172,7 @@ web3._extend({ new web3._extend.Property({ name: 'datadir', getter: 'admin_datadir' - }) + }), ] }); ` @@ -185,8 +180,7 @@ web3._extend({ const Debug_JS = ` web3._extend({ property: 'debug', - methods: - [ + methods: [ new web3._extend.Method({ name: 'printBlock', call: 'debug_printBlock', @@ -268,6 +262,11 @@ web3._extend({ params: 0, outputFormatter: console.log }), + new web3._extend.Method({ + name: 'freeOSMemory', + call: 'debug_freeOSMemory', + params: 0, + }), new web3._extend.Method({ name: 'memStats', call: 'debug_memStats', @@ -358,8 +357,7 @@ web3._extend({ const Eth_JS = ` web3._extend({ property: 'eth', - methods: - [ + methods: [ new web3._extend.Method({ name: 'sign', call: 'eth_sign', @@ -396,10 +394,9 @@ web3._extend({ }, params: 2, inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex] - }) + }), ], - properties: - [ + properties: [ new web3._extend.Property({ name: 'pendingTransactions', getter: 'eth_pendingTransactions', @@ -411,7 +408,7 @@ web3._extend({ } return formatted; } - }) + }), ] }); ` @@ -419,8 +416,7 @@ web3._extend({ const Miner_JS = ` web3._extend({ property: 'miner', - methods: - [ + methods: [ new web3._extend.Method({ name: 'start', call: 'miner_start', @@ -451,7 +447,7 @@ web3._extend({ new web3._extend.Method({ name: 'getHashrate', call: 'miner_getHashrate' - }) + }), ], properties: [] }); @@ -461,12 +457,11 @@ const Net_JS = ` web3._extend({ property: 'net', methods: [], - properties: - [ + properties: [ new web3._extend.Property({ name: 'version', getter: 'net_version' - }) + }), ] }); ` @@ -474,8 +469,7 @@ web3._extend({ const Personal_JS = ` web3._extend({ property: 'personal', - methods: - [ + methods: [ new web3._extend.Method({ name: 'importRawKey', call: 'personal_importRawKey', @@ -501,14 +495,13 @@ web3._extend({ name: 'deriveAccount', call: 'personal_deriveAccount', params: 3 - }) + }), ], - properties: - [ + properties: [ new web3._extend.Property({ name: 'listWallets', getter: 'personal_listWallets' - }) + }), ] }) ` @@ -517,12 +510,11 @@ const RPC_JS = ` web3._extend({ property: 'rpc', methods: [], - properties: - [ + properties: [ new web3._extend.Property({ name: 'modules', getter: 'rpc_modules' - }) + }), ] }); ` @@ -633,7 +625,7 @@ web3._extend({ name: 'newMessageFilter', call: 'shh_newMessageFilter', params: 1 - }) + }), ], properties: [ @@ -669,7 +661,7 @@ web3._extend({ name: 'listmounts', call: 'swarmfs_listmounts', params: 0 - }) + }), ] }); ` @@ -696,7 +688,7 @@ web3._extend({ status.queued = web3._extend.utils.toDecimal(status.queued); return status; } - }) + }), ] }); `