Skip to content

Commit 0a3bcdd

Browse files
committed
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: #26513 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Coe <bencoe@gmail.com>
1 parent 963ee0b commit 0a3bcdd

11 files changed

+231
-194
lines changed

lib/internal/bootstrap/pre_execution.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function setupCoverageHooks(dir) {
6767
const {
6868
writeCoverage,
6969
setCoverageDirectory
70-
} = require('internal/coverage-gen/with_profiler');
70+
} = require('internal/profiler');
7171
setCoverageDirectory(coverageDirectory);
7272
process.on('exit', writeCoverage);
7373
process.reallyExit = (code) => {

lib/internal/process/per_thread.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function wrapProcessMethods(binding) {
158158
function kill(pid, sig) {
159159
var err;
160160
if (process.env.NODE_V8_COVERAGE) {
161-
const { writeCoverage } = require('internal/coverage-gen/with_profiler');
161+
const { writeCoverage } = require('internal/profiler');
162162
writeCoverage();
163163
}
164164

lib/internal/coverage-gen/with_profiler.js lib/internal/profiler.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,16 @@ function writeCoverage() {
2121
}
2222

2323
const target = join(coverageDirectory, filename);
24-
try {
25-
disableAllAsyncHooks();
26-
internalBinding('coverage').end((msg) => {
24+
internalBinding('profiler').endCoverage((msg) => {
25+
try {
2726
const coverageInfo = JSON.parse(msg).result;
2827
if (coverageInfo) {
2928
writeFileSync(target, JSON.stringify(coverageInfo));
3029
}
31-
});
32-
} catch (err) {
33-
console.error(err);
34-
}
35-
}
36-
37-
function disableAllAsyncHooks() {
38-
const { getHookArrays } = require('internal/async_hooks');
39-
const [hooks_array] = getHookArrays();
40-
hooks_array.forEach((hook) => { hook.disable(); });
30+
} catch (err) {
31+
console.error(err);
32+
}
33+
});
4134
}
4235

4336
function setCoverageDirectory(dir) {

node.gyp

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
'lib/internal/cluster/worker.js',
100100
'lib/internal/console/constructor.js',
101101
'lib/internal/console/global.js',
102-
'lib/internal/coverage-gen/with_profiler.js',
103102
'lib/internal/crypto/certificate.js',
104103
'lib/internal/crypto/cipher.js',
105104
'lib/internal/crypto/diffiehellman.js',
@@ -168,6 +167,7 @@
168167
'lib/internal/process/worker_thread_only.js',
169168
'lib/internal/process/report.js',
170169
'lib/internal/process/task_queues.js',
170+
'lib/internal/profiler.js',
171171
'lib/internal/querystring.js',
172172
'lib/internal/readline.js',
173173
'lib/internal/repl.js',

src/env.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ struct CompileFnEntry {
468468
#define DEBUG_CATEGORY_NAMES(V) \
469469
NODE_ASYNC_PROVIDER_TYPES(V) \
470470
V(INSPECTOR_SERVER) \
471-
V(COVERAGE)
471+
V(INSPECTOR_PROFILER)
472472

473473
enum class DebugCategory {
474474
#define V(name) name,

src/inspector/node_inspector.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
'../../src/inspector_io.cc',
4646
'../../src/inspector_agent.h',
4747
'../../src/inspector_io.h',
48-
'../../src/inspector_coverage.cc',
48+
'../../src/inspector_profiler.cc',
4949
'../../src/inspector_js_api.cc',
5050
'../../src/inspector_socket.cc',
5151
'../../src/inspector_socket.h',

src/inspector_coverage.cc

-168
This file was deleted.

0 commit comments

Comments
 (0)