Skip to content

Commit

Permalink
trace_events: stop tracing agent in process.exit()
Browse files Browse the repository at this point in the history
PR-URL: #18005
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
AndreasMadsen authored and MylesBorins committed Jan 10, 2018
1 parent b593d94 commit 7bf6be0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,9 @@ static void WaitForInspectorDisconnect(Environment* env) {

static void Exit(const FunctionCallbackInfo<Value>& args) {
WaitForInspectorDisconnect(Environment::GetCurrent(args));
if (trace_enabled) {
v8_platform.StopTracingAgent();
}
exit(args[0]->Int32Value());
}

Expand Down
22 changes: 22 additions & 0 deletions test/parallel/test-trace-events-process-exit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
const fs = require('fs');

const FILE_NAME = 'node_trace.1.log';

common.refreshTmpDir();
process.chdir(common.tmpDir);

const proc = cp.spawn(process.execPath,
[ '--trace-events-enabled',
'-e', 'process.exit()' ]);

proc.once('exit', common.mustCall(() => {
assert(common.fileExists(FILE_NAME));
fs.readFile(FILE_NAME, common.mustCall((err, data) => {
const traces = JSON.parse(data.toString()).traceEvents;
assert(traces.length > 0);
}));
}));

0 comments on commit 7bf6be0

Please sign in to comment.