From 8e2b0f2456ec64cc2a6935f5ccd4071e84d4f64c Mon Sep 17 00:00:00 2001 From: Marcos Dione Date: Fri, 28 Jul 2017 09:24:56 +0200 Subject: [PATCH 1/4] Current status: -p/--profile option starts v8 compatible profiling. --- bin/carto | 25 ++++++++++++++++++++----- package.json | 8 +++++++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/bin/carto b/bin/carto index a789781e8..952767fd9 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) { + const 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,15 @@ if (ext === '.mml') { console.error("carto: please pass either a .mml file or .mss file"); } +if (options.profile) { + const fs = require('fs'); + const 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", From f95bb9207d2f285f8e0a7448c871c3cf580f1b20 Mon Sep 17 00:00:00 2001 From: Marcos Dione Date: Fri, 28 Jul 2017 21:24:48 +0200 Subject: [PATCH 2/4] Already imported. --- bin/carto | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/carto b/bin/carto index 952767fd9..d1b117694 100755 --- a/bin/carto +++ b/bin/carto @@ -83,7 +83,6 @@ if (ext === '.mml') { } if (options.profile) { - const fs = require('fs'); const profile = profiler.stopProfiling('carto'); profile.export(function(error, result) { From b077c3813a95289d74250e2b74fac1352837b315 Mon Sep 17 00:00:00 2001 From: Marcos Dione Date: Fri, 28 Jul 2017 21:26:03 +0200 Subject: [PATCH 3/4] s/const/var/, because we are still using ES5. --- bin/carto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/carto b/bin/carto index d1b117694..df5e1e106 100755 --- a/bin/carto +++ b/bin/carto @@ -83,7 +83,7 @@ if (ext === '.mml') { } if (options.profile) { - const profile = profiler.stopProfiling('carto'); + var profile = profiler.stopProfiling('carto'); profile.export(function(error, result) { fs.writeFileSync('carto.cpuprofile', result); From 1f3ca6a414f28f1884ca1748c7f33604495e7e76 Mon Sep 17 00:00:00 2001 From: Marcos Dione Date: Sat, 29 Jul 2017 20:23:24 +0200 Subject: [PATCH 4/4] Fix profiling. --- bin/carto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/carto b/bin/carto index df5e1e106..c92b553f1 100755 --- a/bin/carto +++ b/bin/carto @@ -69,7 +69,7 @@ try { } if (options.profile) { - const profiler = require('v8-profiler'); + var profiler = require('v8-profiler'); profiler.startProfiling('carto'); }