diff options
author | Gireesh Punathil <gpunathi@in.ibm.com> | 2018-09-05 17:06:59 +0300 |
---|---|---|
committer | Gireesh Punathil <gpunathi@in.ibm.com> | 2019-01-18 08:04:04 +0300 |
commit | 4f6797378eb6dd290dd5d8dc6417fea22d42ebad (patch) | |
tree | 88967037a1ba9aec47faea701efecf4f44007587 /src/node_report.h | |
parent | 01cd21973b26a2cbacbe143c5983cb4adf8e7681 (diff) |
src: merge into core
Make node-report part of core runtime because:
1. When enabled, node-report significantly helps root cause various
types of problems, including support issues sent to the various repos
of the Node.js organization.
2. The requirement of explicitly adding the dependency to node-report
in user applications often represents a blocker to adoption.
Major deviation from the module version of the node-report is that the
report is generated in JSON format, as opposed to human readable text.
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)
Co-authored-by: Bidisha Pyne <bidipyne@in.ibm.com>
Co-authored-by: Howard Hellyer <hhellyer@uk.ibm.com>
Co-authored-by: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Co-authored-by: Julian Alimin <dmastag@yahoo.com>
Co-authored-by: Lakshmi Swetha Gopireddy <lakshmigopireddy@in.ibm.com>
Co-authored-by: Manusaporn Treerungroj <m.treerungroj@gmail.com>
Co-authored-by: Michael Dawson <michael_dawson@ca.ibm.com>
Co-authored-by: Richard Chamberlain <richard_chamberlain@uk.ibm.com>
Co-authored-by: Richard Lau <riclau@uk.ibm.com>
Co-authored-by: Sam Roberts <vieuxtech@gmail.com>
Co-authored-by: Vipin Menon <vipinmv1@in.ibm.com>
PR-URL: https://github.com/nodejs/node/pull/22712
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <Michael_Dawson@ca.ibm.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Diffstat (limited to 'src/node_report.h')
-rw-r--r-- | src/node_report.h | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/src/node_report.h b/src/node_report.h new file mode 100644 index 00000000000..c64b9c9a20c --- /dev/null +++ b/src/node_report.h @@ -0,0 +1,165 @@ +#ifndef SRC_NODE_REPORT_H_ +#define SRC_NODE_REPORT_H_ + +#include <node.h> +#include <node_buffer.h> +#include <uv.h> +#include <algorithm> +#include <climits> +#include <cstdlib> +#include <cstring> +#include <queue> +#include <string> +#include <utility> +#include <vector> +#include "v8.h" + +#include <stdio.h> +#include <stdlib.h> +#include <iomanip> +#include <iostream> +#include <sstream> + +#ifdef _WIN32 +#include <time.h> +#else +#include <sys/time.h> +#include <sys/types.h> +#include <unistd.h> +#endif + +namespace report { + +#ifdef _WIN32 +typedef SYSTEMTIME TIME_TYPE; +typedef DWORD PID_TYPE; +#define PATHSEP "\\" +#else // UNIX, OSX +typedef struct tm TIME_TYPE; +typedef pid_t PID_TYPE; +#define PATHSEP "/" +#endif + +void InitializeReport(v8::Isolate* isolate, node::Environment* env); + +// Function declarations - functions in src/node_report.cc +std::string TriggerNodeReport(v8::Isolate* isolate, + node::Environment* env, + const char* message, + const char* location, + std::string name, + v8::Local<v8::String> stackstr); +void GetNodeReport(v8::Isolate* isolate, + node::Environment* env, + const char* message, + const char* location, + v8::Local<v8::String> stackstr, + std::ostream& out); + +// Function declarations - utility functions in src/utilities.cc +void ReportEndpoints(uv_handle_t* h, std::ostringstream& out); +void WalkHandle(uv_handle_t* h, void* arg); +std::string EscapeJsonChars(const std::string& str); + +// Function declarations - export functions in src/node_report_module.cc +void TriggerReport(const v8::FunctionCallbackInfo<v8::Value>& info); +void GetReport(const v8::FunctionCallbackInfo<v8::Value>& info); + +// Node.js boot time - defined in src/node.cc +extern double prog_start_time; + +// JSON compiler definitions. +class JSONWriter { + public: + explicit JSONWriter(std::ostream& out) + : out_(out), indent_(0), state_(JSONOBJECT) {} + + inline void indent() { indent_ += 2; } + inline void deindent() { indent_ -= 2; } + inline void advance() { + for (int i = 0; i < indent_; i++) out_ << " "; + } + + inline void json_start() { + if (state_ == JSONVALUE) out_ << ","; + out_ << "\n"; + advance(); + out_ << "{"; + indent(); + state_ = JSONOBJECT; + } + + inline void json_end() { + out_ << "\n"; + deindent(); + advance(); + out_ << "}"; + state_ = JSONVALUE; + } + template <typename T> + inline void json_objectstart(T key) { + if (state_ == JSONVALUE) out_ << ","; + out_ << "\n"; + advance(); + out_ << "\"" << key << "\"" + << ": {"; + indent(); + state_ = JSONOBJECT; + } + + template <typename T> + inline void json_arraystart(T key) { + if (state_ == JSONVALUE) out_ << ","; + out_ << "\n"; + advance(); + out_ << "\"" << key << "\"" + << ": ["; + indent(); + state_ = JSONOBJECT; + } + inline void json_objectend() { + out_ << "\n"; + deindent(); + advance(); + out_ << "}"; + state_ = JSONVALUE; + } + + inline void json_arrayend() { + out_ << "\n"; + deindent(); + advance(); + out_ << "]"; + state_ = JSONVALUE; + } + template <typename T, typename U> + inline void json_keyvalue(T key, U value) { + if (state_ == JSONVALUE) out_ << ","; + out_ << "\n"; + advance(); + out_ << "\"" << key << "\"" + << ": " + << "\""; + out_ << EscapeJsonChars(value) << "\""; + state_ = JSONVALUE; + } + + template <typename U> + inline void json_element(U value) { + if (state_ == JSONVALUE) out_ << ","; + out_ << "\n"; + advance(); + out_ << "\"" << EscapeJsonChars(value) << "\""; + state_ = JSONVALUE; + } + + private: + enum JSONState { JSONOBJECT, JSONVALUE }; + std::ostream& out_; + int indent_; + int state_; +}; + +} // namespace report + +#endif // SRC_NODE_REPORT_H_ |