diff --git a/.gitignore b/.gitignore index e19ac5f..ce05c94 100644 --- a/.gitignore +++ b/.gitignore @@ -38,7 +38,7 @@ /node_modules/ # Package files -NodeReport*.txt +node-report*.txt npm-debug.log -nodereport-*.tgz -nodereport_test.log +node-report-*.tgz +node-report_test.log diff --git a/CHANGES.md b/CHANGES.md index 5a8b23e..f36b3a6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,7 @@ 2016-12-12, Version 1.0.7 ========================= - * Fix version reporting in NodeReport section (Richard Lau) + * Fix version reporting in nodereport section (Richard Lau) * Fix fprintf calls on Windows (Richard Lau) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2082eff..0ab8f95 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Contributing to nodereport +# Contributing to node-report ## Code of Conduct @@ -8,7 +8,7 @@ The [Node.js Code of Conduct][] applies to this repo. ## Code Contributions -The nodereport project falls under the governance of the post-mortem +The node-report project falls under the governance of the post-mortem working group which is documented in: https://github.com/nodejs/post-mortem/blob/master/GOVERNANCE.md diff --git a/GOVERNANCE.md b/GOVERNANCE.md index 39f3ba5..4e521ba 100644 --- a/GOVERNANCE.md +++ b/GOVERNANCE.md @@ -1,5 +1,5 @@ -# nodereport Project Governance +# node-report Project Governance -The nodereport project falls under the governance of the post-mortem +The node-report project falls under the governance of the post-mortem working group which is documented in: https://github.com/nodejs/post-mortem/blob/master/GOVERNANCE.md. diff --git a/LICENCE.md b/LICENCE.md index 40a0f28..6932b27 100644 --- a/LICENCE.md +++ b/LICENCE.md @@ -1,10 +1,10 @@ The MIT License (MIT) ===================== -Copyright (c) 2016 nodereport contributors +Copyright (c) 2016 node-report contributors -------------------------------------------------- -*nodereport contributors listed at * +*node-report contributors listed at * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/MAINTAINER.md b/MAINTAINER.md index eba3eb6..02f2cb7 100644 --- a/MAINTAINER.md +++ b/MAINTAINER.md @@ -1,15 +1,15 @@ -# Instructions for maintainers of the nodereport project +# Instructions for maintainers of the node-report project ## Publishing to the npm registry -The nodereport project is published as an npm native module +The node-report project is published as an npm native module For each publish to npm: - update the version property in the package.json file, incrementing the major, minor and patch level as appropriate - update the CHANGES.md file with a list of commits since last release - - commit CHANGES.md and package.json to nodereport master branch + - commit CHANGES.md and package.json to node-report master branch - tag commit with an annotated tag - - git checkout and npm publish the nodereport package + - git checkout and npm publish the node-report package Suggested tooling is the slt-release script documented here: https://github.com/strongloop/strong-tools diff --git a/README.md b/README.md index 665aeb6..fa55d55 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# nodereport +# node-report Delivers a human-readable diagnostic summary, written to file. @@ -14,51 +14,51 @@ Supports Node.js v4, v6 and v7 on Linux, MacOS, Windows and AIX. ## Usage ```bash -npm install nodereport -node -r nodereport app.js +npm install node-report +node -r node-report app.js ``` -A NodeReport will be triggered automatically on unhandled exceptions and fatal +A node-report will be triggered automatically on unhandled exceptions and fatal error events (for example out of memory errors), and can also be triggered by sending a USR2 signal to a Node.js process (Linux/MacOS only). -A NodeReport can also be triggered via an API call from a JavaScript +A node-report can also be triggered via an API call from a JavaScript application. ```js -var nodereport = require('nodereport'); -nodereport.triggerReport(); +var node-report = require('node-report'); +node-report.triggerReport(); ``` The API can be used without adding the automatic exception and fatal error hooks and the signal handler, as follows: ```js -var nodereport = require('nodereport/api'); -nodereport.triggerReport(); +var node-report = require('node-report/api'); +node-report.triggerReport(); ``` -Content of the NodeReport consists of a header section containing the event +Content of the node-report consists of a header section containing the event type, date, time, PID and Node version, sections containing JavaScript and native stack traces, a section containing V8 heap information, a section containing libuv handle information and an OS platform information section -showing CPU and memory usage and system limits. An example NodeReport can be +showing CPU and memory usage and system limits. An example node-report can be triggered using the Node.js REPL: ``` $ node -> nodereport = require('nodereport') -> nodereport.triggerReport() -Writing Node.js report to file: NodeReport.20161020.091102.8480.001.txt +> node-report = require('node-report') +> node-report.triggerReport() +Writing Node.js report to file: node-report.20161020.091102.8480.001.txt Node.js report completed > ``` -When a NodeReport is triggered, start and end messages are issued to stderr +When a node-report is triggered, start and end messages are issued to stderr and the filename of the report is returned to the caller. The default filename includes the date, time, PID and a sequence number. Alternatively, a filename can be specified as a parameter on the `triggerReport()` call. ```js -nodereport.triggerReport("myReportName"); +node-report.triggerReport("myReportName"); ``` ## Configuration @@ -66,35 +66,35 @@ nodereport.triggerReport("myReportName"); Additional configuration is available using the following APIs: ```js -nodereport.setEvents("exception+fatalerror+signal+apicall"); -nodereport.setSignal("SIGUSR2|SIGQUIT"); -nodereport.setFileName("stdout|stderr|"); -nodereport.setDirectory(""); -nodereport.setCoreDump("yes|no"); -nodereport.setVerbose("yes|no"); +node-report.setEvents("exception+fatalerror+signal+apicall"); +node-report.setSignal("SIGUSR2|SIGQUIT"); +node-report.setFileName("stdout|stderr|"); +node-report.setDirectory(""); +node-report.setCoreDump("yes|no"); +node-report.setVerbose("yes|no"); ``` Configuration on module Initialization is also available via environment variables: ```bash -export NODEREPORT_EVENTS=exception+fatalerror+signal+apicall -export NODEREPORT_SIGNAL=SIGUSR2|SIGQUIT -export NODEREPORT_FILENAME=stdout|stderr| -export NODEREPORT_DIRECTORY= -export NODEREPORT_COREDUMP=yes|no -export NODEREPORT_VERBOSE=yes|no +export NODE_REPORT_EVENTS=exception+fatalerror+signal+apicall +export NODE_REPORT_SIGNAL=SIGUSR2|SIGQUIT +export NODE_REPORT_FILENAME=stdout|stderr| +export NODE_REPORT_DIRECTORY= +export NODE_REPORT_COREDUMP=yes|no +export NODE_REPORT_VERBOSE=yes|no ``` ## Examples -To see examples of NodeReports generated from these events you can run the -demonstration applications provided in the nodereport github repository. These are +To see examples of node-reports generated from these events you can run the +demonstration applications provided in the node-report github repository. These are Node.js applications which will prompt you to trigger the required event. -1. `api.js` - NodeReport triggered by JavaScript API call. -2. `exception.js` - NodeReport triggered by unhandled exception. -3. `fatalerror.js` - NodeReport triggered by fatal error on JavaScript heap out of memory. -4. `loop.js` - looping application, NodeReport triggered using kill `-USR2 `. +1. `api.js` - node-report triggered by JavaScript API call. +2. `exception.js` - node-report triggered by unhandled exception. +3. `fatalerror.js` - node-report triggered by fatal error on JavaScript heap out of memory. +4. `loop.js` - looping application, node-report triggered using kill `-USR2 `. ## License diff --git a/binding.gyp b/binding.gyp index c3ade57..fe1773a 100644 --- a/binding.gyp +++ b/binding.gyp @@ -21,7 +21,7 @@ }], ], "defines": [ - 'NODEREPORT_VERSION="=4.0.0" @@ -21,7 +21,7 @@ "test": "tap test/test*.js" }, "bugs": { - "url": "https://github.com/nodejs/nodereport/issues" + "url": "https://github.com/nodejs/node-report/issues" }, "devDependencies": { "tap": "^8.0.0" diff --git a/src/module.cc b/src/module.cc index 2aa7a57..2c822f6 100644 --- a/src/module.cc +++ b/src/module.cc @@ -1,7 +1,7 @@ #include "node_report.h" #include -namespace nodereport { +namespace node-report { // Internal/static function declarations static void OnFatalError(const char* location, const char* message); @@ -17,17 +17,17 @@ static void SignalDump(int signo); static void SetupSignalHandler(); #endif -// Default nodereport option settings -static unsigned int nodereport_events = NR_APICALL; -static unsigned int nodereport_core = 1; -static unsigned int nodereport_verbose = 0; +// Default node-report option settings +static unsigned int node-report_events = NR_APICALL; +static unsigned int node-report_core = 1; +static unsigned int node-report_verbose = 0; #ifdef _WIN32 // signal trigger not supported on Windows -static unsigned int nodereport_signal = 0; +static unsigned int node-report_signal = 0; #else // trigger signal supported on Unix platforms and OSX -static unsigned int nodereport_signal = SIGUSR2; // default signal is SIGUSR2 +static unsigned int node-report_signal = SIGUSR2; // default signal is SIGUSR2 static int report_signal = 0; // atomic for signal handling in progress static uv_sem_t report_semaphore; // semaphore for hand-off to watchdog -static uv_async_t nodereport_trigger_async; // async handle for event loop +static uv_async_t node-report_trigger_async; // async handle for event loop static uv_mutex_t node_isolate_mutex; // mutex for wachdog thread static struct sigaction saved_sa; // saved signal action #endif @@ -40,7 +40,7 @@ static bool signal_thread_initialised = false; static v8::Isolate* node_isolate; /******************************************************************************* - * External JavaScript API for triggering a NodeReport + * External JavaScript API for triggering a node-report * ******************************************************************************/ NAN_METHOD(TriggerReport) { @@ -54,34 +54,34 @@ NAN_METHOD(TriggerReport) { if (filename_parameter.length() < NR_MAXNAME) { snprintf(filename, sizeof(filename), "%s", *filename_parameter); } else { - Nan::ThrowError("nodereport: filename parameter is too long"); + Nan::ThrowError("node-report: filename parameter is too long"); } } - if (nodereport_events & NR_APICALL) { - TriggerNodeReport(isolate, kJavaScript, "JavaScript API", __func__, filename); - // Return value is the NodeReport filename + if (node-report_events & NR_APICALL) { + Triggernode-report(isolate, kJavaScript, "JavaScript API", __func__, filename); + // Return value is the node-report filename info.GetReturnValue().Set(Nan::New(filename).ToLocalChecked()); } } /******************************************************************************* - * External JavaScript APIs for nodereport configuration + * External JavaScript APIs for node-report configuration * ******************************************************************************/ NAN_METHOD(SetEvents) { Nan::Utf8String parameter(info[0]); v8::Isolate* isolate = info.GetIsolate(); - unsigned int previous_events = nodereport_events; // save previous settings - nodereport_events = ProcessNodeReportEvents(*parameter); + unsigned int previous_events = node-report_events; // save previous settings + node-report_events = Processnode-reportEvents(*parameter); - // If NodeReport newly requested for fatalerror, set up the V8 call-back - if ((nodereport_events & NR_FATALERROR) && (error_hook_initialised == false)) { + // If node-report newly requested for fatalerror, set up the V8 call-back + if ((node-report_events & NR_FATALERROR) && (error_hook_initialised == false)) { isolate->SetFatalErrorHandler(OnFatalError); error_hook_initialised = true; } - // If NodeReport newly requested for exceptions, tell V8 to capture stack trace and set up the callback - if ((nodereport_events & NR_EXCEPTION) && (exception_hook_initialised == false)) { + // If node-report newly requested for exceptions, tell V8 to capture stack trace and set up the callback + if ((node-report_events & NR_EXCEPTION) && (exception_hook_initialised == false)) { isolate->SetCaptureStackTraceForUncaughtExceptions(true, 32, v8::StackTrace::kDetailed); // The hook for uncaught exception won't get called unless the --abort_on_uncaught_exception option is set v8::V8::SetFlagsFromString("--abort_on_uncaught_exception", sizeof("--abort_on_uncaught_exception")-1); @@ -90,48 +90,48 @@ NAN_METHOD(SetEvents) { } #ifndef _WIN32 - // If NodeReport newly requested on external user signal set up watchdog thread and handler - if ((nodereport_events & NR_SIGNAL) && (signal_thread_initialised == false)) { + // If node-report newly requested on external user signal set up watchdog thread and handler + if ((node-report_events & NR_SIGNAL) && (signal_thread_initialised == false)) { SetupSignalHandler(); } - // If NodeReport no longer required on external user signal, reset the OS signal handler - if (!(nodereport_events & NR_SIGNAL) && (previous_events & NR_SIGNAL)) { - RestoreSignalHandler(nodereport_signal, &saved_sa); + // If node-report no longer required on external user signal, reset the OS signal handler + if (!(node-report_events & NR_SIGNAL) && (previous_events & NR_SIGNAL)) { + RestoreSignalHandler(node-report_signal, &saved_sa); } #endif } NAN_METHOD(SetCoreDump) { Nan::Utf8String parameter(info[0]); - nodereport_core = ProcessNodeReportCoreSwitch(*parameter); + node-report_core = Processnode-reportCoreSwitch(*parameter); } NAN_METHOD(SetSignal) { #ifndef _WIN32 Nan::Utf8String parameter(info[0]); - unsigned int previous_signal = nodereport_signal; // save previous setting - nodereport_signal = ProcessNodeReportSignal(*parameter); + unsigned int previous_signal = node-report_signal; // save previous setting + node-report_signal = Processnode-reportSignal(*parameter); // If signal event active and selected signal has changed, switch the OS signal handler - if ((nodereport_events & NR_SIGNAL) && (nodereport_signal != previous_signal)) { + if ((node-report_events & NR_SIGNAL) && (node-report_signal != previous_signal)) { RestoreSignalHandler(previous_signal, &saved_sa); - RegisterSignalHandler(nodereport_signal, SignalDump, &saved_sa); + RegisterSignalHandler(node-report_signal, SignalDump, &saved_sa); } #endif } NAN_METHOD(SetFileName) { Nan::Utf8String parameter(info[0]); - ProcessNodeReportFileName(*parameter); + Processnode-reportFileName(*parameter); } NAN_METHOD(SetDirectory) { Nan::Utf8String parameter(info[0]); - ProcessNodeReportDirectory(*parameter); + Processnode-reportDirectory(*parameter); } NAN_METHOD(SetVerbose) { Nan::Utf8String parameter(info[0]); - nodereport_verbose = ProcessNodeReportVerboseSwitch(*parameter); + node-report_verbose = Processnode-reportVerboseSwitch(*parameter); } /******************************************************************************* - * Callbacks for triggering NodeReport on fatal error, uncaught exception and + * Callbacks for triggering node-report on fatal error, uncaught exception and * external signals ******************************************************************************/ static void OnFatalError(const char* location, const char* message) { @@ -140,12 +140,12 @@ static void OnFatalError(const char* location, const char* message) { } else { fprintf(stderr, "FATAL ERROR: %s\n", message); } - // Trigger NodeReport if requested - if (nodereport_events & NR_FATALERROR) { - TriggerNodeReport(Isolate::GetCurrent(), kFatalError, message, location, nullptr); + // Trigger node-report if requested + if (node-report_events & NR_FATALERROR) { + Triggernode-report(Isolate::GetCurrent(), kFatalError, message, location, nullptr); } fflush(stderr); - if (nodereport_core) { + if (node-report_core) { raise(SIGABRT); // core dump requested (default) } else { exit(1); // user specified that no core dump is wanted, just exit @@ -153,24 +153,24 @@ static void OnFatalError(const char* location, const char* message) { } bool OnUncaughtException(v8::Isolate* isolate) { - // Trigger NodeReport if required - if (nodereport_events & NR_EXCEPTION) { - TriggerNodeReport(isolate, kException, "exception", __func__, nullptr); + // Trigger node-report if required + if (node-report_events & NR_EXCEPTION) { + Triggernode-report(isolate, kException, "exception", __func__, nullptr); } - return nodereport_core; + return node-report_core; } #ifndef _WIN32 static void SignalDumpInterruptCallback(Isolate* isolate, void* data) { if (report_signal != 0) { - if (nodereport_verbose) { - fprintf(stdout, "nodereport: SignalDumpInterruptCallback handling signal\n"); + if (node-report_verbose) { + fprintf(stdout, "node-report: SignalDumpInterruptCallback handling signal\n"); } - if (nodereport_events & NR_SIGNAL) { - if (nodereport_verbose) { - fprintf(stdout, "nodereport: SignalDumpInterruptCallback triggering NodeReport\n"); + if (node-report_events & NR_SIGNAL) { + if (node-report_verbose) { + fprintf(stdout, "node-report: SignalDumpInterruptCallback triggering node-report\n"); } - TriggerNodeReport(isolate, kSignal_JS, + Triggernode-report(isolate, kSignal_JS, node::signo_string(report_signal), __func__, nullptr); } report_signal = 0; @@ -178,14 +178,14 @@ static void SignalDumpInterruptCallback(Isolate* isolate, void* data) { } static void SignalDumpAsyncCallback(uv_async_t* handle) { if (report_signal != 0) { - if (nodereport_verbose) { - fprintf(stdout, "nodereport: SignalDumpAsyncCallback handling signal\n"); + if (node-report_verbose) { + fprintf(stdout, "node-report: SignalDumpAsyncCallback handling signal\n"); } - if (nodereport_events & NR_SIGNAL) { - if (nodereport_verbose) { - fprintf(stdout, "nodereport: SignalDumpAsyncCallback triggering NodeReport\n"); + if (node-report_events & NR_SIGNAL) { + if (node-report_verbose) { + fprintf(stdout, "node-report: SignalDumpAsyncCallback triggering node-report\n"); } - TriggerNodeReport(Isolate::GetCurrent(), kSignal_UV, + Triggernode-report(Isolate::GetCurrent(), kSignal_UV, node::signo_string(report_signal), __func__, nullptr); } report_signal = 0; @@ -215,9 +215,9 @@ static void RestoreSignalHandler(int signo, struct sigaction* saved_sa) { sigaction(signo, saved_sa, nullptr); } -// Raw signal handler for triggering a NodeReport - runs on an arbitrary thread +// Raw signal handler for triggering a node-report - runs on an arbitrary thread static void SignalDump(int signo) { - // Check atomic for NodeReport already pending, storing the signal number + // Check atomic for node-report already pending, storing the signal number if (__sync_val_compare_and_swap(&report_signal, 0, signo) == 0) { uv_sem_post(&report_semaphore); // Hand-off to watchdog thread } @@ -241,26 +241,26 @@ static int StartWatchdogThread(void* (*thread_main)(void* unused)) { pthread_sigmask(SIG_SETMASK, &sigmask, nullptr); pthread_attr_destroy(&attr); if (err != 0) { - fprintf(stderr, "nodereport: StartWatchdogThread pthread_create() failed: %s\n", strerror(err)); + fprintf(stderr, "node-report: StartWatchdogThread pthread_create() failed: %s\n", strerror(err)); fflush(stderr); return -err; } return 0; } -// Watchdog thread implementation for signal-triggered NodeReport +// Watchdog thread implementation for signal-triggered node-report inline void* ReportSignalThreadMain(void* unused) { for (;;) { uv_sem_wait(&report_semaphore); - if (nodereport_verbose) { - fprintf(stdout, "nodereport: signal %s received\n", node::signo_string(report_signal)); + if (node-report_verbose) { + fprintf(stdout, "node-report: signal %s received\n", node::signo_string(report_signal)); } uv_mutex_lock(&node_isolate_mutex); if (auto isolate = node_isolate) { // Request interrupt callback for running JavaScript code isolate->RequestInterrupt(SignalDumpInterruptCallback, nullptr); // Event loop may be idle, so also request an async callback - uv_async_send(&nodereport_trigger_async); + uv_async_send(&node-report_trigger_async); } uv_mutex_unlock(&node_isolate_mutex); } @@ -271,23 +271,23 @@ inline void* ReportSignalThreadMain(void* unused) { static void SetupSignalHandler() { int rc = uv_sem_init(&report_semaphore, 0); if (rc != 0) { - fprintf(stderr, "nodereport: initialization failed, uv_sem_init() returned %d\n", rc); - Nan::ThrowError("nodereport: initialization failed, uv_sem_init() returned error\n"); + fprintf(stderr, "node-report: initialization failed, uv_sem_init() returned %d\n", rc); + Nan::ThrowError("node-report: initialization failed, uv_sem_init() returned error\n"); } rc = uv_mutex_init(&node_isolate_mutex); if (rc != 0) { - fprintf(stderr, "nodereport: initialization failed, uv_mutex_init() returned %d\n", rc); - Nan::ThrowError("nodereport: initialization failed, uv_mutex_init() returned error\n"); + fprintf(stderr, "node-report: initialization failed, uv_mutex_init() returned %d\n", rc); + Nan::ThrowError("node-report: initialization failed, uv_mutex_init() returned error\n"); } if (StartWatchdogThread(ReportSignalThreadMain) == 0) { - rc = uv_async_init(uv_default_loop(), &nodereport_trigger_async, SignalDumpAsyncCallback); + rc = uv_async_init(uv_default_loop(), &node-report_trigger_async, SignalDumpAsyncCallback); if (rc != 0) { - fprintf(stderr, "nodereport: initialization failed, uv_async_init() returned %d\n", rc); - Nan::ThrowError("nodereport: initialization failed, uv_async_init() returned error\n"); + fprintf(stderr, "node-report: initialization failed, uv_async_init() returned %d\n", rc); + Nan::ThrowError("node-report: initialization failed, uv_async_init() returned error\n"); } - uv_unref(reinterpret_cast(&nodereport_trigger_async)); - RegisterSignalHandler(nodereport_signal, SignalDump, &saved_sa); + uv_unref(reinterpret_cast(&node-report_trigger_async)); + RegisterSignalHandler(node-report_signal, SignalDump, &saved_sa); signal_thread_initialised = true; } } @@ -305,39 +305,39 @@ void Initialize(v8::Local exports) { SetVersionString(isolate); SetCommandLine(); - const char* verbose_switch = secure_getenv("NODEREPORT_VERBOSE"); + const char* verbose_switch = secure_getenv("NODE_REPORT_VERBOSE"); if (verbose_switch != nullptr) { - nodereport_verbose = ProcessNodeReportVerboseSwitch(verbose_switch); + node-report_verbose = Processnode-reportVerboseSwitch(verbose_switch); } - const char* trigger_events = secure_getenv("NODEREPORT_EVENTS"); + const char* trigger_events = secure_getenv("NODE_REPORT_EVENTS"); if (trigger_events != nullptr) { - nodereport_events = ProcessNodeReportEvents(trigger_events); + node-report_events = Processnode-reportEvents(trigger_events); } - const char* core_dump_switch = secure_getenv("NODEREPORT_COREDUMP"); + const char* core_dump_switch = secure_getenv("NODE_REPORT_COREDUMP"); if (core_dump_switch != nullptr) { - nodereport_core = ProcessNodeReportCoreSwitch(core_dump_switch); + node-report_core = Processnode-reportCoreSwitch(core_dump_switch); } - const char* trigger_signal = secure_getenv("NODEREPORT_SIGNAL"); + const char* trigger_signal = secure_getenv("NODE_REPORT_SIGNAL"); if (trigger_signal != nullptr) { - nodereport_signal = ProcessNodeReportSignal(trigger_signal); + node-report_signal = Processnode-reportSignal(trigger_signal); } - const char* report_name = secure_getenv("NODEREPORT_FILENAME"); + const char* report_name = secure_getenv("NODE_REPORT_FILENAME"); if (report_name != nullptr) { - ProcessNodeReportFileName(report_name); + Processnode-reportFileName(report_name); } - const char* directory_name = secure_getenv("NODEREPORT_DIRECTORY"); + const char* directory_name = secure_getenv("NODE_REPORT_DIRECTORY"); if (directory_name != nullptr) { - ProcessNodeReportDirectory(directory_name); + Processnode-reportDirectory(directory_name); } - // If NodeReport requested for fatalerror, set up the V8 call-back - if (nodereport_events & NR_FATALERROR) { + // If node-report requested for fatalerror, set up the V8 call-back + if (node-report_events & NR_FATALERROR) { isolate->SetFatalErrorHandler(OnFatalError); error_hook_initialised = true; } - // If NodeReport requested for exceptions, tell V8 to capture stack trace and set up the callback - if (nodereport_events & NR_EXCEPTION) { + // If node-report requested for exceptions, tell V8 to capture stack trace and set up the callback + if (node-report_events & NR_EXCEPTION) { isolate->SetCaptureStackTraceForUncaughtExceptions(true, 32, v8::StackTrace::kDetailed); // The hook for uncaught exception won't get called unless the --abort_on_uncaught_exception option is set v8::V8::SetFlagsFromString("--abort_on_uncaught_exception", sizeof("--abort_on_uncaught_exception")-1); @@ -346,8 +346,8 @@ void Initialize(v8::Local exports) { } #ifndef _WIN32 - // If NodeReport requested on external user signal set up watchdog thread and callbacks - if (nodereport_events & NR_SIGNAL) { + // If node-report requested on external user signal set up watchdog thread and callbacks + if (node-report_events & NR_SIGNAL) { SetupSignalHandler(); } #endif @@ -367,18 +367,18 @@ void Initialize(v8::Local exports) { exports->Set(Nan::New("setVerbose").ToLocalChecked(), Nan::New(SetVerbose)->GetFunction()); - if (nodereport_verbose) { + if (node-report_verbose) { #ifdef _WIN32 - fprintf(stdout, "nodereport: initialization complete, event flags: %#x core flag: %#x\n", - nodereport_events, nodereport_core); + fprintf(stdout, "node-report: initialization complete, event flags: %#x core flag: %#x\n", + node-report_events, node-report_core); #else - fprintf(stdout, "nodereport: initialization complete, event flags: %#x core flag: %#x signal flag: %#x\n", - nodereport_events, nodereport_core, nodereport_signal); + fprintf(stdout, "node-report: initialization complete, event flags: %#x core flag: %#x signal flag: %#x\n", + node-report_events, node-report_core, node-report_signal); #endif } } -NODE_MODULE(nodereport, Initialize) +NODE_MODULE(node-report, Initialize) -} // namespace nodereport +} // namespace node-report diff --git a/src/node_report.cc b/src/node_report.cc index b296a60..4249072 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -35,8 +35,8 @@ #include #endif -#if !defined(NODEREPORT_VERSION) -#define NODEREPORT_VERSION "dev" +#if !defined(NODE_REPORT_VERSION) +#define NODE_REPORT_VERSION "dev" #endif #if !defined(UNKNOWN_NODEVERSION_STRING) @@ -52,7 +52,7 @@ extern char** environ; #endif -namespace nodereport { +namespace node-report { using v8::HeapSpaceStatistics; using v8::HeapStatistics; @@ -79,7 +79,7 @@ static void PrintSystemInformation(FILE* fp, Isolate* isolate); static void WriteInteger(FILE* fp, size_t value); // Global variables -static int seq = 0; // sequence number for NodeReport filenames +static int seq = 0; // sequence number for node-report filenames const char* v8_states[] = {"JS", "GC", "COMPILER", "OTHER", "EXTERNAL", "IDLE"}; static bool report_active = false; // recursion protection static char report_filename[NR_MAXNAME + 1] = ""; @@ -93,15 +93,15 @@ static struct tm loadtime_tm_struct; // module load time #endif /******************************************************************************* - * Functions to process nodereport configuration options: + * Functions to process node-report configuration options: * Trigger event selection * Core dump yes/no switch * Trigger signal selection - * NodeReport filename - * NodeReport directory + * node-report filename + * node-report directory * Verbose mode ******************************************************************************/ -unsigned int ProcessNodeReportEvents(const char* args) { +unsigned int ProcessProcessNode_ReportEvents(const char* args) { // Parse the supplied event types unsigned int event_flags = 0; const char* cursor = args; @@ -119,7 +119,7 @@ unsigned int ProcessNodeReportEvents(const char* args) { event_flags |= NR_APICALL; cursor += sizeof("apicall") - 1; } else { - fprintf(stderr, "Unrecognised argument for nodereport events option: %s\n", cursor); + fprintf(stderr, "Unrecognised argument for node-report events option: %s\n", cursor); return 0; } if (*cursor == '+') { @@ -129,9 +129,9 @@ unsigned int ProcessNodeReportEvents(const char* args) { return event_flags; } -unsigned int ProcessNodeReportCoreSwitch(const char* args) { +unsigned int ProcessNode_ReportCoreSwitch(const char* args) { if (strlen(args) == 0) { - fprintf(stderr, "Missing argument for nodereport core switch option\n"); + fprintf(stderr, "Missing argument for node-report core switch option\n"); } else { // Parse the supplied switch if (!strncmp(args, "yes", sizeof("yes") - 1) || !strncmp(args, "true", sizeof("true") - 1)) { @@ -139,18 +139,18 @@ unsigned int ProcessNodeReportCoreSwitch(const char* args) { } else if (!strncmp(args, "no", sizeof("no") - 1) || !strncmp(args, "false", sizeof("false") - 1)) { return 0; } else { - fprintf(stderr, "Unrecognised argument for nodereport core switch option: %s\n", args); + fprintf(stderr, "Unrecognised argument for node-report core switch option: %s\n", args); } } return 1; // Default is to produce core dumps } -unsigned int ProcessNodeReportSignal(const char* args) { +unsigned int ProcessNode_ReportSignal(const char* args) { #ifdef _WIN32 return 0; // no-op on Windows #else if (strlen(args) == 0) { - fprintf(stderr, "Missing argument for nodereport signal option\n"); + fprintf(stderr, "Missing argument for node-report signal option\n"); } else { // Parse the supplied switch if (!strncmp(args, "SIGUSR2", sizeof("SIGUSR2") - 1)) { @@ -158,40 +158,40 @@ unsigned int ProcessNodeReportSignal(const char* args) { } else if (!strncmp(args, "SIGQUIT", sizeof("SIGQUIT") - 1)) { return SIGQUIT; } else { - fprintf(stderr, "Unrecognised argument for nodereport signal option: %s\n", args); + fprintf(stderr, "Unrecognised argument for node-report signal option: %s\n", args); } } return SIGUSR2; // Default signal is SIGUSR2 #endif } -void ProcessNodeReportFileName(const char* args) { +void ProcessNode_ReportFileName(const char* args) { if (strlen(args) == 0) { - fprintf(stderr, "Missing argument for nodereport filename option\n"); + fprintf(stderr, "Missing argument for node-report filename option\n"); return; } if (strlen(args) > NR_MAXNAME) { - fprintf(stderr, "Supplied nodereport filename too long (max %d characters)\n", NR_MAXNAME); + fprintf(stderr, "Supplied node-report filename too long (max %d characters)\n", NR_MAXNAME); return; } snprintf(report_filename, sizeof(report_filename), "%s", args); } -void ProcessNodeReportDirectory(const char* args) { +void ProcessNode_ReportDirectory(const char* args) { if (strlen(args) == 0) { - fprintf(stderr, "Missing argument for nodereport directory option\n"); + fprintf(stderr, "Missing argument for directory option\n"); return; } if (strlen(args) > NR_MAXPATH) { - fprintf(stderr, "Supplied nodereport directory path too long (max %d characters)\n", NR_MAXPATH); + fprintf(stderr, "Supplied node-report directory path too long (max %d characters)\n", NR_MAXPATH); return; } snprintf(report_directory, sizeof(report_directory), "%s", args); } -unsigned int ProcessNodeReportVerboseSwitch(const char* args) { +unsigned int ProcessNode_ReportVerboseSwitch(const char* args) { if (strlen(args) == 0) { - fprintf(stderr, "Missing argument for nodereport verbose switch option\n"); + fprintf(stderr, "Missing argument for node-report verbose switch option\n"); return 0; } // Parse the supplied switch @@ -200,7 +200,7 @@ unsigned int ProcessNodeReportVerboseSwitch(const char* args) { } else if (!strncmp(args, "no", sizeof("no") - 1) || !strncmp(args, "false", sizeof("false") - 1)) { return 0; } else { - fprintf(stderr, "Unrecognised argument for nodereport verbose switch option: %s\n", args); + fprintf(stderr, "Unrecognised argument for node-report verbose switch option: %s\n", args); } return 0; // Default is verbose mode off } @@ -297,7 +297,7 @@ void SetVersionString(Isolate* isolate) { } /******************************************************************************* - * Function to save the nodereport module load time value + * Function to save the node-report module load time value *******************************************************************************/ void SetLoadTime() { #ifdef _WIN32 @@ -370,17 +370,17 @@ void SetCommandLine() { } /******************************************************************************* - * Main API function to write a NodeReport to file. + * Main API function to write a node-report to file. * * Parameters: * Isolate* isolate * DumpEvent event * const char* message * const char* location - * char* name - in/out - returns the NodeReport filename + * char* name - in/out - returns the node-report filename ******************************************************************************/ -void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, const char* location, char* name) { - // Recursion check for NodeReport in progress, bail out +void TriggerNode_Report(Isolate* isolate, DumpEvent event, const char* message, const char* location, char* name) { + // Recursion check for node-report in progress, bail out if (report_active) return; report_active = true; @@ -397,7 +397,7 @@ void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, c pid_t pid = getpid(); #endif - // Determine the required NodeReport filename. In order of priority: + // Determine the required node-report filename. In order of priority: // 1) supplied on API 2) configured on startup 3) default generated char filename[NR_MAXNAME + 1] = ""; if (name != nullptr && strlen(name) > 0) { @@ -407,8 +407,8 @@ void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, c // File name was supplied via start-up option, use that snprintf(filename, sizeof(filename), "%s", report_filename); } else { - // Construct the NodeReport filename, with timestamp, pid and sequence number - snprintf(filename, sizeof(filename), "%s", "NodeReport"); + // Construct the node-report filename, with timestamp, pid and sequence number + snprintf(filename, sizeof(filename), "%s", "node-report"); seq++; #ifdef _WIN32 snprintf(&filename[strlen(filename)], sizeof(filename) - strlen(filename), @@ -425,7 +425,7 @@ void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, c #endif } - // Open the NodeReport file stream for writing. Supports stdout/err, user-specified or (default) generated name + // Open the node-report file stream for writing. Supports stdout/err, user-specified or (default) generated name FILE* fp = nullptr; if (!strncmp(filename, "stdout", sizeof("stdout") - 1)) { fp = stdout; @@ -457,10 +457,10 @@ void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, c } } - // File stream opened OK, now start printing the NodeReport content, starting with the title + // File stream opened OK, now start printing the node-report content, starting with the title // and header information (event, filename, timestamp and pid) fprintf(fp, "================================================================================\n"); - fprintf(fp, "==== NodeReport ================================================================\n"); + fprintf(fp, "==== node-report ================================================================\n"); fprintf(fp, "\nEvent: %s, location: \"%s\"\n", message, location); fprintf(fp, "Filename: %s\n", filename); @@ -532,7 +532,7 @@ void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, c fprintf(stderr, "Node.js report completed\n"); if (name != nullptr) { - snprintf(name, NR_MAXNAME + 1, "%s", filename); // return the NodeReport file name + snprintf(name, NR_MAXNAME + 1, "%s", filename); // return the node-report file name } report_active = false; } @@ -556,10 +556,10 @@ static void PrintVersionInformation(FILE* fp, Isolate* isolate) { // Print Node.js and deps component versions fprintf(fp, "\n%s", version_string.c_str()); - // Print NodeReport version - // e.g. NodeReport version: 1.0.6 (built against Node.js v6.9.1) - fprintf(fp, "\nNodeReport version: %s (built against Node.js v%s)\n", - NODEREPORT_VERSION, NODE_VERSION_STRING); + // Print node-report version + // e.g. node-report version: 1.0.6 (built against Node.js v6.9.1) + fprintf(fp, "\nnode-report version: %s (built against Node.js v%s)\n", + NODE_REPORT_VERSION, NODE_VERSION_STRING); // Print operating system and machine information (Windows) #ifdef _WIN32 @@ -830,7 +830,7 @@ void PrintNativeStack(FILE* fp) { return; } - // Print the native frames, omitting the top 3 frames as they are in nodereport code + // Print the native frames, omitting the top 3 frames as they are in node-report code // backtrace_symbols_fd(frames, size, fileno(fp)); for (int i = 2; i < size; i++) { // print frame index and instruction address @@ -1050,4 +1050,4 @@ static void WriteInteger(FILE* fp, size_t value) { } } -} // namespace nodereport +} // namespace node-report diff --git a/src/node_report.h b/src/node_report.h index 95148e7..e5bb312 100644 --- a/src/node_report.h +++ b/src/node_report.h @@ -10,7 +10,7 @@ #endif #endif -namespace nodereport { +namespace node-report { using v8::Isolate; using v8::Local; @@ -21,7 +21,7 @@ using v8::Number; using v8::String; using v8::Value; -// Bit-flags for NodeReport trigger options +// Bit-flags for node-report trigger options #define NR_EXCEPTION 0x01 #define NR_FATALERROR 0x02 #define NR_SIGNAL 0x04 @@ -33,14 +33,14 @@ using v8::Value; enum DumpEvent {kException, kFatalError, kSignal_JS, kSignal_UV, kJavaScript}; -void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, const char* location, char* name); +void Triggernode-report(Isolate* isolate, DumpEvent event, const char* message, const char* location, char* name); -unsigned int ProcessNodeReportEvents(const char* args); -unsigned int ProcessNodeReportCoreSwitch(const char* args); -unsigned int ProcessNodeReportSignal(const char* args); -void ProcessNodeReportFileName(const char* args); -void ProcessNodeReportDirectory(const char* args); -unsigned int ProcessNodeReportVerboseSwitch(const char* args); +unsigned int ProcessNode_ReportEvents(const char* args); +unsigned int ProcessNode_ReportCoreSwitch(const char* args); +unsigned int ProcessNode_ReportSignal(const char* args); +void ProcessNode_ReportFileName(const char* args); +void ProcessNode_ReportDirectory(const char* args); +unsigned int ProcessNode_ReportVerboseSwitch(const char* args); void SetLoadTime(); void SetVersionString(Isolate* isolate); @@ -78,6 +78,6 @@ inline static int snprintf(char* buffer, size_t n, const char* format, ...) { #define __func__ __FUNCTION__ #endif // defined( _MSC_VER ) && (_MSC_VER < 1900) -} // namespace nodereport +} // namespace node-report #endif // SRC_NODE_REPORT_H_ diff --git a/test/common.js b/test/common.js index bc11f42..75ac46b 100644 --- a/test/common.js +++ b/test/common.js @@ -3,7 +3,7 @@ const fs = require('fs'); const REPORT_SECTIONS = [ - 'NodeReport', + 'node-report', 'JavaScript Stack Trace', 'JavaScript Heap', 'System Information' @@ -12,8 +12,8 @@ const REPORT_SECTIONS = [ const reNewline = '(?:\\r*\\n)'; exports.findReports = (pid) => { - // Default filenames are of the form NodeReport..