From d819de1aba1b2ad71141115c5127e18c67194561 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 9 Jun 2020 21:18:25 +0800 Subject: [PATCH] v8: implement v8.stopCoverage() Add a v8.stopCoverage() API to stop the coverage collection started by NODE_V8_COVERAGE - this would be useful in conjunction with v8.takeCoverage() if the user don't want to emit the coverage at the process exit but still want to collect it on demand at some point. 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 | 1 + src/inspector_profiler.cc | 20 +++++++++++++ src/inspector_profiler.h | 1 + test/fixtures/v8-coverage/stop-coverage.js | 3 ++ test/parallel/test-v8-stop-coverage.js | 34 ++++++++++++++++++++++ 6 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/v8-coverage/stop-coverage.js create mode 100644 test/parallel/test-v8-stop-coverage.js diff --git a/doc/api/v8.md b/doc/api/v8.md index 2968c267dc6f87..629fa5ee9425e8 100644 --- a/doc/api/v8.md +++ b/doc/api/v8.md @@ -236,7 +236,18 @@ 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. +disk, unless [`v8.stopCoverage()`][] is invoked before the process exits. + +## `v8.stopCoverage()` + + + +The `v8.stopCoverage()` method allows the user to stop the coverage collection +started by [`NODE_V8_COVERAGE`][], so that V8 can release the execution count +records and optimize code. This can be used in conjunction with +`v8.takeCoverage()` if the user wants to collect the coverage on demand. ## `v8.writeHeapSnapshot([filename])`