From c46effc6f87e230687d23891a400e24ddfe296b4 Mon Sep 17 00:00:00 2001 From: Rafael Gonzaga Date: Wed, 15 Mar 2023 17:22:15 -0300 Subject: [PATCH] feat: accept name as dest identifier (#117) Signed-off-by: RafaelGSS --- src/index.js | 3 ++- src/visualizer/data-tree.js | 4 ++-- src/visualizer/flame-graph-frame.js | 4 ++-- test/basic.test.js | 2 +- test/cmd-collect-analysing.test.js | 2 +- test/detect-port.test.js | 2 +- test/failure.test.js | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index 2f34502..a0e4035 100644 --- a/src/index.js +++ b/src/index.js @@ -105,7 +105,8 @@ class ClinicHeapProfiler extends events.EventEmitter { detectPort = false, collectOnFailure = false, debug = false, - dest = `.clinic/${process.pid}.clinic-heapprofile` + name, + dest = `.clinic/${name || process.pid}.clinic-heapprofiler` } = settings this.detectPort = !!detectPort diff --git a/src/visualizer/data-tree.js b/src/visualizer/data-tree.js index f0e0cd2..12a9978 100644 --- a/src/visualizer/data-tree.js +++ b/src/visualizer/data-tree.js @@ -76,8 +76,8 @@ class DataTree { // Value of hidden frames is the sum of their visible children return node.children ? node.children.reduce((acc, child) => { - return acc + this.getNodeValue(child) - }, 0) + return acc + this.getNodeValue(child) + }, 0) : 0 } diff --git a/src/visualizer/flame-graph-frame.js b/src/visualizer/flame-graph-frame.js index 77182c0..e431d49 100644 --- a/src/visualizer/flame-graph-frame.js +++ b/src/visualizer/flame-graph-frame.js @@ -89,8 +89,8 @@ function renderStackFrame (globals, locals, rect) { // For a narrow right-hand edge of a block of frames of the same code area... const rightEdgeReducer = (thinFrameReducer === 1 || !previousSibling || (!!nextSibling && sameArea(nodeData, nextSibling.data))) ? thinFrameReducer - // ...fade as above, but based on the width of these same-area siblings, not just this node, so that - // something like [ someFunc ./file.js ][ f ./file.js ][][]||| gets a visible right hand edge + // ...fade as above, but based on the width of these same-area siblings, not just this node, so that + // something like [ someFunc ./file.js ][ f ./file.js ][][]||| gets a visible right hand edge : Math.min(1, visibleSiblings.slice(0, indexPosition).reduce((acc, sibling) => acc + (sameArea(nodeData, sibling.data) ? (sibling.x1 - sibling.x0) * widthRatio : 0), 0) / (lineWidth * 2)) const alphaFull = this.ui.presentationMode ? 0.8 : 0.7 diff --git a/test/basic.test.js b/test/basic.test.js index 84626ad..d926ec9 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -21,7 +21,7 @@ test('cmd - test collect - data exists, html generated', t => { t.error(err) - t.match(filename, /[0-9]+\.clinic-heapprofile$/) + t.match(filename, /[0-9]+\.clinic-heapprofiler$/) fs.unlink(filename, callback) fs.unlink(filename + '.html', callback) diff --git a/test/cmd-collect-analysing.test.js b/test/cmd-collect-analysing.test.js index 544dbc6..48148a3 100644 --- a/test/cmd-collect-analysing.test.js +++ b/test/cmd-collect-analysing.test.js @@ -11,7 +11,7 @@ test('test collect - emits "analysing" event', t => { function cleanup (err, filename) { t.error(err) - t.match(filename, /[0-9]+\.clinic-heapprofile$/) + t.match(filename, /[0-9]+\.clinic-heapprofiler$/) fs.unlink(filename, err => { t.error(err) diff --git a/test/detect-port.test.js b/test/detect-port.test.js index 8a46346..aa925ec 100644 --- a/test/detect-port.test.js +++ b/test/detect-port.test.js @@ -22,7 +22,7 @@ test('cmd - collect - detect server port', t => { t.error(err) - t.match(filename, /[0-9]+\.clinic-heapprofile$/) + t.match(filename, /[0-9]+\.clinic-heapprofiler$/) fs.unlink(filename, callback) fs.unlink(filename + '.html', callback) diff --git a/test/failure.test.js b/test/failure.test.js index abaa1f4..3aa2f3e 100644 --- a/test/failure.test.js +++ b/test/failure.test.js @@ -20,7 +20,7 @@ test('cmd - test collect - works with nonzero exit code when collectOnFailure=tr function cleanup (err, filename) { t.error(err) - t.match(filename, /[0-9]+\.clinic-heapprofile$/) + t.match(filename, /[0-9]+\.clinic-heapprofiler$/) fs.unlink(filename, err => { t.error(err)