Expose crash reporter start for child node processes

This commit is contained in:
Ramya Achutha Rao 2016-12-01 18:19:57 -08:00 committed by Kevin Sawicki
parent 61aff5ed35
commit d4b44d8b69
6 changed files with 77 additions and 11 deletions

View file

@ -14,11 +14,11 @@
#include "gin/public/isolate_holder.h"
#include "gin/v8_initializer.h"
#if defined(OS_WIN)
#include "atom/common/api/atom_bindings.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "native_mate/dictionary.h"
#endif
#include "atom/common/node_includes.h"
@ -58,10 +58,12 @@ int NodeMain(int argc, char *argv[]) {
if (node_debugger.IsRunning())
env->AssignToContext(v8::Debug::GetDebugContext(gin_env.isolate()));
#if defined(OS_WIN)
mate::Dictionary process(gin_env.isolate(), env->process_object());
#if defined(OS_WIN)
process.SetMethod("log", &AtomBindings::Log);
#endif
process.SetMethod("startCrashReporter", &AtomBindings::StartCrashReporter);
process.SetMethod("crash", &AtomBindings::Crash);
node::LoadEnvironment(env);

View file

@ -6,10 +6,12 @@
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include "atom/common/atom_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/node_includes.h"
#include "base/logging.h"
@ -23,10 +25,6 @@ namespace {
// Dummy class type that used for crashing the program.
struct DummyClass { bool crash; };
void Crash() {
static_cast<DummyClass*>(nullptr)->crash = true;
}
void Hang() {
for (;;)
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.
void FatalErrorCallback(const char* location, const char* message) {
LOG(ERROR) << "Fatal error in V8: " << location << " " << message;
Crash();
AtomBindings::Crash();
}
} // namespace
@ -95,7 +93,7 @@ void AtomBindings::BindTo(v8::Isolate* isolate,
v8::V8::SetFatalErrorHandler(FatalErrorCallback);
mate::Dictionary dict(isolate, process);
dict.SetMethod("crash", &Crash);
dict.SetMethod("crash", &AtomBindings::Crash);
dict.SetMethod("hang", &Hang);
dict.SetMethod("log", &Log);
dict.SetMethod("getProcessMemoryInfo", &GetProcessMemoryInfo);
@ -159,4 +157,29 @@ void AtomBindings::Log(const base::string16& message) {
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

View file

@ -6,6 +6,8 @@
#define ATOM_COMMON_API_ATOM_BINDINGS_H_
#include <list>
#include <map>
#include <string>
#include "base/macros.h"
#include "base/strings/string16.h"
@ -28,6 +30,13 @@ class AtomBindings {
void BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process);
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:
void ActivateUVLoop(v8::Isolate* isolate);

View file

@ -1,4 +1,4 @@
const {app, BrowserWindow} = require('electron')
const {app, BrowserWindow, crashReporter} = require('electron')
const path = require('path')
let mainWindow = null
@ -20,6 +20,11 @@ exports.load = (appUrl) => {
if (process.platform === 'linux') {
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.loadURL(appUrl)

View 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();

View file

@ -114,11 +114,24 @@
</head>
<body>
<script>
const {remote, shell} = require('electron');
const {remote, shell, crashReporter} = require('electron');
const cp = require('child_process')
const execPath = remote.process.execPath;
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) {
e.preventDefault();
if (e.target.tagName == 'A')
@ -157,6 +170,8 @@
<div class="container">
<button id="crashMe">Fork a process which crashes</button>
<p>
To run your app with Electron, execute the following command in your
Console (or Terminal):