diff --git a/.gitignore b/.gitignore index a75301c6..2d125746 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .nyc_output .vscode +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index b617c9a8..a327baa7 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Programmable interface to [Clinic.js][clinic-url] Flame. Learn more about Clinic ## Supported node versions -* Node.js 8 and above +* Node.js 10 and above ## Example @@ -41,6 +41,7 @@ const flame = new ClinicFlame() **Default**: false * dest [``][] The folder where the collected data is stored. **Default**: '.' + * collectDelay [``][] **Default**: 0 #### `flame.collect(args, callback)` @@ -76,5 +77,6 @@ possible error. [``]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object [``]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type [``]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String +[``]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number [azure-status]: https://dev.azure.com/node-clinic/node-clinic/_apis/build/status/nearform.node-clinic-doctor [azure-url]: https://dev.azure.com/node-clinic/node-clinic/_apis/build/status/nearform.node-clinic-doctor?branchName=master diff --git a/azure-pipelines-npm-template.yml b/azure-pipelines-npm-template.yml index 682ebf41..f36a7f9b 100644 --- a/azure-pipelines-npm-template.yml +++ b/azure-pipelines-npm-template.yml @@ -20,7 +20,9 @@ jobs: inputs: versionSpec: $(node_version) displayName: Install Node.js - - bash: npm i + - bash: | + npm install + npm ls displayName: Install dependencies - bash: npm run ci-lint displayName: Check linting diff --git a/index.js b/index.js index 023a716c..adce4b55 100644 --- a/index.js +++ b/index.js @@ -19,11 +19,13 @@ class ClinicFlame extends events.EventEmitter { super() const { + collectDelay = 0, detectPort = false, debug = false, dest = null } = settings + this.collectDelay = collectDelay this.detectPort = detectPort this.debug = debug this.path = dest @@ -37,7 +39,6 @@ class ClinicFlame extends events.EventEmitter { path: this.path, identifier: '{pid}' // replaced with actual pid by 0x }) - callbackify(x({ argv, onPort: this.detectPort ? onPort : undefined, @@ -48,7 +49,8 @@ class ClinicFlame extends events.EventEmitter { collectOnly: true, writeTicks: true, outputDir: paths['/0x-data/'], - workingDir: '.' // 0x temporary working files, doesn't support placeholders like {pid} + workingDir: '.', // 0x temporary working files, doesn't support placeholders like {pid} + collectDelay: this.collectDelay }), done) function done (err, dir) { diff --git a/package.json b/package.json index 6eab52c4..22676a9a 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "author": "", "license": "GPL-3.0-or-later", "dependencies": { - "0x": "^4.9.1", + "0x": "DylanC/0x#collect_timeout_feature", "@nearform/clinic-common": "^2.2.0", "copy-to-clipboard": "^3.0.8", "d3-array": "^2.0.2", diff --git a/test/cmd-collect-delay.test.js b/test/cmd-collect-delay.test.js new file mode 100644 index 00000000..f31a243b --- /dev/null +++ b/test/cmd-collect-delay.test.js @@ -0,0 +1,52 @@ +const fs = require('fs') +const path = require('path') +const { test } = require('tap') +const rimraf = require('rimraf') +const ClinicFlame = require('../index.js') + +test('cmd - test collect - 1s collect delay', (t) => { + const tool = new ClinicFlame({ debug: true, collectDelay: 2000 }) + + function cleanup (err, dirname) { + t.ifError(err) + t.match(dirname, /^[0-9]+\.clinic-flame$/) + + rimraf(dirname, (err) => { + t.ifError(err) + t.end() + }) + } + + function countFn (ticks, name) { + return ticks.reduce((total, tick) => { + return tick.reduce((acc, frame) => { + if (frame.name.includes(name)) { + return acc + 1 + } + return acc + }, total) + }, 0) + } + + tool.collect( + [process.execPath, path.join('test', 'fixtures', 'delay.js')], + function (err, dirname) { + if (err) return cleanup(err, dirname) + + const getLoggingPaths = require('../collect/get-logging-paths') + const analyse = require('../analysis') + const paths = getLoggingPaths({ path: dirname }) + analyse(paths).then((result) => { + const ticks = JSON.parse(fs.readFileSync(paths['/samples'], 'utf8')) + t.comment(`first ticks delays are: ${ticks[0].map(frame => frame.tm)}`) + + const c1 = countFn(ticks, 'delayOneSecond') + t.equal(c1, 0, `delayOneSecond showed up ${c1} times out of ${ticks.length} ticks`) + const c2 = countFn(ticks, 'delayTwoSecond') + t.ok(c2 > 0, `delayTwoSecond showed up ${c2} times`) + + cleanup(null, dirname) + }) + } + ) +}) diff --git a/test/fixtures/delay.js b/test/fixtures/delay.js new file mode 100644 index 00000000..be94fc16 --- /dev/null +++ b/test/fixtures/delay.js @@ -0,0 +1,15 @@ +const syncWait = ms => { + const end = Date.now() + ms + while (Date.now() < end) continue +} + +function delayOneSecond () { + syncWait(1000) +} + +function delayTwoSecond () { + syncWait(2000) +} + +delayOneSecond() +delayTwoSecond() diff --git a/visualizer/assets/icons/.DS_Store b/visualizer/assets/icons/.DS_Store deleted file mode 100644 index 5008ddfc..00000000 Binary files a/visualizer/assets/icons/.DS_Store and /dev/null differ