diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-03-08 09:34:46 +0100 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2019-03-12 07:03:53 +0800 |
commit | 0a3bcdd26108bb29045a557bc555c3a53c244a55 (patch) | |
tree | b510257ef03b0ad2d04ed9c597677b39bce0405c /lib | |
parent | 963ee0bc736008e01d80fbad973f80fd021735fd (diff) | |
download | android-node-v8-0a3bcdd26108bb29045a557bc555c3a53c244a55.tar.gz android-node-v8-0a3bcdd26108bb29045a557bc555c3a53c244a55.tar.bz2 android-node-v8-0a3bcdd26108bb29045a557bc555c3a53c244a55.zip |
src: refactor coverage connection
- Refactor the C++ class to be resuable for other types of profiles
- Move the try-catch block around coverage collection callback
to be inside the callback to silence potential JSON or write
errors.
- Use Function::Call instead of MakeCallback to call the coverage
message callback since it does not actually need async hook
handling. This way we no longer needs to disable the async
hooks when writing the coverage results.
- Renames `lib/internal/coverage-gen/with_profiler.js` to
`lib/internal/profiler.js` because it is now the only way
to generate coverage.
PR-URL: https://github.com/nodejs/node/pull/26513
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Coe <bencoe@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/bootstrap/pre_execution.js | 2 | ||||
-rw-r--r-- | lib/internal/process/per_thread.js | 2 | ||||
-rw-r--r-- | lib/internal/profiler.js (renamed from lib/internal/coverage-gen/with_profiler.js) | 19 |
3 files changed, 8 insertions, 15 deletions
diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 936dc4673c..79bb5cc291 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -67,7 +67,7 @@ function setupCoverageHooks(dir) { const { writeCoverage, setCoverageDirectory - } = require('internal/coverage-gen/with_profiler'); + } = require('internal/profiler'); setCoverageDirectory(coverageDirectory); process.on('exit', writeCoverage); process.reallyExit = (code) => { diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 85772aafd8..a0d6b32596 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -158,7 +158,7 @@ function wrapProcessMethods(binding) { function kill(pid, sig) { var err; if (process.env.NODE_V8_COVERAGE) { - const { writeCoverage } = require('internal/coverage-gen/with_profiler'); + const { writeCoverage } = require('internal/profiler'); writeCoverage(); } diff --git a/lib/internal/coverage-gen/with_profiler.js b/lib/internal/profiler.js index 573d2c3712..1042f126dd 100644 --- a/lib/internal/coverage-gen/with_profiler.js +++ b/lib/internal/profiler.js @@ -21,23 +21,16 @@ function writeCoverage() { } const target = join(coverageDirectory, filename); - try { - disableAllAsyncHooks(); - internalBinding('coverage').end((msg) => { + internalBinding('profiler').endCoverage((msg) => { + try { const coverageInfo = JSON.parse(msg).result; if (coverageInfo) { writeFileSync(target, JSON.stringify(coverageInfo)); } - }); - } catch (err) { - console.error(err); - } -} - -function disableAllAsyncHooks() { - const { getHookArrays } = require('internal/async_hooks'); - const [hooks_array] = getHookArrays(); - hooks_array.forEach((hook) => { hook.disable(); }); + } catch (err) { + console.error(err); + } + }); } function setCoverageDirectory(dir) { |