Skip to content

Commit

Permalink
node-report: merge into core
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gireeshpunathil committed Sep 5, 2018
1 parent b52101f commit 9f73800
Show file tree
Hide file tree
Showing 13 changed files with 2,538 additions and 12 deletions.
67 changes: 57 additions & 10 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,23 @@ parser.add_option("--enable-vtune-profiling",
"JavaScript code executed in nodejs. This feature is only available "
"for x32, x86, and x64 architectures.")

parser.add_option("--enable-pgo-generate",
action="store_true",
dest="enable_pgo_generate",
help="Enable profiling with pgo of a binary. This feature is only available "
"on linux with gcc and g++ 5.4.1 or newer.")

parser.add_option("--enable-pgo-use",
action="store_true",
dest="enable_pgo_use",
help="Enable use of the profile generated with --enable-pgo-generate. This "
"feature is only available on linux with gcc and g++ 5.4.1 or newer.")

parser.add_option("--enable-lto",
action="store_true",
dest="enable_lto",
help="Enable compiling with lto of a binary. This feature is only available "
"on linux with gcc and g++.")
"on linux with gcc and g++ 5.4.1 or newer.")

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

parser.add_option('--without-node-report',
action='store_true',
dest='without_node_report',
help='build without node-report'),

parser.add_option('--without-perfctr',
action='store_true',
dest='without_perfctr',
Expand Down Expand Up @@ -898,11 +915,22 @@ def configure_mips(o):
o['variables']['mips_fpu_mode'] = options.mips_fpu_mode


def gcc_version_ge(version_checked):
for compiler in [(CC, 'c'), (CXX, 'c++')]:
ok, is_clang, clang_version, compiler_version = \
try_check_compiler(compiler[0], compiler[1])
compiler_version_num = tuple(map(int, compiler_version))
if is_clang or compiler_version_num < version_checked:
return False
return True


def configure_node(o):
if options.dest_os == 'android':
o['variables']['OS'] = 'android'
o['variables']['node_prefix'] = options.prefix
o['variables']['node_install_npm'] = b(not options.without_npm)
o['variables']['node_report'] = b(not options.without_node_report)
o['default_configuration'] = 'Debug' if options.debug else 'Release'

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

if flavor != 'linux' and (options.enable_pgo_generate or options.enable_pgo_use):
raise Exception(
'The pgo option is supported only on linux.')

if flavor == 'linux':
if options.enable_pgo_generate or options.enable_pgo_use:
version_checked = (5, 4, 1)
if not gcc_version_ge(version_checked):
version_checked_str = ".".join(map(str, version_checked))
raise Exception(
'The options --enable-pgo-generate and --enable-pgo-use '
'are supported for gcc and gxx %s or newer only.' % (version_checked_str))

if options.enable_pgo_generate and options.enable_pgo_use:
raise Exception(
'Only one of the --enable-pgo-generate or --enable-pgo-use options '
'can be specified at a time. You would like to use '
'--enable-pgo-generate first, profile node, and then recompile '
'with --enable-pgo-use')

o['variables']['enable_pgo_generate'] = b(options.enable_pgo_generate)
o['variables']['enable_pgo_use'] = b(options.enable_pgo_use)

if flavor != 'linux' and (options.enable_lto):
raise Exception(
'The lto option is supported only on linux.')

if flavor == 'linux':
if options.enable_lto:
version_checked = (5, 4, 1)
for compiler in [(CC, 'c'), (CXX, 'c++')]:
ok, is_clang, clang_version, compiler_version = \
try_check_compiler(compiler[0], compiler[1])
compiler_version_num = tuple(map(int, compiler_version))
if is_clang or compiler_version_num < version_checked:
version_checked_str = ".".join(map(str, version_checked))
raise Exception(
'The option --enable-lto is supported for gcc and gxx %s'
' or newer only.' % (version_checked_str))
if not gcc_version_ge(version_checked):
version_checked_str = ".".join(map(str, version_checked))
raise Exception(
'The option --enable-lto is supported for gcc and gxx %s'
' or newer only.' % (version_checked_str))

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

Expand Down
24 changes: 24 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1541,3 +1541,27 @@ module.exports = exports = {
'util.puts is deprecated. Use console.log instead.',
'DEP0027')
};

const {
triggerNodeReport,
getNodeReport,
setReportEvents,
setReportSignal,
setReportFileName,
setReportDirectory,
setReportverbose,
} = process.binding('util');
if (triggerNodeReport !== undefined)
exports.triggerNodeReport = triggerNodeReport;
if (getNodeReport !== undefined)
exports.getNodeReport = getNodeReport;
if (setReportEvents !== undefined)
exports.setReportEvents = setReportEvents;
if (setReportSignal !== undefined)
exports.setReportSignal = setReportSignal;
if (setReportFileName !== undefined)
exports.setReportFileName = setReportFileName;
if (setReportDirectory !== undefined)
exports.setReportDirectory = setReportDirectory;
if (setReportverbose !== undefined)
exports.setReportverbose = setReportverbose;
29 changes: 28 additions & 1 deletion node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,34 @@
'src/tls_wrap.h'
],
}],
],
[ 'node_report=="true"', {
'sources': [
'src/node_report.cc',
'src/node_report_module.cc',
'src/node_report_utils.cc',
],
'defines': [
'NODE_REPORT',
'NODEREPORT_VERSION="1.0.0"',
],
'conditions': [
['OS=="win"', {
'libraries': [
'dbghelp.lib',
'Netapi32.lib',
'PsApi.lib',
'Ws2_32.lib',
],
'dll_files': [
'dbghelp.dll',
'Netapi32.dll',
'PsApi.dll',
'Ws2_32.dll',
],
}],
],
}],
],
},
{
'target_name': 'mkssldef',
Expand Down
24 changes: 24 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
#include <unicode/uvernum.h>
#endif

#if defined(NODE_REPORT)
#include "node_report.h"
#endif

#if defined(LEAK_SANITIZER)
#include <sanitizer/lsan_interface.h>
#endif
Expand Down Expand Up @@ -2332,6 +2336,14 @@ void LoadEnvironment(Environment* env) {
return;
}

#if defined(NODE_REPORT)
auto env_opts = per_process_opts->per_isolate->per_env;
if (!env_opts->report_events.empty()) {
nodereport::InitializeNodeReport();
nodereport::SetEvents(env->isolate(), env_opts->report_events.c_str());
}
#endif // NODE_REPORT

// Bootstrap Node.js
Local<Object> bootstrapper = Object::New(env->isolate());
SetupBootstrapObject(env, bootstrapper);
Expand Down Expand Up @@ -2647,6 +2659,18 @@ void ProcessArgv(std::vector<std::string>* args,
exit(9);
}

#if defined(NODE_REPORT)
if (!env_opts->report_events.empty()) {
size_t pos = 0;
std::string& temp = env_opts->report_events;
while ((pos = temp.find(",", pos)) != std::string::npos) {
temp.replace(pos, 1, "+");
pos += 1;
}
env_opts->report_events = temp;
}
#endif // NODE_REPORT

#if HAVE_OPENSSL
if (per_process_opts->use_openssl_ca && per_process_opts->use_bundled_ca) {
fprintf(stderr, "%s: either --use-openssl-ca or --use-bundled-ca can be "
Expand Down
8 changes: 8 additions & 0 deletions src/node_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ static void Initialize(Local<Object> target,
v8EnvironmentFlags->Set(i, OneByteString(env->isolate(),
v8_environment_flags[i]));
}

#if defined(NODE_REPORT)
const std::string& report_events = env->options()->report_events;
if (!report_events.empty()) {
READONLY_STRING_PROPERTY(target, "node_report", report_events);
}
#endif // NODE_REPORT

} // InitConfig

} // namespace node
Expand Down
9 changes: 8 additions & 1 deletion src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ struct sockaddr;
#define NODE_BUILTIN_ICU_MODULES(V)
#endif

#if NODE_REPORT
#define NODE_BUILTIN_NODE_REPORT_MODULES(V) V(node_report)
#else
#define NODE_BUILTIN_NODE_REPORT_MODULES(V)
#endif

// A list of built-in modules. In order to do module registration
// in node::Init(), need to add built-in modules in the following list.
// Then in node::RegisterBuiltinModules(), it calls modules' registration
Expand Down Expand Up @@ -147,7 +153,8 @@ struct sockaddr;
#define NODE_BUILTIN_MODULES(V) \
NODE_BUILTIN_STANDARD_MODULES(V) \
NODE_BUILTIN_OPENSSL_MODULES(V) \
NODE_BUILTIN_ICU_MODULES(V)
NODE_BUILTIN_ICU_MODULES(V) \
NODE_BUILTIN_NODE_REPORT_MODULES(V)

#define NODE_MODULE_CONTEXT_AWARE_CPP(modname, regfunc, priv, flags) \
static node::node_module _module = { \
Expand Down
6 changes: 6 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"show stack traces on process warnings",
&EnvironmentOptions::trace_warnings,
kAllowedInEnvironment);
#if defined(NODE_REPORT)
AddOption("--report-events",
"enable node report generation",
&EnvironmentOptions::report_events,
kAllowedInEnvironment);
#endif // NODE_REPORT

AddOption("--check",
"syntax check script without executing",
Expand Down
3 changes: 3 additions & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class EnvironmentOptions {
bool syntax_check_only = false;
bool has_eval_string = false;
std::string eval_string;
#if defined(NODE_REPORT)
std::string report_events;
#endif // NODE_REPORT
bool print_eval = false;
bool force_repl = false;

Expand Down
Loading

0 comments on commit 9f73800

Please sign in to comment.