Skip to content

Commit

Permalink
fix: not output js stack on fatal error & update dependencies
Browse files Browse the repository at this point in the history
PR-URL: #64
Reviewed-BY: hyj1991 <[email protected]>
  • Loading branch information
hyj1991 authored May 30, 2020
1 parent 40d7883 commit 536160b
Show file tree
Hide file tree
Showing 12 changed files with 13,167 additions and 9,154 deletions.
42 changes: 42 additions & 0 deletions .autod.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

module.exports = {
write: true,
prefix: '^',
test: [
'test',
],
dep: [
'bindings',
'nan',
'node-gyp',
'uuid',
'yargs',
],
devdep: [
'@istanbuljs/schema',
'autod',
'clang-format',
'codecov',
'eslint',
'expect.js',
'formstream',
'mm',
'mocha',
'moment',
'nyc',
'tunnel-agent',
'urllib',
],
exclude: [
'./build',
'./scripts',
'./test/fixtures',
'./demo.js',
'./nyc.config.js',
],
semver: [
'eslint@6',
'node-gyp@6',
]
};
2 changes: 1 addition & 1 deletion lib/xctl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const os = require('os');
const fs = require('fs');
const net = require('net');
const path = require('path');
const uuid = require('uuid/v4');
const { v4: uuid } = require('uuid');
const pkg = require('../package.json');
const utils = require('../lib/utils');
const { StringDecoder } = require('string_decoder');
Expand Down
2 changes: 1 addition & 1 deletion nyc.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { defaultExclude } = require('test-exclude');
const defaultExclude = require('@istanbuljs/schema/default-exclude');
const os = require('os');

let platformExclude = [
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@
"dependencies": {
"bindings": "^1.5.0",
"nan": "^2.14.1",
"node-gyp": "^6.0.0",
"uuid": "^3.3.3",
"yargs": "^14.2.0"
"node-gyp": "^6.1.0",
"uuid": "^8.1.0",
"yargs": "^15.3.1"
},
"devDependencies": {
"@istanbuljs/schema": "^0.1.2",
"autod": "^3.1.0",
"clang-format": "^1.2.4",
"codecov": "^3.6.1",
"eslint": "^6.6.0",
"clang-format": "^1.4.0",
"codecov": "^3.7.0",
"eslint": "^6.8.0",
"expect.js": "^0.3.1",
"formstream": "^1.1.0",
"mm": "^2.5.0",
"mocha": "^6.2.2",
"moment": "^2.24.0",
"nyc": "^14.1.1",
"test-exclude": "^5.2.3",
"mm": "^3.2.0",
"mocha": "^7.2.0",
"moment": "^2.26.0",
"nyc": "^15.0.1",
"tunnel-agent": "^0.6.0",
"urllib": "^2.34.1"
"urllib": "^2.35.0"
},
"xctlIpcPath": {
"unix": "xprofiler-ctl-uds-path.sock",
"win32": "xprofiler-ctl"
},
"blurryTag": "__"
}
}
8 changes: 7 additions & 1 deletion src/commands/report/javascript_stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using v8::SampleInfo;
using v8::StackFrame;
using v8::StackTrace;

void SetJavaScriptStack(JSONWriter* writer) {
void SetJavaScriptStack(JSONWriter* writer, bool fatal_error) {
HandleScope scope;
RegisterState state;
SampleInfo info;
Expand All @@ -48,6 +48,12 @@ void SetJavaScriptStack(JSONWriter* writer) {
writer->json_keyvalue("vmState", "unknown");
}

if (fatal_error) {
writer->json_arraystart("jsStacks");
writer->json_arrayend();
return;
}

// get js stacks
Local<StackTrace> stack = StackTrace::CurrentStackTrace(
isolate, kMaxFramesCount, StackTrace::kDetailed);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/report/javascript_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "../../library/writer.h"

namespace xprofiler {
void SetJavaScriptStack(JSONWriter* writer);
void SetJavaScriptStack(JSONWriter* writer, bool fatal_error = false);
}

#endif
12 changes: 6 additions & 6 deletions src/commands/report/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ using std::ofstream;
NodeReport::NodeReport() {}
NodeReport::~NodeReport() {}

static void WriteNodeReport(JSONWriter *writer, string location,
string message) {
static void WriteNodeReport(JSONWriter *writer, string location, string message,
bool fatal_error) {
writer->json_start();

writer->json_keyvalue("pid", GetPid());
Expand All @@ -32,7 +32,7 @@ static void WriteNodeReport(JSONWriter *writer, string location,
writer->json_keyvalue("loadTime", GetStartTime("%Y-%m-%d %H:%M:%S"));
writer->json_keyvalue("dumpTime", ConvertTime("%Y-%m-%d %H:%M:%S"));

SetJavaScriptStack(writer);
SetJavaScriptStack(writer, fatal_error);
SetNativeStack(writer);
SetHeapStatistics(writer);
SetUvStatistics(writer);
Expand All @@ -41,8 +41,8 @@ static void WriteNodeReport(JSONWriter *writer, string location,
writer->json_end();
}

void NodeReport::GetNodeReport(string filepath, string location,
string message) {
void NodeReport::GetNodeReport(string filepath, string location, string message,
bool fatal_error) {
ofstream outfile;
outfile.open(filepath, ios::out | ios::binary);
if (!outfile.is_open()) {
Expand All @@ -51,7 +51,7 @@ void NodeReport::GetNodeReport(string filepath, string location,
return;
}
JSONWriter writer(outfile);
WriteNodeReport(&writer, location, message);
WriteNodeReport(&writer, location, message, fatal_error);
outfile.close();
}
} // namespace xprofiler
3 changes: 2 additions & 1 deletion src/commands/report/node_report.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class NodeReport {
NodeReport();
virtual ~NodeReport();
static void GetNodeReport(string filepath, string location = "Active Dump",
string message = "Active Dump");
string message = "Active Dump",
bool fatal_error = false);
};
} // namespace xprofiler

Expand Down
4 changes: 3 additions & 1 deletion src/hooks/fatal_error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ static void OnFatalError(const char* location, const char* message) {
to_string(GetPid()) + "-" + ConvertTime("%Y%m%d") + "-" +
RandNum() + ".diag";
Info(module_type, "dump report to %s.", filepath.c_str());
NodeReport::GetNodeReport(filepath, location, message);
NodeReport::GetNodeReport(filepath, location, message, true);
Info(module_type, "report dumped.");
raise(SIGABRT);
}

void SetFatalErrorHandler() {
Expand Down
Loading

0 comments on commit 536160b

Please sign in to comment.