@nearform/heap-profiler
Advanced tools
Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "@nearform/heap-profiler", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Heap dump and sample profiler generator for Node.", | ||
@@ -38,4 +38,4 @@ "author": "NearForm Ltd", | ||
"lint": "eslint src/**/*.js test/**/*.js", | ||
"test": "tap --reporter=spec --coverage-report=html --coverage-report=text --no-browser test/*.spec.js", | ||
"ci": "npm run lint && tap --no-color --reporter=spec --coverage-report=json --coverage-report=text --branches 90 --functions 90 --lines 90 --statements 90 test/*.spec.js" | ||
"test": "tap --gc --reporter=spec --coverage-report=html --coverage-report=text --no-browser test/*.spec.js", | ||
"ci": "npm run lint && tap --gc --no-color --reporter=spec --coverage-report=json --coverage-report=text --branches 90 --functions 90 --lines 90 --statements 90 test/*.spec.js" | ||
}, | ||
@@ -42,0 +42,0 @@ "dependencies": { |
@@ -39,2 +39,4 @@ # @nearform/heap-profiler | ||
- `HEAP_PROFILER_SNAPSHOT_RUN_GC`: If to run the garbage collector before taking the snapshot. The default is `false` and it is ignored if the process is not started with the `--expose-gc` flag. | ||
- `HEAP_PROFILER_PROFILE`: If set to `false`, it will not generate heap sampling profile. | ||
@@ -58,2 +60,3 @@ | ||
- `destination`: The path where to store the snapshot. The default will be a `.heapsnapshot` in the current directory. | ||
- `runGC`: If to run the garbage collector before taking the snapshot. The default is `false` and it is ignored if the process is not started with the `--expose-gc` flag. | ||
@@ -60,0 +63,0 @@ - `generateHeapSamplingProfile([options], [callback])`: Generates a heap sampling profiler. The valid options are: |
@@ -37,2 +37,6 @@ 'use strict' | ||
if ('HEAP_PROFILER_SNAPSHOT_RUN_GC' in process.env) { | ||
profilerOptions.runGC = process.env.HEAP_PROFILER_SNAPSHOT_RUN_GC === 'true' | ||
} | ||
if ('HEAP_PROFILER_PROFILE_DESTINATION' in process.env) { | ||
@@ -39,0 +43,0 @@ profilerOptions.destination = process.env.HEAP_PROFILER_PROFILE_DESTINATION |
@@ -16,3 +16,3 @@ 'use strict' | ||
const [callback, promise] = ensurePromiseCallback(cb) | ||
const { destination } = Object.assign({ destination: destinationFile('heapsnapshot') }, options) | ||
const { destination, runGC } = Object.assign({ destination: destinationFile('heapsnapshot'), runGC: false }, options) | ||
const session = new Session() | ||
@@ -48,2 +48,12 @@ let error = null | ||
if (runGC && typeof global.gc === 'function') { | ||
try { | ||
global.gc() | ||
} catch (e) { | ||
error = e | ||
writer.end() | ||
return promise | ||
} | ||
} | ||
// Start the session | ||
@@ -50,0 +60,0 @@ session.connect() |
@@ -20,2 +20,3 @@ 'use strict' | ||
'HEAP_PROFILER_SNAPSHOT', | ||
'HEAP_PROFILER_SNAPSHOT_RUN_GC', | ||
'HEAP_PROFILER_DESTINATION', | ||
@@ -49,2 +50,3 @@ 'HEAP_PROFILER_SNAPSHOT_DESTINATION', | ||
process.env.HEAP_PROFILER_SNAPSHOT_DESTINATION = snapshotDestination | ||
process.env.HEAP_PROFILER_SNAPSHOT_RUN_GC = 'true' | ||
process.env.HEAP_PROFILER_PROFILE_DESTINATION = profileDestination | ||
@@ -51,0 +53,0 @@ process.env.HEAP_PROFILER_PROFILE_DURATION = 10 |
@@ -6,2 +6,3 @@ 'use strict' | ||
const { file: tmpFile } = require('tmp-promise') | ||
const { stub } = require('sinon') | ||
@@ -41,2 +42,36 @@ const generateHeapSnapshot = require('../src/snapshot') | ||
t.test('it runs the garbage collector if requested to', async t => { | ||
const gcStub = stub(global, 'gc') | ||
const { path: destination, cleanup } = await tmpFile() | ||
await generateHeapSnapshot({ destination, runGC: true }) | ||
const generated = JSON.parse(readFileSync(destination, 'utf-8')) | ||
t.true(validate(generated)) | ||
t.equal(gcStub.callCount, 1) | ||
cleanup() | ||
gcStub.restore() | ||
}) | ||
t.test('it handles garbage collector errors', async t => { | ||
const gcStub = stub(global, 'gc') | ||
gcStub.onFirstCall().throws(new Error('FAILED')) | ||
const { path: destination, cleanup } = await tmpFile() | ||
try { | ||
await generateHeapSnapshot({ destination, runGC: true }) | ||
t.fail('DID NOT THROW') | ||
} catch (e) { | ||
t.equal(e.message, 'FAILED') | ||
} | ||
t.equal(gcStub.callCount, 1) | ||
cleanup() | ||
gcStub.restore() | ||
}) | ||
t.test('it handles file saving errors using promises', async t => { | ||
@@ -43,0 +78,0 @@ await t.rejects(() => generateHeapSnapshot({ destination: '/this/doesnt/exists' }), { |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
33402
642
80
0
32