diff --git a/bin/carto b/bin/carto index a789781e8..c92b553f1 100755 --- a/bin/carto +++ b/bin/carto @@ -11,16 +11,17 @@ var existsSync = require('fs').existsSync || require('path').existsSync var yargs = require('yargs') .usage("Usage: $0 ") - .options('h', {alias:'help', describe:'Display this help message'}) - .options('v', {alias:'version', boolean:true, describe:'Display version information'}) + .options('a', {alias:'api', describe:'Specify Mapnik API version'}) .options('b', {alias:'benchmark', boolean:true, describe:'Outputs total compile time'}) + .options('f', {alias:'file', describe:'Outputs to the given file instead of stdout.'}) + .options('h', {alias:'help', describe:'Display this help message'}) .options('l', {alias:'localize', boolean:true, default:false, describe:'Use millstone to localize resources when loading an MML'}) .options('n', {alias:'nosymlink', boolean:true, describe:'Use absolute paths instead of symlinking files'}) - .options('a', {alias:'api', describe:'Specify Mapnik API version'}) - .options('f', {alias:'file', describe:'Outputs to the given file instead of stdout.'}) .options('o', {alias:'output', describe:'Specify output format (mapnik, json)', default:'mapnik'}) + .options('p', {alias:'profile', boolean:true, default:false, describe:'Generate v8 profile data that can be loaded in chromium/chrome\'s profiler for inspection.'}) .options('q', {alias:'quiet', boolean:true, default:false, describe:'Do not output any warnings'}) - .options('ppi', {describe:'Pixels per inch used to convert m, mm, cm, in, pt, pc to pixels', default:90.714}); + .options('ppi', {describe:'Pixels per inch used to convert m, mm, cm, in, pt, pc to pixels', default:90.714}) + .options('v', {alias:'version', boolean:true, describe:'Display version information'}); var options = yargs.argv; @@ -67,6 +68,11 @@ try { process.exit(1); } +if (options.profile) { + var profiler = require('v8-profiler'); + profiler.startProfiling('carto'); +} + if (ext === '.mml') { var mml = new carto.MML(options); mml.load(path.dirname(input), data, compile); @@ -76,6 +82,14 @@ if (ext === '.mml') { console.error("carto: please pass either a .mml file or .mss file"); } +if (options.profile) { + var profile = profiler.stopProfiling('carto'); + + profile.export(function(error, result) { + fs.writeFileSync('carto.cpuprofile', result); + profile.delete(); + }) +} function compile(err, data) { if (err) { diff --git a/package.json b/package.json index cac7f9a41..def318740 100644 --- a/package.json +++ b/package.json @@ -42,11 +42,17 @@ "yargs": "~8.0.1" }, "devDependencies": { + "core-util-is": "^1.0.2", "coveralls": "~2.13.1", + "inherits": "^2.0.3", "istanbul": "~0.4.5", "mocha": "~3.4.1", "mocha-eslint": "^4.0.0", - "sax": "~1.2.1" + "npm": "^5.3.0", + "readable-stream": "^2.3.3", + "sax": "~1.2.1", + "util-deprecate": "^1.0.2", + "v8-profiler": "^5.7.0" }, "scripts": { "pretest": "npm install && mocha -R spec --timeout 50000 -f jslint",