diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-12-29 18:44:11 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2019-01-16 13:49:36 +0800 |
commit | b367ab2a6624b41bd59b751c61cf64ad91a9e2d6 (patch) | |
tree | 60e2e85a2f60bb773a642d6c948855072ff3e3d6 /lib/internal/bootstrap/node.js | |
parent | 2b401e33de81428dc5f6dfc60343e65ee5167886 (diff) | |
download | android-node-v8-b367ab2a6624b41bd59b751c61cf64ad91a9e2d6.tar.gz android-node-v8-b367ab2a6624b41bd59b751c61cf64ad91a9e2d6.tar.bz2 android-node-v8-b367ab2a6624b41bd59b751c61cf64ad91a9e2d6.zip |
process: refactor coverage setup during bootstrap
- Renamed `internal/process/write-coverage.js` to
`internal/coverage-gen/with_instrumentation.js`,
`internal/process/coverage.js` to
`internal/coverage-gen/with_profiler.js` to distinguish
the two better and added comments.
- Separate the coverage directory setup and the connection
setup, moves the directory setup into `node.js` and
closer to the exit hooks because that's where it's used.
- Moves the `process.reallyExit` overwrite and
`process.on('exit')` hooks setup into bootstrap/node.js
for clarity, and move them to a later stage of
bootstrap since they do not have to happen that early.
PR-URL: https://github.com/nodejs/node/pull/25398
Reviewed-By: Ben Coe <bencoe@gmail.com>
Diffstat (limited to 'lib/internal/bootstrap/node.js')
-rw-r--r-- | lib/internal/bootstrap/node.js | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 53bab24ef5..ca979af258 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -158,13 +158,6 @@ function startup() { setupProcessStdio(getStdout, getStdin, getStderr); } - if (global.__coverage__) - NativeModule.require('internal/process/write-coverage').setup(); - - if (process.env.NODE_V8_COVERAGE) { - NativeModule.require('internal/process/coverage').setupExitHooks(); - } - if (config.hasInspector) { NativeModule.require('internal/inspector_async_hook').setup(); } @@ -295,6 +288,45 @@ function startup() { } }); + // Set up coverage exit hooks. + let originalReallyExit = process.reallyExit; + // Core coverage generation using nyc instrumented lib/ files. + // See `make coverage-build`. This does not affect user land. + // TODO(joyeecheung): this and `with_instrumentation.js` can be + // removed in favor of NODE_V8_COVERAGE once we switch to that + // in https://coverage.nodejs.org/ + if (global.__coverage__) { + const { + writeCoverage + } = NativeModule.require('internal/coverage-gen/with_instrumentation'); + process.on('exit', writeCoverage); + originalReallyExit = process.reallyExit = (code) => { + writeCoverage(); + originalReallyExit(code); + }; + } + // User-facing NODE_V8_COVERAGE environment variable that writes + // ScriptCoverage to a specified file. + if (process.env.NODE_V8_COVERAGE) { + const cwd = NativeModule.require('internal/process/execution').tryGetCwd(); + const { resolve } = NativeModule.require('path'); + // Resolve the coverage directory to an absolute path, and + // overwrite process.env so that the original path gets passed + // to child processes even when they switch cwd. + const coverageDirectory = resolve(cwd, process.env.NODE_V8_COVERAGE); + process.env.NODE_V8_COVERAGE = coverageDirectory; + const { + writeCoverage, + setCoverageDirectory + } = NativeModule.require('internal/coverage-gen/with_profiler'); + setCoverageDirectory(coverageDirectory); + process.on('exit', writeCoverage); + process.reallyExit = (code) => { + writeCoverage(); + originalReallyExit(code); + }; + } + const perf = internalBinding('performance'); const { NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE, |