Skip to content

Commit 9f73800

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 b52101f commit 9f73800

13 files changed

+2538
-12
lines changed

configure

+57-10
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,23 @@ parser.add_option("--enable-vtune-profiling",
157157
"JavaScript code executed in nodejs. This feature is only available "
158158
"for x32, x86, and x64 architectures.")
159159

160+
parser.add_option("--enable-pgo-generate",
161+
action="store_true",
162+
dest="enable_pgo_generate",
163+
help="Enable profiling with pgo of a binary. This feature is only available "
164+
"on linux with gcc and g++ 5.4.1 or newer.")
165+
166+
parser.add_option("--enable-pgo-use",
167+
action="store_true",
168+
dest="enable_pgo_use",
169+
help="Enable use of the profile generated with --enable-pgo-generate. This "
170+
"feature is only available on linux with gcc and g++ 5.4.1 or newer.")
171+
160172
parser.add_option("--enable-lto",
161173
action="store_true",
162174
dest="enable_lto",
163175
help="Enable compiling with lto of a binary. This feature is only available "
164-
"on linux with gcc and g++.")
176+
"on linux with gcc and g++ 5.4.1 or newer.")
165177

166178
parser.add_option("--link-module",
167179
action="append",
@@ -488,6 +500,11 @@ parser.add_option('--without-npm',
488500
dest='without_npm',
489501
help='do not install the bundled npm (package manager)')
490502

503+
parser.add_option('--without-node-report',
504+
action='store_true',
505+
dest='without_node_report',
506+
help='build without node-report'),
507+
491508
parser.add_option('--without-perfctr',
492509
action='store_true',
493510
dest='without_perfctr',
@@ -898,11 +915,22 @@ def configure_mips(o):
898915
o['variables']['mips_fpu_mode'] = options.mips_fpu_mode
899916

900917

918+
def gcc_version_ge(version_checked):
919+
for compiler in [(CC, 'c'), (CXX, 'c++')]:
920+
ok, is_clang, clang_version, compiler_version = \
921+
try_check_compiler(compiler[0], compiler[1])
922+
compiler_version_num = tuple(map(int, compiler_version))
923+
if is_clang or compiler_version_num < version_checked:
924+
return False
925+
return True
926+
927+
901928
def configure_node(o):
902929
if options.dest_os == 'android':
903930
o['variables']['OS'] = 'android'
904931
o['variables']['node_prefix'] = options.prefix
905932
o['variables']['node_install_npm'] = b(not options.without_npm)
933+
o['variables']['node_report'] = b(not options.without_node_report)
906934
o['default_configuration'] = 'Debug' if options.debug else 'Release'
907935

908936
host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
@@ -942,22 +970,41 @@ def configure_node(o):
942970
else:
943971
o['variables']['node_enable_v8_vtunejit'] = 'false'
944972

973+
if flavor != 'linux' and (options.enable_pgo_generate or options.enable_pgo_use):
974+
raise Exception(
975+
'The pgo option is supported only on linux.')
976+
977+
if flavor == 'linux':
978+
if options.enable_pgo_generate or options.enable_pgo_use:
979+
version_checked = (5, 4, 1)
980+
if not gcc_version_ge(version_checked):
981+
version_checked_str = ".".join(map(str, version_checked))
982+
raise Exception(
983+
'The options --enable-pgo-generate and --enable-pgo-use '
984+
'are supported for gcc and gxx %s or newer only.' % (version_checked_str))
985+
986+
if options.enable_pgo_generate and options.enable_pgo_use:
987+
raise Exception(
988+
'Only one of the --enable-pgo-generate or --enable-pgo-use options '
989+
'can be specified at a time. You would like to use '
990+
'--enable-pgo-generate first, profile node, and then recompile '
991+
'with --enable-pgo-use')
992+
993+
o['variables']['enable_pgo_generate'] = b(options.enable_pgo_generate)
994+
o['variables']['enable_pgo_use'] = b(options.enable_pgo_use)
995+
945996
if flavor != 'linux' and (options.enable_lto):
946997
raise Exception(
947998
'The lto option is supported only on linux.')
948999

9491000
if flavor == 'linux':
9501001
if options.enable_lto:
9511002
version_checked = (5, 4, 1)
952-
for compiler in [(CC, 'c'), (CXX, 'c++')]:
953-
ok, is_clang, clang_version, compiler_version = \
954-
try_check_compiler(compiler[0], compiler[1])
955-
compiler_version_num = tuple(map(int, compiler_version))
956-
if is_clang or compiler_version_num < version_checked:
957-
version_checked_str = ".".join(map(str, version_checked))
958-
raise Exception(
959-
'The option --enable-lto is supported for gcc and gxx %s'
960-
' or newer only.' % (version_checked_str))
1003+
if not gcc_version_ge(version_checked):
1004+
version_checked_str = ".".join(map(str, version_checked))
1005+
raise Exception(
1006+
'The option --enable-lto is supported for gcc and gxx %s'
1007+
' or newer only.' % (version_checked_str))
9611008

9621009
o['variables']['enable_lto'] = b(options.enable_lto)
9631010

lib/util.js

+24
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

+28-1
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

+24
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

+8
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

+8-1
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

+6
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",

src/node_options.h

+3
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)