Merge pull request #399 from embark-framework/profileMeSir

Profile me officer
This commit is contained in:
Iuri Matias 2018-05-08 13:35:37 -04:00 committed by GitHub
commit a6bb44c20f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 113 additions and 45 deletions

View File

@ -16,6 +16,10 @@ class Deploy {
this.chainConfig = options.chainConfig;
this.plugins = options.plugins;
this.gasLimit = options.gasLimit;
this.events.setCommandHandler("contracts:contract", (contractName, cb) => {
cb(this.contractsManager.getContract(contractName));
});
}
initTracker(cb) {

View File

@ -187,6 +187,10 @@ class Engine {
this.registerModule('vyper', {
contractDirectories: self.config.contractDirectories
});
this.registerModule('profiler', {
events: this.events,
logger: this.logger
});
this.contractsManager = new ContractsManager({
contractFiles: this.config.contractsFiles,

View File

@ -0,0 +1,56 @@
const asciiTable = require('ascii-table');
class Profiler {
constructor(embark) {
this.embark = embark;
this.logger = embark.logger;
this.events = embark.events;
this.plugins = embark.plugins;
this.registerConsoleCommand();
}
profile(contractName, contract) {
const self = this;
let table = new asciiTable(contractName);
table.setHeading('Function', 'Payable', 'Mutability', 'Inputs', 'Outputs');
contract.abiDefinition.forEach((abiMethod) => {
switch(abiMethod.type) {
case "constructor":
table.addRow("constructor", abiMethod.payable, abiMethod.stateMutability, this.formatParams(abiMethod.inputs), this.formatParams(abiMethod.outputs));
break;
default:
table.addRow(abiMethod.name, abiMethod.payable, abiMethod.stateMutability, this.formatParams(abiMethod.inputs), this.formatParams(abiMethod.outputs));
}
});
self.logger.info(table.toString());
}
formatParams(params) {
if (!params || !params.length) {
return "()";
}
let paramString = "(";
let mappedParams = params.map(param => param.type);
paramString += mappedParams.join(',');
paramString += ")";
return paramString;
}
registerConsoleCommand() {
const self = this;
self.embark.registerConsoleCommand((cmd, _options) => {
let cmdName = cmd.split(' ')[0];
let contractName = cmd.split(' ')[1];
if (cmdName === 'profile') {
self.events.request('contracts:contract', contractName, (contract) => {
self.logger.info("-- profile for " + contractName);
this.profile(contractName, contract);
});
return "profiled...";
}
});
}
}
module.exports = Profiler;

93
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "embark",
"version": "3.0.0",
"version": "3.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -463,6 +463,11 @@
"integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=",
"dev": true
},
"ascii-table": {
"version": "0.0.9",
"resolved": "https://registry.npmjs.org/ascii-table/-/ascii-table-0.0.9.tgz",
"integrity": "sha1-BqZgTWpV1L9BqaR9mHLXp42jHnM="
},
"asn1": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz",
@ -3512,7 +3517,7 @@
"fsevents": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.1.3.tgz",
"integrity": "sha1-EfgjGPX+e7LNIpZaEI6TBiCCFtg=",
"integrity": "sha512-WIr7iDkdmdbxu/Gh6eKEZJL6KPE74/5MEsf2whTOFNxbIoIixogroLdKYqB6FDav4Wavh/lZdzzd3b2KxIXC5Q==",
"optional": true,
"requires": {
"nan": "2.9.2",
@ -3759,9 +3764,9 @@
"integrity": "sha1-M8GDrPGTJ27KqYFDpp6Uv+4XUNE=",
"optional": true,
"requires": {
"asynckit": "0.4.0",
"combined-stream": "1.0.5",
"mime-types": "2.1.15"
"asynckit": "^0.4.0",
"combined-stream": "^1.0.5",
"mime-types": "^2.1.12"
}
},
"fs.realpath": {
@ -3854,8 +3859,8 @@
"integrity": "sha1-M0gdDxu/9gDdID11gSpqX7oALio=",
"optional": true,
"requires": {
"ajv": "4.11.8",
"har-schema": "1.0.5"
"ajv": "^4.9.1",
"har-schema": "^1.0.5"
}
},
"has-unicode": {
@ -3916,7 +3921,7 @@
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
"requires": {
"number-is-nan": "1.0.1"
"number-is-nan": "^1.0.0"
}
},
"is-typedarray": {
@ -4008,7 +4013,7 @@
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.15.tgz",
"integrity": "sha1-pOv1BkCUVpI3uM9wBGd20J/JKu0=",
"requires": {
"mime-db": "1.27.0"
"mime-db": "~1.27.0"
}
},
"minimatch": {
@ -4016,7 +4021,7 @@
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"requires": {
"brace-expansion": "1.1.7"
"brace-expansion": "^1.1.7"
}
},
"minimist": {
@ -5979,19 +5984,19 @@
"resolved": "https://registry.npmjs.org/libp2p-crypto/-/libp2p-crypto-0.8.8.tgz",
"integrity": "sha1-3IpJy87bUjnel3YZ8tGN+fwRDzk=",
"requires": {
"asn1.js": "4.10.1",
"async": "2.6.0",
"browserify-aes": "1.1.1",
"keypair": "1.0.1",
"libp2p-crypto-secp256k1": "0.1.4",
"multihashing-async": "0.4.8",
"node-webcrypto-ossl": "1.0.35",
"nodeify": "1.0.1",
"pem-jwk": "1.5.1",
"protocol-buffers": "3.2.1",
"rsa-pem-to-jwk": "1.1.3",
"safe-buffer": "5.1.1",
"tweetnacl": "1.0.0",
"asn1.js": "^4.9.1",
"async": "^2.1.5",
"browserify-aes": "^1.0.6",
"keypair": "^1.0.1",
"libp2p-crypto-secp256k1": "^0.1.4",
"multihashing-async": "~0.4.4",
"node-webcrypto-ossl": "^1.0.21",
"nodeify": "^1.0.1",
"pem-jwk": "^1.5.1",
"protocol-buffers": "^3.2.1",
"rsa-pem-to-jwk": "^1.1.3",
"safe-buffer": "^5.0.1",
"tweetnacl": "^1.0.0-rc.1",
"webcrypto-shim": "github:dignifiedquire/webcrypto-shim#190bc9ec341375df6025b17ae12ddb2428ea49c8"
}
},
@ -6000,12 +6005,12 @@
"resolved": "https://registry.npmjs.org/libp2p-crypto-secp256k1/-/libp2p-crypto-secp256k1-0.1.4.tgz",
"integrity": "sha1-IRN4/jqFnYmtEgOqng111obIW98=",
"requires": {
"async": "2.6.0",
"libp2p-crypto": "0.8.8",
"multihashing-async": "0.4.8",
"nodeify": "1.0.1",
"safe-buffer": "5.1.1",
"secp256k1": "3.5.0"
"async": "^2.1.4",
"libp2p-crypto": "~0.8.4",
"multihashing-async": "~0.4.2",
"nodeify": "^1.0.0",
"safe-buffer": "^5.0.1",
"secp256k1": "^3.2.5"
}
}
}
@ -6056,9 +6061,9 @@
}
},
"minipass": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-2.2.4.tgz",
"integrity": "sha512-hzXIWWet/BzWhYs2b+u7dRHlruXhwdgvlTMDKC6Cb1U7ps6Ac6yQlR39xsbjWJE377YTCtKwIXIpJ5oP+j5y8g==",
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.0.tgz",
"integrity": "sha512-jWC2Eg+Np4bxah7llu1IrUNSJQxtLz/J+pOjTM0nFpJXGAaV18XBWhUn031Q1tAA/TJtA1jgwnOe9S2PQa4Lbg==",
"requires": {
"safe-buffer": "5.1.2",
"yallist": "3.0.2"
@ -6076,7 +6081,7 @@
"requires": {
"chownr": "1.0.1",
"fs-minipass": "1.2.5",
"minipass": "2.2.4",
"minipass": "2.3.0",
"minizlib": "1.1.0",
"mkdirp": "0.5.1",
"safe-buffer": "5.1.2",
@ -11272,13 +11277,22 @@
"requires": {
"underscore": "1.8.3",
"web3-core-helpers": "1.0.0-beta.34",
"websocket": "1.0.25"
"websocket": "git://github.com/frozeman/WebSocket-Node.git#7004c39c42ac98875ab61126e5b4a925430f592c"
},
"dependencies": {
"underscore": {
"version": "1.8.3",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz",
"integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI="
},
"websocket": {
"version": "git://github.com/frozeman/WebSocket-Node.git#7004c39c42ac98875ab61126e5b4a925430f592c",
"requires": {
"debug": "2.6.9",
"nan": "2.9.2",
"typedarray-to-buffer": "3.1.5",
"yaeti": "0.0.6"
}
}
}
},
@ -11404,17 +11418,6 @@
}
}
},
"websocket": {
"version": "1.0.25",
"resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.25.tgz",
"integrity": "sha512-M58njvi6ZxVb5k7kpnHh2BvNKuBWiwIYvsToErBzWhvBZYwlEiLcyLrG41T1jRcrY9ettqPYEqduLI7ul54CVQ==",
"requires": {
"debug": "2.6.9",
"nan": "2.9.2",
"typedarray-to-buffer": "3.1.5",
"yaeti": "0.0.6"
}
},
"whet.extend": {
"version": "0.9.9",
"resolved": "https://registry.npmjs.org/whet.extend/-/whet.extend-0.9.9.tgz",

View File

@ -21,6 +21,7 @@
"url": "https://github.com/iurimatias/embark-framework.git"
},
"dependencies": {
"ascii-table": "0.0.9",
"async": "^2.0.1",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",