Expose crash reporter start for child node processes
This commit is contained in:
parent
61aff5ed35
commit
d4b44d8b69
6 changed files with 77 additions and 11 deletions
|
@ -14,11 +14,11 @@
|
||||||
#include "gin/public/isolate_holder.h"
|
#include "gin/public/isolate_holder.h"
|
||||||
#include "gin/v8_initializer.h"
|
#include "gin/v8_initializer.h"
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
#include "atom/common/api/atom_bindings.h"
|
#include "atom/common/api/atom_bindings.h"
|
||||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
|
|
||||||
|
@ -58,10 +58,12 @@ int NodeMain(int argc, char *argv[]) {
|
||||||
if (node_debugger.IsRunning())
|
if (node_debugger.IsRunning())
|
||||||
env->AssignToContext(v8::Debug::GetDebugContext(gin_env.isolate()));
|
env->AssignToContext(v8::Debug::GetDebugContext(gin_env.isolate()));
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
mate::Dictionary process(gin_env.isolate(), env->process_object());
|
mate::Dictionary process(gin_env.isolate(), env->process_object());
|
||||||
|
#if defined(OS_WIN)
|
||||||
process.SetMethod("log", &AtomBindings::Log);
|
process.SetMethod("log", &AtomBindings::Log);
|
||||||
#endif
|
#endif
|
||||||
|
process.SetMethod("startCrashReporter", &AtomBindings::StartCrashReporter);
|
||||||
|
process.SetMethod("crash", &AtomBindings::Crash);
|
||||||
|
|
||||||
node::LoadEnvironment(env);
|
node::LoadEnvironment(env);
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,12 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "atom/common/atom_version.h"
|
#include "atom/common/atom_version.h"
|
||||||
#include "atom/common/chrome_version.h"
|
#include "atom/common/chrome_version.h"
|
||||||
|
#include "atom/common/crash_reporter/crash_reporter.h"
|
||||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
|
@ -23,10 +25,6 @@ namespace {
|
||||||
// Dummy class type that used for crashing the program.
|
// Dummy class type that used for crashing the program.
|
||||||
struct DummyClass { bool crash; };
|
struct DummyClass { bool crash; };
|
||||||
|
|
||||||
void Crash() {
|
|
||||||
static_cast<DummyClass*>(nullptr)->crash = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Hang() {
|
void Hang() {
|
||||||
for (;;)
|
for (;;)
|
||||||
base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
|
base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
|
||||||
|
@ -76,7 +74,7 @@ v8::Local<v8::Value> GetSystemMemoryInfo(v8::Isolate* isolate,
|
||||||
// we can get the stack trace.
|
// we can get the stack trace.
|
||||||
void FatalErrorCallback(const char* location, const char* message) {
|
void FatalErrorCallback(const char* location, const char* message) {
|
||||||
LOG(ERROR) << "Fatal error in V8: " << location << " " << message;
|
LOG(ERROR) << "Fatal error in V8: " << location << " " << message;
|
||||||
Crash();
|
AtomBindings::Crash();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -95,7 +93,7 @@ void AtomBindings::BindTo(v8::Isolate* isolate,
|
||||||
v8::V8::SetFatalErrorHandler(FatalErrorCallback);
|
v8::V8::SetFatalErrorHandler(FatalErrorCallback);
|
||||||
|
|
||||||
mate::Dictionary dict(isolate, process);
|
mate::Dictionary dict(isolate, process);
|
||||||
dict.SetMethod("crash", &Crash);
|
dict.SetMethod("crash", &AtomBindings::Crash);
|
||||||
dict.SetMethod("hang", &Hang);
|
dict.SetMethod("hang", &Hang);
|
||||||
dict.SetMethod("log", &Log);
|
dict.SetMethod("log", &Log);
|
||||||
dict.SetMethod("getProcessMemoryInfo", &GetProcessMemoryInfo);
|
dict.SetMethod("getProcessMemoryInfo", &GetProcessMemoryInfo);
|
||||||
|
@ -159,4 +157,29 @@ void AtomBindings::Log(const base::string16& message) {
|
||||||
std::cout << message << std::flush;
|
std::cout << message << std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AtomBindings::Crash() {
|
||||||
|
static_cast<DummyClass*>(nullptr)->crash = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AtomBindings::StartCrashReporter(
|
||||||
|
const std::string& productName,
|
||||||
|
const std::string& companyName,
|
||||||
|
const std::string& submitUrl,
|
||||||
|
const std::string& tmpPath,
|
||||||
|
const std::map<std::string, std::string>& extra_parameters) {
|
||||||
|
std::map<std::string, std::string> allParameters;
|
||||||
|
allParameters.insert(std::make_pair("_productName", productName));
|
||||||
|
allParameters.insert(std::make_pair("_companyName", companyName));
|
||||||
|
allParameters.insert(extra_parameters.begin(), extra_parameters.end());
|
||||||
|
|
||||||
|
auto reporter = crash_reporter::CrashReporter::GetInstance();
|
||||||
|
reporter->Start(productName,
|
||||||
|
companyName,
|
||||||
|
submitUrl,
|
||||||
|
base::FilePath(tmpPath),
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
allParameters);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#define ATOM_COMMON_API_ATOM_BINDINGS_H_
|
#define ATOM_COMMON_API_ATOM_BINDINGS_H_
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "base/macros.h"
|
#include "base/macros.h"
|
||||||
#include "base/strings/string16.h"
|
#include "base/strings/string16.h"
|
||||||
|
@ -28,6 +30,13 @@ class AtomBindings {
|
||||||
void BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process);
|
void BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process);
|
||||||
|
|
||||||
static void Log(const base::string16& message);
|
static void Log(const base::string16& message);
|
||||||
|
static void Crash();
|
||||||
|
static void StartCrashReporter(
|
||||||
|
const std::string& productName,
|
||||||
|
const std::string& companyName,
|
||||||
|
const std::string& submitUrl,
|
||||||
|
const std::string& tmpPath,
|
||||||
|
const std::map<std::string, std::string>& extra_parameters);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ActivateUVLoop(v8::Isolate* isolate);
|
void ActivateUVLoop(v8::Isolate* isolate);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const {app, BrowserWindow} = require('electron')
|
const {app, BrowserWindow, crashReporter} = require('electron')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
let mainWindow = null
|
let mainWindow = null
|
||||||
|
@ -20,6 +20,11 @@ exports.load = (appUrl) => {
|
||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
options.icon = path.join(__dirname, 'icon.png')
|
options.icon = path.join(__dirname, 'icon.png')
|
||||||
}
|
}
|
||||||
|
crashReporter.start({
|
||||||
|
submitURL: "http://localhost:8080/uploadDump/mainDump",
|
||||||
|
companyName: "Main Company",
|
||||||
|
productName: "Main Product"
|
||||||
|
})
|
||||||
|
|
||||||
mainWindow = new BrowserWindow(options)
|
mainWindow = new BrowserWindow(options)
|
||||||
mainWindow.loadURL(appUrl)
|
mainWindow.loadURL(appUrl)
|
||||||
|
|
12
default_app/forkedProcess.js
Normal file
12
default_app/forkedProcess.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
const os = require('os')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
let productName = 'Child Product';
|
||||||
|
let companyName = 'Child Company';
|
||||||
|
let tmpPath = path.join(os.tmpdir(), productName + ' Crashes');
|
||||||
|
|
||||||
|
process.startCrashReporter(productName, companyName, 'http://localhost:8080/uploadDump/childDump', tmpPath, {
|
||||||
|
randomData1: 'The Holidays are here!',
|
||||||
|
randomData2: 'Happy New Year!'
|
||||||
|
});
|
||||||
|
process.crash();
|
|
@ -114,11 +114,24 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
const {remote, shell} = require('electron');
|
const {remote, shell, crashReporter} = require('electron');
|
||||||
|
const cp = require('child_process')
|
||||||
|
|
||||||
const execPath = remote.process.execPath;
|
const execPath = remote.process.execPath;
|
||||||
const command = execPath + ' path-to-your-app';
|
const command = execPath + ' path-to-your-app';
|
||||||
|
|
||||||
|
crashReporter.start({
|
||||||
|
productName: 'Renderer Product',
|
||||||
|
companyName: 'Renderer Company',
|
||||||
|
submitURL: 'http://localhost:8080/uploadDump/rendererDump'
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", function(event) {
|
||||||
|
document.getElementById('crashMe').addEventListener('click', () => {
|
||||||
|
cp.fork('./default_app/forkedProcess')
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
document.onclick = function(e) {
|
document.onclick = function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (e.target.tagName == 'A')
|
if (e.target.tagName == 'A')
|
||||||
|
@ -157,6 +170,8 @@
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
||||||
|
<button id="crashMe">Fork a process which crashes</button>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
To run your app with Electron, execute the following command in your
|
To run your app with Electron, execute the following command in your
|
||||||
Console (or Terminal):
|
Console (or Terminal):
|
||||||
|
|
Loading…
Reference in a new issue