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 e007166 commit 1982b34
Show file tree
Hide file tree
Showing 14 changed files with 2,492 additions and 3 deletions.
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -2236,5 +2236,8 @@ Shelley Vohr <shelley.vohr@gmail.com>
Deepjyoti Mondal <djmdeveloper060796@gmail.com>
Brett Kiefer <brett@trello.com>
Kevin Thomas <kevintab95@gmail.com>
Richard Chamberlain <richard_chamberlain@uk.ibm.com>
Manusaporn Treerungroj <m.treerungroj@gmail.com>
Julian Alimin <unknown>

# Generated by tools/update-authors.sh
6 changes: 6 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -500,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 @@ -925,6 +930,7 @@ def configure_node(o):
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
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
9 changes: 8 additions & 1 deletion 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 Expand Up @@ -203,7 +209,8 @@ PerProcessOptionsParser::PerProcessOptionsParser() {
kAllowedInEnvironment);
AddOption("--trace-event-file-pattern",
"Template string specifying the filepath for the trace-events "
"data, it supports ${rotation} and ${pid} log-rotation id.",
"data, it supports ${rotation} and ${pid} log-rotation id. %2$u "
"is the pid.",
&PerProcessOptions::trace_event_file_pattern,
kAllowedInEnvironment);
AddAlias("--trace-events-enabled", {
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 1982b34

Please sign in to comment.