Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: stop the profiler and the inspector before snapshot serialization #51815

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,9 @@ class Environment : public MemoryRetainer {
inline inspector::Agent* inspector_agent() const {
return inspector_agent_.get();
}
inline void StopInspector() {
inspector_agent_.reset();
}

inline bool is_in_inspector_console_call() const;
inline void set_is_in_inspector_console_call(bool value);
Expand Down
8 changes: 8 additions & 0 deletions src/node_snapshotable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,14 @@ ExitCode SnapshotBuilder::CreateSnapshot(SnapshotData* out,
fprintf(stderr, "Environment = %p\n", env);
}

// Clean up the states left by the inspector because V8 cannot serialize
// them. They don't need to be persisted and can be created from scratch
// after snapshot deserialization.
RunAtExit(env);
#if HAVE_INSPECTOR
env->StopInspector();
#endif

// Serialize the native states
out->isolate_data_info = setup->isolate_data()->Serialize(creator);
out->env_info = env->Serialize(creator);
Expand Down
55 changes: 55 additions & 0 deletions test/parallel/test-snapshot-coverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict';

// This tests that the snapshot works with built-in coverage collection.

require('../common');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const fs = require('fs');
const assert = require('assert');

tmpdir.refresh();
const blobPath = tmpdir.resolve('snapshot.blob');
const file = fixtures.path('empty.js');

function filterCoverageFiles(name) {
return name.startsWith('coverage') && name.endsWith('.json');
}
{
// Create the snapshot.
spawnSyncAndExitWithoutError(process.execPath, [
'--snapshot-blob',
blobPath,
'--build-snapshot',
file,
], {
cwd: tmpdir.path,
env: {
...process.env,
NODE_V8_COVERAGE: tmpdir.path,
}
});
const files = fs.readdirSync(tmpdir.path);
console.log('Files in tmpdir.path', files); // Log for debugging the test.
const coverage = files.filter(filterCoverageFiles);
assert.strictEqual(coverage.length, 1);
}

{
spawnSyncAndExitWithoutError(process.execPath, [
'--snapshot-blob',
blobPath,
file,
], {
cwd: tmpdir.path,
env: {
...process.env,
NODE_V8_COVERAGE: tmpdir.path,
},
});
const files = fs.readdirSync(tmpdir.path);
console.log('Files in tmpdir.path', files); // Log for debugging the test.
const coverage = files.filter(filterCoverageFiles);
assert.strictEqual(coverage.length, 2);
}
Loading