From 7bf6be0b7c81b6ee5cd24b2fe71efe38d6195c58 Mon Sep 17 00:00:00 2001 From: Andreas Madsen Date: Fri, 5 Jan 2018 16:40:18 +0100 Subject: [PATCH] trace_events: stop tracing agent in process.exit() PR-URL: https://github.com/nodejs/node/pull/18005 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Gireesh Punathil --- src/node.cc | 3 +++ .../test-trace-events-process-exit.js | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 test/parallel/test-trace-events-process-exit.js diff --git a/src/node.cc b/src/node.cc index 40800a5e7047df..55e5ad3dd71a75 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2358,6 +2358,9 @@ static void WaitForInspectorDisconnect(Environment* env) { static void Exit(const FunctionCallbackInfo& args) { WaitForInspectorDisconnect(Environment::GetCurrent(args)); + if (trace_enabled) { + v8_platform.StopTracingAgent(); + } exit(args[0]->Int32Value()); } diff --git a/test/parallel/test-trace-events-process-exit.js b/test/parallel/test-trace-events-process-exit.js new file mode 100644 index 00000000000000..be45cb1d3e0f22 --- /dev/null +++ b/test/parallel/test-trace-events-process-exit.js @@ -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); + })); +}));