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: fix --diagnostic-dir not working with --heapsnapshot-signal #49496

Closed
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 8 additions & 5 deletions src/heap_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,16 @@ void TriggerHeapSnapshot(const FunctionCallbackInfo<Value>& args) {
auto options = GetHeapSnapshotOptions(args[1]);

if (filename_v->IsUndefined()) {
std::string dir = env->options()->diagnostic_dir;
if (dir.empty()) {
dir = Environment::GetCwd(env->exec_path());
}
DiagnosticFilename name(env, "Heap", "heapsnapshot");
std::string filename = dir + kPathSeparator + (*name);
THROW_IF_INSUFFICIENT_PERMISSIONS(
env,
permission::PermissionScope::kFileSystemWrite,
Environment::GetCwd(env->exec_path()));
if (WriteSnapshot(env, *name, options).IsNothing()) return;
if (String::NewFromUtf8(isolate, *name).ToLocal(&filename_v)) {
env, permission::PermissionScope::kFileSystemWrite, dir);
if (WriteSnapshot(env, filename.c_str(), options).IsNothing()) return;
if (String::NewFromUtf8(isolate, filename.c_str()).ToLocal(&filename_v)) {
args.GetReturnValue().Set(filename_v);
}
return;
Expand Down
49 changes: 49 additions & 0 deletions test/sequential/test-diagnostic-dir-heapdump-flag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';
const common = require('../common');
const tmpdir = require('../common/tmpdir');

if (common.isWindows)
common.skip('test not supported on Windows');

const assert = require('assert');

if (process.argv[2] === 'child') {
const fs = require('fs');
const path = require('path');

assert.strictEqual(process.listenerCount('SIGUSR2'), 1);
process.kill(process.pid, 'SIGUSR2');
process.kill(process.pid, 'SIGUSR2');

// Asynchronously wait for the snapshot. Use an async loop to be a bit more
// robust in case platform or machine differences throw off the timing.
(function validate() {
const files = fs.readdirSync(tmpdir.path);

if (files.length === 0)
return setImmediate(validate);

assert.strictEqual(files.length, 2);

for (let i = 0; i < files.length; i++) {
assert.match(files[i], /^Heap\..+\.heapsnapshot$/);
JSON.parse(fs.readFileSync(path.join(tmpdir.path, files[i])));
}
})();
} else {
const { spawnSync } = require('child_process');

tmpdir.refresh();
const args = [
'--heapsnapshot-signal',
'SIGUSR2',
'--diagnostic-dir',
tmpdir.path,
__filename,
'child',
];
const child = spawnSync(process.execPath, args);

assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
}
Loading