From 7e9b6888e7b8ab93e582f3325f7c5ab62e77d759 Mon Sep 17 00:00:00 2001 From: Dylan Coakley Date: Tue, 11 Feb 2020 17:34:16 +0000 Subject: [PATCH 01/13] 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 8f15501ea5d634c99563255be4ae0a62168ad7df Mon Sep 17 00:00:00 2001 From: Dylan Coakley Date: Wed, 12 Feb 2020 16:16:43 +0000 Subject: [PATCH 02/13] 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 90fd1bde76b9cbedd59910344ed652927e365bf1 Mon Sep 17 00:00:00 2001 From: Dylan Coakley Date: Thu, 13 Feb 2020 16:22:48 +0000 Subject: [PATCH 03/13] 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 037cb33..096e438 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', 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 b84d734..380fa8e 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 36d4ddfd5d17cf7e12214b8b71d7bb373b6e54bb Mon Sep 17 00:00:00 2001 From: Dylan Coakley Date: Tue, 18 Feb 2020 11:09:25 +0000 Subject: [PATCH 04/13] 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 096e438..91629c4 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', 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 1318a0f58a11e6cf7463e6b3fbc508cd8d4a9e50 Mon Sep 17 00:00:00 2001 From: Dylan Coakley Date: Tue, 18 Feb 2020 11:11:58 +0000 Subject: [PATCH 05/13] 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 73cacc3d7c8d251558a80ca96306e759eb8e137c Mon Sep 17 00:00:00 2001 From: Dylan Coakley Date: Tue, 25 Feb 2020 13:26:49 +0000 Subject: [PATCH 06/13] 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 f2c987221502fc4de634e07f483247c10179ca89 Mon Sep 17 00:00:00 2001 From: Dylan Coakley Date: Tue, 25 Feb 2020 13:30:36 +0000 Subject: [PATCH 07/13] 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 b38ad8cf172b0e5bf0bafb6d51212a87cab1afcf Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 19 Mar 2020 10:53:14 +0000 Subject: [PATCH 08/13] 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 91629c4..6497666 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 c0cbfc2e80548a40c8373cef9896f04d221a148b Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 19 Mar 2020 11:01:39 +0000 Subject: [PATCH 09/13] 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 6497666..8ec350b 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 b0f4c054c120988b820d944b8d39e4678217131d Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 19 Mar 2020 11:05:16 +0000 Subject: [PATCH 10/13] 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 8ec350b..5eeab94 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 a05110dc88597f4c4f5347668bbdf67de65a2e9a Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 19 Mar 2020 11:23:31 +0000 Subject: [PATCH 11/13] 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 From d20bc90ed12b1d2bd796f0c680c615a8037dca5d Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Tue, 17 Aug 2021 14:20:51 +0100 Subject: [PATCH 12/13] Added usage information for collect-delay --- usage.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/usage.txt b/usage.txt index 135df22..a7ab52b 100644 --- a/usage.txt +++ b/usage.txt @@ -66,6 +66,9 @@ --collect-only Do not process captured stacks into a flamegraph. + --collect-delay Specify a delay(ms) before collecting data. + + --visualize-only Build or rebuild flamegraph using the output dir. Counterpart to --collect-only. From 56c051bd2dc389b47fc54486691dfbf061dcddaf Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Tue, 17 Aug 2021 14:21:55 +0100 Subject: [PATCH 13/13] Only calculate delay once - seems like this only needs to happen once, outside of the stream function --- 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 5eeab94..3365ab5 100644 --- a/lib/v8-log-to-ticks.js +++ b/lib/v8-log-to-ticks.js @@ -120,10 +120,10 @@ function v8LogToTicks (isolateLogPath, options) { }) const firstTick = [] + const delayMs = options.collectDelay * 1000; 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) }