From b238b6bf17c0a3b98f78a044a0b00e4131ec9ed3 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 9 Jun 2020 20:46:52 +0800 Subject: [PATCH] v8: implement v8.takeCoverage() Add an v8.takeCoverage() API that allows the user to write the coverage started by NODE_V8_COVERAGE to disk on demand. The coverage can be written multiple times during the lifetime of the process, each time the execution counter will be reset. When the process is about to exit, one last coverage will still be written to disk. Also refactors the internal profiler connection code so that we use the inspector response id to identify the profile response instead of using an ad-hoc flag in C++. PR-URL: https://github.com/nodejs/node/pull/33807 Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis Reviewed-By: Jiawen Geng Reviewed-By: Ben Coe --- doc/api/v8.md | 16 ++ lib/v8.js | 7 + src/inspector_profiler.cc | 187 ++++++++++++-------- src/inspector_profiler.h | 21 ++- test/fixtures/v8-coverage/interval.js | 14 ++ test/fixtures/v8-coverage/take-coverage.js | 10 ++ test/parallel/test-v8-take-coverage-noop.js | 32 ++++ test/parallel/test-v8-take-coverage.js | 85 +++++++++ 8 files changed, 292 insertions(+), 80 deletions(-) create mode 100644 test/fixtures/v8-coverage/interval.js create mode 100644 test/fixtures/v8-coverage/take-coverage.js create mode 100644 test/parallel/test-v8-take-coverage-noop.js create mode 100644 test/parallel/test-v8-take-coverage.js diff --git a/doc/api/v8.md b/doc/api/v8.md index 5dec224d359168..2968c267dc6f87 100644 --- a/doc/api/v8.md +++ b/doc/api/v8.md @@ -223,6 +223,21 @@ v8.setFlagsFromString('--trace_gc'); setTimeout(() => { v8.setFlagsFromString('--notrace_gc'); }, 60e3); ``` +## `v8.takeCoverage()` + + + +The `v8.takeCoverage()` method allows the user to write the coverage started by +[`NODE_V8_COVERAGE`][] to disk on demand. This method can be invoked multiple +times during the lifetime of the process, each time the execution counter will +be reset and a new coverage report will be written to the directory specified +by [`NODE_V8_COVERAGE`][]. + +When the process is about to exit, one last coverage will still be written to +disk. + ## `v8.writeHeapSnapshot([filename])`