Skip to content

Commit 1982b34

Browse files
node-report: merge into core
Make node-report part of core runtime, to satisfy its tier1 status on diagnostic tooling. No new functionalities have been added, changes that are required for melding it as a built-in capability has been affected on the module version of node-report (https://github.com/nodejs/node-report) Refs: nodejs#19661 Refs: nodejs#18760 Refs: nodejs/node-report#103
1 parent e007166 commit 1982b34

14 files changed

Lines changed: 2492 additions & 3 deletions

AUTHORS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,5 +2236,8 @@ Shelley Vohr <shelley.vohr@gmail.com>
22362236
Deepjyoti Mondal <djmdeveloper060796@gmail.com>
22372237
Brett Kiefer <brett@trello.com>
22382238
Kevin Thomas <kevintab95@gmail.com>
2239+
Richard Chamberlain <richard_chamberlain@uk.ibm.com>
2240+
Manusaporn Treerungroj <m.treerungroj@gmail.com>
2241+
Julian Alimin <unknown>
22392242

22402243
# Generated by tools/update-authors.sh

configure

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,11 @@ parser.add_option('--without-npm',
500500
dest='without_npm',
501501
help='do not install the bundled npm (package manager)')
502502

503+
parser.add_option('--without-node-report',
504+
action='store_true',
505+
dest='without_node_report',
506+
help='build without node-report'),
507+
503508
parser.add_option('--without-perfctr',
504509
action='store_true',
505510
dest='without_perfctr',
@@ -925,6 +930,7 @@ def configure_node(o):
925930
o['variables']['OS'] = 'android'
926931
o['variables']['node_prefix'] = options.prefix
927932
o['variables']['node_install_npm'] = b(not options.without_npm)
933+
o['variables']['node_report'] = b(not options.without_node_report)
928934
o['default_configuration'] = 'Debug' if options.debug else 'Release'
929935

930936
host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()

lib/util.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,3 +1541,27 @@ module.exports = exports = {
15411541
'util.puts is deprecated. Use console.log instead.',
15421542
'DEP0027')
15431543
};
1544+
1545+
const {
1546+
triggerNodeReport,
1547+
getNodeReport,
1548+
setReportEvents,
1549+
setReportSignal,
1550+
setReportFileName,
1551+
setReportDirectory,
1552+
setReportverbose,
1553+
} = process.binding('util');
1554+
if (triggerNodeReport !== undefined)
1555+
exports.triggerNodeReport = triggerNodeReport;
1556+
if (getNodeReport !== undefined)
1557+
exports.getNodeReport = getNodeReport;
1558+
if (setReportEvents !== undefined)
1559+
exports.setReportEvents = setReportEvents;
1560+
if (setReportSignal !== undefined)
1561+
exports.setReportSignal = setReportSignal;
1562+
if (setReportFileName !== undefined)
1563+
exports.setReportFileName = setReportFileName;
1564+
if (setReportDirectory !== undefined)
1565+
exports.setReportDirectory = setReportDirectory;
1566+
if (setReportverbose !== undefined)
1567+
exports.setReportverbose = setReportverbose;

node.gyp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,34 @@
628628
'src/tls_wrap.h'
629629
],
630630
}],
631-
],
631+
[ 'node_report=="true"', {
632+
'sources': [
633+
'src/node_report.cc',
634+
'src/node_report_module.cc',
635+
'src/node_report_utils.cc',
636+
],
637+
'defines': [
638+
'NODE_REPORT',
639+
'NODEREPORT_VERSION="1.0.0"',
640+
],
641+
'conditions': [
642+
['OS=="win"', {
643+
'libraries': [
644+
'dbghelp.lib',
645+
'Netapi32.lib',
646+
'PsApi.lib',
647+
'Ws2_32.lib',
648+
],
649+
'dll_files': [
650+
'dbghelp.dll',
651+
'Netapi32.dll',
652+
'PsApi.dll',
653+
'Ws2_32.dll',
654+
],
655+
}],
656+
],
657+
}],
658+
],
632659
},
633660
{
634661
'target_name': 'mkssldef',

src/node.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@
9090
#include <unicode/uvernum.h>
9191
#endif
9292

93+
#if defined(NODE_REPORT)
94+
#include "node_report.h"
95+
#endif
96+
9397
#if defined(LEAK_SANITIZER)
9498
#include <sanitizer/lsan_interface.h>
9599
#endif
@@ -2332,6 +2336,14 @@ void LoadEnvironment(Environment* env) {
23322336
return;
23332337
}
23342338

2339+
#if defined(NODE_REPORT)
2340+
auto env_opts = per_process_opts->per_isolate->per_env;
2341+
if (!env_opts->report_events.empty()) {
2342+
nodereport::InitializeNodeReport();
2343+
nodereport::SetEvents(env->isolate(), env_opts->report_events.c_str());
2344+
}
2345+
#endif // NODE_REPORT
2346+
23352347
// Bootstrap Node.js
23362348
Local<Object> bootstrapper = Object::New(env->isolate());
23372349
SetupBootstrapObject(env, bootstrapper);
@@ -2647,6 +2659,18 @@ void ProcessArgv(std::vector<std::string>* args,
26472659
exit(9);
26482660
}
26492661

2662+
#if defined(NODE_REPORT)
2663+
if (!env_opts->report_events.empty()) {
2664+
size_t pos = 0;
2665+
std::string& temp = env_opts->report_events;
2666+
while ((pos = temp.find(",", pos)) != std::string::npos) {
2667+
temp.replace(pos, 1, "+");
2668+
pos += 1;
2669+
}
2670+
env_opts->report_events = temp;
2671+
}
2672+
#endif // NODE_REPORT
2673+
26502674
#if HAVE_OPENSSL
26512675
if (per_process_opts->use_openssl_ca && per_process_opts->use_bundled_ca) {
26522676
fprintf(stderr, "%s: either --use-openssl-ca or --use-bundled-ca can be "

src/node_config.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ static void Initialize(Local<Object> target,
153153
v8EnvironmentFlags->Set(i, OneByteString(env->isolate(),
154154
v8_environment_flags[i]));
155155
}
156+
157+
#if defined(NODE_REPORT)
158+
const std::string& report_events = env->options()->report_events;
159+
if (!report_events.empty()) {
160+
READONLY_STRING_PROPERTY(target, "node_report", report_events);
161+
}
162+
#endif // NODE_REPORT
163+
156164
} // InitConfig
157165

158166
} // namespace node

src/node_internals.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ struct sockaddr;
9797
#define NODE_BUILTIN_ICU_MODULES(V)
9898
#endif
9999

100+
#if NODE_REPORT
101+
#define NODE_BUILTIN_NODE_REPORT_MODULES(V) V(node_report)
102+
#else
103+
#define NODE_BUILTIN_NODE_REPORT_MODULES(V)
104+
#endif
105+
100106
// A list of built-in modules. In order to do module registration
101107
// in node::Init(), need to add built-in modules in the following list.
102108
// Then in node::RegisterBuiltinModules(), it calls modules' registration
@@ -147,7 +153,8 @@ struct sockaddr;
147153
#define NODE_BUILTIN_MODULES(V) \
148154
NODE_BUILTIN_STANDARD_MODULES(V) \
149155
NODE_BUILTIN_OPENSSL_MODULES(V) \
150-
NODE_BUILTIN_ICU_MODULES(V)
156+
NODE_BUILTIN_ICU_MODULES(V) \
157+
NODE_BUILTIN_NODE_REPORT_MODULES(V)
151158

152159
#define NODE_MODULE_CONTEXT_AWARE_CPP(modname, regfunc, priv, flags) \
153160
static node::node_module _module = { \

src/node_options.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
129129
"show stack traces on process warnings",
130130
&EnvironmentOptions::trace_warnings,
131131
kAllowedInEnvironment);
132+
#if defined(NODE_REPORT)
133+
AddOption("--report-events",
134+
"enable node report generation",
135+
&EnvironmentOptions::report_events,
136+
kAllowedInEnvironment);
137+
#endif // NODE_REPORT
132138

133139
AddOption("--check",
134140
"syntax check script without executing",
@@ -203,7 +209,8 @@ PerProcessOptionsParser::PerProcessOptionsParser() {
203209
kAllowedInEnvironment);
204210
AddOption("--trace-event-file-pattern",
205211
"Template string specifying the filepath for the trace-events "
206-
"data, it supports ${rotation} and ${pid} log-rotation id.",
212+
"data, it supports ${rotation} and ${pid} log-rotation id. %2$u "
213+
"is the pid.",
207214
&PerProcessOptions::trace_event_file_pattern,
208215
kAllowedInEnvironment);
209216
AddAlias("--trace-events-enabled", {

src/node_options.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class EnvironmentOptions {
8282
bool syntax_check_only = false;
8383
bool has_eval_string = false;
8484
std::string eval_string;
85+
#if defined(NODE_REPORT)
86+
std::string report_events;
87+
#endif // NODE_REPORT
8588
bool print_eval = false;
8689
bool force_repl = false;
8790

0 commit comments

Comments
 (0)