From b965580d4d71907ab9b35d73b1bfd210bd1e961c Mon Sep 17 00:00:00 2001 From: Dylan Coakley Date: Tue, 11 Feb 2020 17:34:16 +0000 Subject: [PATCH 01/11] Add collectDelay argument for 0x --- cmd.js | 3 ++- index.js | 8 +++++++- schema.json | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd.js b/cmd.js index d632e58..8ad4ab5 100755 --- a/cmd.js +++ b/cmd.js @@ -65,7 +65,8 @@ async function cmd (argv, banner = defaultBanner) { treeDebug: 'tree-debug', writeTicks: 'write-ticks', onPort: 'on-port', - P: 'onPort' + P: 'onPort', + collectDelay: 'on-timeout' } }) diff --git a/index.js b/index.js index b5e3443..7030b20 100644 --- a/index.js +++ b/index.js @@ -24,9 +24,11 @@ async function zeroEks (args) { if (args.pathToNodeBinary === 'node') { args.pathToNodeBinary = pathTo('node') } + + args.collectDelay = args.collectDelay || 0 validate(args) - const { collectOnly, visualizeOnly, writeTicks, treeDebug, mapFrames, visualizeCpuProfile } = args + const { collectOnly, visualizeOnly, writeTicks, treeDebug, mapFrames, visualizeCpuProfile, collectDelay } = args let incompatibleOptions = 0 if (collectOnly) incompatibleOptions += 1 @@ -63,6 +65,10 @@ async function zeroEks (args) { return folder } + if (collectDelay) { + debug('data collection will be delayed by '+timeoutDelay+' ms') + } + try { const file = generateFlamegraph({ ...args, ticks, inlined, pid, folder }) return file diff --git a/schema.json b/schema.json index a0371cd..3376723 100644 --- a/schema.json +++ b/schema.json @@ -100,6 +100,9 @@ }, "P": { "type": "string" + }, + "collectDelay": { + "type": "number" }, "kernelTracing": { "type": "boolean" From e3a7a913551749d307076c8616c0eeee1e33538e Mon Sep 17 00:00:00 2001 From: Dylan Coakley Date: Wed, 12 Feb 2020 16:16:43 +0000 Subject: [PATCH 02/11] Add extra item to the schema for collect-delay --- schema.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/schema.json b/schema.json index 3376723..e17fbeb 100644 --- a/schema.json +++ b/schema.json @@ -101,6 +101,9 @@ "P": { "type": "string" }, + "collect-delay": { + "type": "number" + }, "collectDelay": { "type": "number" }, From 42e5102da87edd9ec17cb380567e0ae041b8db4f Mon Sep 17 00:00:00 2001 From: Dylan Coakley Date: Thu, 13 Feb 2020 16:22:48 +0000 Subject: [PATCH 03/11] Add collectDelay to filter the stacks --- index.js | 4 ++-- lib/v8-log-to-ticks.js | 7 +++++-- platform/v8.js | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 7030b20..3f23fb7 100644 --- a/index.js +++ b/index.js @@ -24,7 +24,7 @@ async function zeroEks (args) { if (args.pathToNodeBinary === 'node') { args.pathToNodeBinary = pathTo('node') } - + args.collectDelay = args.collectDelay || 0 validate(args) @@ -66,7 +66,7 @@ async function zeroEks (args) { } if (collectDelay) { - debug('data collection will be delayed by '+timeoutDelay+' ms') + debug('data collection will be delayed by ' + collectDelay + ' ms') } try { diff --git a/lib/v8-log-to-ticks.js b/lib/v8-log-to-ticks.js index 91b96fb..73ed887 100644 --- a/lib/v8-log-to-ticks.js +++ b/lib/v8-log-to-ticks.js @@ -69,7 +69,7 @@ function fixLines (line) { function v8LogToTicks (isolateLogPath, node) { const isJson = extname(isolateLogPath) === '.json' - const sp = isJson || spawn(node, [ + const sp = isJson || spawn(node.pathToNodeBinary, [ '--prof-process', '--preprocess', '-j', isolateLogPath ], { stdio: ['ignore', 'pipe', 'pipe'] }) @@ -122,7 +122,10 @@ function v8LogToTicks (isolateLogPath, node) { const tickStream = parse('ticks.*', (tick) => { const addr = tick.s.filter((n, i) => i % 2 === 0) var stack = addr.map((n) => codes[n]).filter(Boolean) - ticks.push(stack.reverse()) + const delayMs = node.collectDelay * 1000 + if (tick.tm > delayMs) { + ticks.push(stack.reverse()) + } }) pump(srcStream, tickStream, (err) => { diff --git a/platform/v8.js b/platform/v8.js index fb30999..052fc97 100644 --- a/platform/v8.js +++ b/platform/v8.js @@ -21,7 +21,7 @@ const { module.exports = v8 async function v8 (args) { - const { status, outputDir, workingDir, name, onPort, pathToNodeBinary } = args + const { status, outputDir, workingDir, name, onPort, pathToNodeBinary, collectDelay } = args let proc = spawn(pathToNodeBinary, [ '--prof', @@ -114,7 +114,7 @@ async function v8 (args) { const isolateLogPath = path.join(folder, isolateLog) await renameSafe(path.join(args.workingDir, isolateLog), isolateLogPath) return { - ticks: await v8LogToTicks(isolateLogPath, pathToNodeBinary), + ticks: await v8LogToTicks(isolateLogPath, { pathToNodeBinary, collectDelay }), inlined: inlined, pid: proc.pid, folder: folder From 01fa41839d01c379a2613e5253ebadbe51f6a342 Mon Sep 17 00:00:00 2001 From: Dylan Coakley Date: Tue, 18 Feb 2020 11:09:25 +0000 Subject: [PATCH 04/11] Rename node parameter to options --- lib/v8-log-to-ticks.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/v8-log-to-ticks.js b/lib/v8-log-to-ticks.js index 73ed887..a7bf6fe 100644 --- a/lib/v8-log-to-ticks.js +++ b/lib/v8-log-to-ticks.js @@ -15,9 +15,9 @@ const nodeMajorV = Number(process.versions.node.split('.')[0]) module.exports = wrapper -async function wrapper (isolateLogPath, node) { +async function wrapper (isolateLogPath, options) { const normalised = await prepareForPreprocess(isolateLogPath) - return v8LogToTicks(normalised, node) + return v8LogToTicks(normalised, options) } // 1. Filter because long lines make the --preprocess crash. Filter them beforehand, @@ -67,9 +67,9 @@ function fixLines (line) { } } -function v8LogToTicks (isolateLogPath, node) { +function v8LogToTicks (isolateLogPath, options) { const isJson = extname(isolateLogPath) === '.json' - const sp = isJson || spawn(node.pathToNodeBinary, [ + const sp = isJson || spawn(options.pathToNodeBinary, [ '--prof-process', '--preprocess', '-j', isolateLogPath ], { stdio: ['ignore', 'pipe', 'pipe'] }) @@ -122,7 +122,7 @@ function v8LogToTicks (isolateLogPath, node) { const tickStream = parse('ticks.*', (tick) => { const addr = tick.s.filter((n, i) => i % 2 === 0) var stack = addr.map((n) => codes[n]).filter(Boolean) - const delayMs = node.collectDelay * 1000 + const delayMs = options.collectDelay * 1000 if (tick.tm > delayMs) { ticks.push(stack.reverse()) } From 1a9167a854cc25f81b7a185e154921cc255cd46d Mon Sep 17 00:00:00 2001 From: Dylan Coakley Date: Tue, 18 Feb 2020 11:11:58 +0000 Subject: [PATCH 05/11] Change arg from on-timeout to collect-delay --- cmd.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd.js b/cmd.js index 8ad4ab5..51c615b 100755 --- a/cmd.js +++ b/cmd.js @@ -60,13 +60,13 @@ async function cmd (argv, banner = defaultBanner) { visualizeOnly: 'visualize-only', visualizeCpuProfile: 'visualize-cpu-profile', collectOnly: 'collect-only', + collectDelay: 'collect-delay', kernelTracing: 'kernel-tracing', kernelTracingDebug: 'kernel-tracing-debug', treeDebug: 'tree-debug', writeTicks: 'write-ticks', onPort: 'on-port', - P: 'onPort', - collectDelay: 'on-timeout' + P: 'onPort' } }) From cf98adf2a2aaf9989ecf2878a2b7daec8881c285 Mon Sep 17 00:00:00 2001 From: Dylan Coakley Date: Tue, 25 Feb 2020 13:26:49 +0000 Subject: [PATCH 06/11] Update call to v8LogToTicks for new options param --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 3f23fb7..82e9b89 100644 --- a/index.js +++ b/index.js @@ -151,7 +151,7 @@ async function visualize ({ visualizeOnly, treeDebug, workingDir, title, mapFram name = name || meta.name const ticks = (srcType === 'v8') - ? await v8LogToTicks(src, pathToNodeBinary) + ? await v8LogToTicks(src, { pathToNodeBinary }) : traceStacksToTicks(src) if (treeDebug === true) { From 3e179ba670a307d0bf034efa26fea31b64321068 Mon Sep 17 00:00:00 2001 From: Dylan Coakley Date: Tue, 25 Feb 2020 13:30:36 +0000 Subject: [PATCH 07/11] Add collectDelay to the API docs --- docs/api.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/api.md b/docs/api.md index f1c957d..b34fb2a 100644 --- a/docs/api.md +++ b/docs/api.md @@ -59,6 +59,12 @@ with relevant outputs. Default: false +#### `collectDelay` (number) + +Specify a delay(ms) before collecting data. + +Default: 0 + #### `mapFrames` (function) A custom mapping function that receives From 04f5dca7a0dfa8b748c42ce0fb5eeef5bf71a9df Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 19 Mar 2020 10:53:14 +0000 Subject: [PATCH 08/11] Make comparison relative to first tick --- lib/v8-log-to-ticks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/v8-log-to-ticks.js b/lib/v8-log-to-ticks.js index a7bf6fe..5c54a0e 100644 --- a/lib/v8-log-to-ticks.js +++ b/lib/v8-log-to-ticks.js @@ -123,7 +123,7 @@ function v8LogToTicks (isolateLogPath, options) { const addr = tick.s.filter((n, i) => i % 2 === 0) var stack = addr.map((n) => codes[n]).filter(Boolean) const delayMs = options.collectDelay * 1000 - if (tick.tm > delayMs) { + if (tick.tm > (tick.tm+delayMs)) { ticks.push(stack.reverse()) } }) From 1c635ab5af5c51ee4bcc61d881e9affa1feacb39 Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 19 Mar 2020 11:01:39 +0000 Subject: [PATCH 09/11] Compare relative to the first tick --- lib/v8-log-to-ticks.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/v8-log-to-ticks.js b/lib/v8-log-to-ticks.js index 5c54a0e..df0fcb9 100644 --- a/lib/v8-log-to-ticks.js +++ b/lib/v8-log-to-ticks.js @@ -119,11 +119,16 @@ function v8LogToTicks (isolateLogPath, options) { close() }) + const firstTick = []; const tickStream = parse('ticks.*', (tick) => { const addr = tick.s.filter((n, i) => i % 2 === 0) var stack = addr.map((n) => codes[n]).filter(Boolean) const delayMs = options.collectDelay * 1000 - if (tick.tm > (tick.tm+delayMs)) { + if(firstTick.length===0) { + firstTick.push(tick.tm); + } + // Compare ticks to first for collectDelay + if (tick.tm > (firstTick[0]+delayMs)) { ticks.push(stack.reverse()) } }) From eac0d24ee1103a54f7f486ad691aa3d97272ef4d Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 19 Mar 2020 11:05:16 +0000 Subject: [PATCH 10/11] Lint new changes --- lib/v8-log-to-ticks.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/v8-log-to-ticks.js b/lib/v8-log-to-ticks.js index df0fcb9..6c49ed8 100644 --- a/lib/v8-log-to-ticks.js +++ b/lib/v8-log-to-ticks.js @@ -119,16 +119,16 @@ function v8LogToTicks (isolateLogPath, options) { close() }) - const firstTick = []; + const firstTick = [] const tickStream = parse('ticks.*', (tick) => { const addr = tick.s.filter((n, i) => i % 2 === 0) var stack = addr.map((n) => codes[n]).filter(Boolean) const delayMs = options.collectDelay * 1000 - if(firstTick.length===0) { - firstTick.push(tick.tm); + if (firstTick.length === 0) { + firstTick.push(tick.tm) } // Compare ticks to first for collectDelay - if (tick.tm > (firstTick[0]+delayMs)) { + if (tick.tm > (firstTick[0] + delayMs)) { ticks.push(stack.reverse()) } }) From a93a75ed543c67ee07f80bb3f61a769a7eb63f3a Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 19 Mar 2020 11:23:31 +0000 Subject: [PATCH 11/11] Add description of collect-delay to the readme --- readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/readme.md b/readme.md index b70281f..ff8e9aa 100644 --- a/readme.md +++ b/readme.md @@ -226,6 +226,12 @@ with relevant outputs. Default: false +### --collect-delay + +Delay the collection of stacks by a specified time(ms) relative to the first entry. + +Default: 0 + ### --visualize-only Supply a path to a profile folder to build or rebuild visualization