-
Notifications
You must be signed in to change notification settings - Fork 29.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start crash reporter inside child processes (#27180)
* Use service to get crash reporter start options * some refactorings and fixes * Move crashesDirectory to the main payload from extra bag
- Loading branch information
1 parent
f962f52
commit 29a7a86
Showing
7 changed files
with
171 additions
and
97 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 was deleted.
Oops, something went wrong.
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
43 changes: 43 additions & 0 deletions
43
src/vs/workbench/services/crashReporter/common/crashReporterService.ts
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
'use strict'; | ||
|
||
import nls = require('vs/nls'); | ||
import { IConfigurationRegistry, Extensions } from 'vs/platform/configuration/common/configurationRegistry'; | ||
import { Registry } from 'vs/platform/platform'; | ||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; | ||
|
||
export const ICrashReporterService = createDecorator<ICrashReporterService>('crashReporterService'); | ||
|
||
export const TELEMETRY_SECTION_ID = 'telemetry'; | ||
|
||
export interface ICrashReporterConfig { | ||
enableCrashReporter: boolean; | ||
} | ||
|
||
const configurationRegistry = <IConfigurationRegistry>Registry.as(Extensions.Configuration); | ||
configurationRegistry.registerConfiguration({ | ||
'id': TELEMETRY_SECTION_ID, | ||
'order': 110, | ||
title: nls.localize('telemetryConfigurationTitle', "Telemetry"), | ||
'type': 'object', | ||
'properties': { | ||
'telemetry.enableCrashReporter': { | ||
'type': 'boolean', | ||
'description': nls.localize('telemetry.enableCrashReporting', "Enable crash reports to be sent to Microsoft.\nThis option requires restart to take effect."), | ||
'default': true | ||
} | ||
} | ||
}); | ||
|
||
export interface ICrashReporterService { | ||
_serviceBrand: any; | ||
getChildProcessStartOptions(processName: string): Electron.CrashReporterStartOptions; | ||
} | ||
|
||
export const NullCrashReporterService: ICrashReporterService = { | ||
_serviceBrand: undefined, | ||
getChildProcessStartOptions(processName: string) { return undefined; } | ||
}; |
91 changes: 91 additions & 0 deletions
91
src/vs/workbench/services/crashReporter/electron-browser/crashReporterService.ts
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
'use strict'; | ||
|
||
import { onUnexpectedError } from 'vs/base/common/errors'; | ||
import { assign, clone } from 'vs/base/common/objects'; | ||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; | ||
import { IWindowsService } from 'vs/platform/windows/common/windows'; | ||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; | ||
import { crashReporter } from 'electron'; | ||
import product from 'vs/platform/node/product'; | ||
import pkg from 'vs/platform/node/package'; | ||
import * as os from 'os'; | ||
import { ICrashReporterService, TELEMETRY_SECTION_ID, ICrashReporterConfig } from "vs/workbench/services/crashReporter/common/crashReporterService"; | ||
import { isWindows, isMacintosh, isLinux } from "vs/base/common/platform"; | ||
|
||
export class CrashReporterService implements ICrashReporterService { | ||
|
||
public _serviceBrand: any; | ||
|
||
private options: Electron.CrashReporterStartOptions; | ||
|
||
constructor( | ||
@ITelemetryService private telemetryService: ITelemetryService, | ||
@IWindowsService private windowsService: IWindowsService, | ||
@IConfigurationService configurationService: IConfigurationService | ||
) { | ||
const config = configurationService.getConfiguration<ICrashReporterConfig>(TELEMETRY_SECTION_ID); | ||
if (config.enableCrashReporter) { | ||
this.startCrashReporter(); | ||
} | ||
} | ||
|
||
private startCrashReporter(): void { | ||
|
||
// base options | ||
this.options = { | ||
companyName: product.crashReporter.companyName, | ||
productName: product.crashReporter.productName, | ||
submitURL: this.getSubmitURL() | ||
}; | ||
|
||
// mixin telemetry info and product info | ||
this.telemetryService.getTelemetryInfo() | ||
.then(info => { | ||
assign(this.options, { | ||
extra: { | ||
vscode_sessionId: info.sessionId, | ||
vscode_version: pkg.version, | ||
vscode_commit: product.commit, | ||
vscode_machineId: info.machineId | ||
} | ||
}); | ||
|
||
// start crash reporter right here | ||
crashReporter.start(clone(this.options)); | ||
|
||
// start crash reporter in the main process | ||
return this.windowsService.startCrashReporter(this.options); | ||
}) | ||
.done(null, onUnexpectedError); | ||
} | ||
|
||
private getSubmitURL(): string { | ||
let submitURL: string; | ||
if (isWindows) { | ||
submitURL = product.hockeyApp[`win32-${process.arch}`]; | ||
} else if (isMacintosh) { | ||
submitURL = product.hockeyApp.darwin; | ||
} else if (isLinux) { | ||
submitURL = product.hockeyApp[`linux-${process.arch}`]; | ||
} | ||
|
||
return submitURL; | ||
} | ||
|
||
public getChildProcessStartOptions(name: string): Electron.CrashReporterStartOptions { | ||
|
||
// Experimental attempt on Mac only for now | ||
if (isMacintosh) { | ||
const childProcessOptions = clone(this.options); | ||
childProcessOptions.extra.processName = name; | ||
childProcessOptions.crashesDirectory = os.tmpdir(); | ||
return childProcessOptions; | ||
} | ||
|
||
return void 0; | ||
} | ||
} |