-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: print location and message on fatal error
PR-URL: #137 Reviewed-BY: hyj1991 <[email protected]>
- Loading branch information
1 parent
95ed727
commit eb5fbc5
Showing
8 changed files
with
53 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,40 @@ | ||
#include "../commands/report/node_report.h" | ||
#include "../library/utils.h" | ||
#include "../logger.h" | ||
#include "../platform/platform.h" | ||
#include "commands/report/node_report.h" | ||
#include "configure-inl.h" | ||
#include "library/utils.h" | ||
#include "logger.h" | ||
#include "nan.h" | ||
#include "platform/platform.h" | ||
#include "util.h" | ||
#include "xpf_v8.h" | ||
|
||
namespace xprofiler { | ||
using std::string; | ||
using std::to_string; | ||
using v8::Isolate; | ||
|
||
static const char module_type[] = "fatal_error"; | ||
constexpr char module_type[] = "fatal_error"; | ||
|
||
[[noreturn]] void OnFatalError(const char* location, const char* message) { | ||
if (location) { | ||
fprintf(stderr, "xprofiler: %s %s\n", location, message); | ||
} else { | ||
fprintf(stderr, "xprofiler: %s\n", message); | ||
} | ||
fflush(stderr); | ||
|
||
static void OnFatalError(const char* location, const char* message) { | ||
Isolate* isolate = Isolate::GetCurrent(); | ||
string filepath = GetLogDir() + GetSep() + "x-fatal-error-" + | ||
to_string(GetPid()) + "-" + ConvertTime("%Y%m%d") + "-" + | ||
RandNum() + ".diag"; | ||
|
||
Info(module_type, "dump report to %s.", filepath.c_str()); | ||
Isolate* isolate = TryGetCurrentIsolate(); | ||
NodeReport::GetNodeReport(isolate, filepath, location, message, true); | ||
Info(module_type, "report dumped."); | ||
raise(SIGABRT); | ||
|
||
Abort(); | ||
} | ||
|
||
void SetFatalErrorHandler() { | ||
Isolate* isolate = Isolate::GetCurrent(); | ||
void SetFatalErrorHandler(v8::Isolate* isolate) { | ||
isolate->SetFatalErrorHandler(OnFatalError); | ||
} | ||
} // namespace xprofiler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
#ifndef _SRC_HOOKS_FATAL_ERROR_H | ||
#define _SRC_HOOKS_FATAL_ERROR_H | ||
#ifndef XPROFILER_SRC_HOOKS_FATAL_ERROR_H | ||
#define XPROFILER_SRC_HOOKS_FATAL_ERROR_H | ||
|
||
namespace xprofiler { | ||
void SetFatalErrorHandler(); | ||
[[noreturn]] void OnFatalError(const char* location, const char* message); | ||
void SetFatalErrorHandler(v8::Isolate* isolate); | ||
} | ||
|
||
#endif | ||
#endif /* XPROFILER_SRC_HOOKS_FATAL_ERROR_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
#ifndef _SRC_HOOKS_SET_HOOKS_H | ||
#define _SRC_HOOKS_SET_HOOKS_H | ||
#ifndef XPROFILER_SRC_HOOKS_SET_HOOKS_H | ||
#define XPROFILER_SRC_HOOKS_SET_HOOKS_H | ||
|
||
#include "nan.h" | ||
|
||
namespace xprofiler { | ||
using Nan::FunctionCallbackInfo; | ||
using v8::Value; | ||
void SetHooks(const FunctionCallbackInfo<Value>& info); | ||
void SetHooks(const Nan::FunctionCallbackInfo<v8::Value>& info); | ||
} // namespace xprofiler | ||
|
||
#endif | ||
#endif /* XPROFILER_SRC_HOOKS_SET_HOOKS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters