Skip to content

Commit

Permalink
Issue reporter: Loading process information takes a long time, #42860
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachel Macfarlane committed Feb 5, 2018
1 parent d7f097c commit 004d668
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 50 deletions.
62 changes: 46 additions & 16 deletions src/vs/code/electron-browser/issue/issueReporterMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export class IssueReporter extends Disposable {
private telemetryService: ITelemetryService;
private issueReporterModel: IssueReporterModel;
private shouldQueueSearch = true;
private receivedSystemInfo = false;
private receivedPerformanceInfo = false;

constructor(configuration: IssueReporterConfiguration) {
super();
Expand All @@ -72,17 +74,26 @@ export class IssueReporter extends Disposable {
reprosWithoutExtensions: false
});

ipcRenderer.on('issueInfoResponse', (event, info) => {
ipcRenderer.on('issuePerformanceInfoResponse', (event, info) => {
this.issueReporterModel.update(info);
this.receivedPerformanceInfo = true;

this.updateAllBlocks(this.issueReporterModel.getData());
const state = this.issueReporterModel.getData();
this.updateProcessInfo(state);
this.updateWorkspaceInfo(state);
this.updatePreviewButtonState();
});

const submitButton = <HTMLButtonElement>document.getElementById('github-submit-btn');
submitButton.disabled = false;
submitButton.textContent = localize('previewOnGitHub', "Preview on GitHub");
ipcRenderer.on('issueSystemInfoResponse', (event, info) => {
this.issueReporterModel.update({ systemInfo: info });
this.receivedSystemInfo = true;

this.updateSystemInfo(this.issueReporterModel.getData());
this.updatePreviewButtonState();
});

ipcRenderer.send('issueInfoRequest');
ipcRenderer.send('issueSystemInfoRequest');
ipcRenderer.send('issuePerformanceInfoRequest');

if (window.document.documentElement.lang !== 'en') {
show(document.getElementById('english'));
Expand Down Expand Up @@ -209,6 +220,7 @@ export class IssueReporter extends Disposable {
private setEventHandlers(): void {
document.getElementById('issue-type').addEventListener('change', (event: Event) => {
this.issueReporterModel.update({ issueType: parseInt((<HTMLInputElement>event.target).value) });
this.updatePreviewButtonState();
this.render();
});

Expand Down Expand Up @@ -267,6 +279,34 @@ export class IssueReporter extends Disposable {
}
}

private updatePreviewButtonState() {
const submitButton = <HTMLButtonElement>document.getElementById('github-submit-btn');
if (this.isPreviewEnabled()) {
submitButton.disabled = false;
submitButton.textContent = localize('previewOnGitHub', "Preview on GitHub");
} else {
submitButton.disabled = true;
submitButton.textContent = localize('loadingData', "Loading data...");
}
}

private isPreviewEnabled() {
const issueType = this.issueReporterModel.getData().issueType;
if (issueType === IssueType.Bug && this.receivedSystemInfo) {
return true;
}

if (issueType === IssueType.PerformanceIssue && this.receivedSystemInfo && this.receivedPerformanceInfo) {
return true;
}

if (issueType === IssueType.FeatureRequest) {
return true;
}

return false;
}

@debounce(300)
private searchGitHub(event: Event): void {
const title = (<HTMLInputElement>event.target).value;
Expand Down Expand Up @@ -447,16 +487,6 @@ export class IssueReporter extends Disposable {
return true;
}

/**
* Update blocks
*/

private updateAllBlocks(state) {
this.updateSystemInfo(state);
this.updateProcessInfo(state);
this.updateWorkspaceInfo(state);
}

private updateSystemInfo = (state) => {
const target = document.querySelector('.block-system .block-info');
let tableHtml = '';
Expand Down
54 changes: 26 additions & 28 deletions src/vs/code/electron-main/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ export interface ProcessInfo {
name: string;
}

export interface DiagnosticInfo {
systemInfo?: SystemInfo;
export interface PerformanceInfo {
processInfo?: ProcessInfo[];
workspaceInfo?: string;
}

export function buildDiagnostics(info: IMainProcessInfo): Promise<DiagnosticInfo> {
export function getPerformanceInfo(info: IMainProcessInfo): Promise<PerformanceInfo> {
return listProcesses(info.mainPID).then(rootProcess => {
const workspaceInfoMessages = [];

Expand Down Expand Up @@ -79,13 +78,36 @@ export function buildDiagnostics(info: IMainProcessInfo): Promise<DiagnosticInfo
}

return {
systemInfo: getSystemInfo(info),
processInfo: getProcessList(info, rootProcess),
workspaceInfo: workspaceInfoMessages.join('\n')
};
});
}

export function getSystemInfo(info: IMainProcessInfo): SystemInfo {
const MB = 1024 * 1024;
const GB = 1024 * MB;

const systemInfo: SystemInfo = {
'Memory (System)': `${(os.totalmem() / GB).toFixed(2)}GB (${(os.freemem() / GB).toFixed(2)}GB free)`,
VM: `${Math.round((virtualMachineHint.value() * 100))}%`,
'Screen Reader': `${app.isAccessibilitySupportEnabled() ? 'yes' : 'no'}`,
'Process Argv': `${info.mainArguments.join(' ')}`
};

const cpus = os.cpus();
if (cpus && cpus.length > 0) {
systemInfo.CPUs = `${cpus[0].model} (${cpus.length} x ${cpus[0].speed})`;
}

if (!isWindows) {
systemInfo['Load (avg)'] = `${os.loadavg().map(l => Math.round(l)).join(', ')}`;
}


return systemInfo;
}

export function printDiagnostics(info: IMainProcessInfo): Promise<any> {
return listProcesses(info.mainPID).then(rootProcess => {

Expand Down Expand Up @@ -186,30 +208,6 @@ function formatLaunchConfigs(configs: WorkspaceStatItem[]): string {
return output.join('\n');
}

function getSystemInfo(info: IMainProcessInfo): SystemInfo {
const MB = 1024 * 1024;
const GB = 1024 * MB;

const systemInfo: SystemInfo = {
'Memory (System)': `${(os.totalmem() / GB).toFixed(2)}GB (${(os.freemem() / GB).toFixed(2)}GB free)`,
VM: `${Math.round((virtualMachineHint.value() * 100))}%`,
'Screen Reader': `${app.isAccessibilitySupportEnabled() ? 'yes' : 'no'}`,
'Process Argv': `${info.mainArguments.join(' ')}`
};

const cpus = os.cpus();
if (cpus && cpus.length > 0) {
systemInfo.CPUs = `${cpus[0].model} (${cpus.length} x ${cpus[0].speed})`;
}

if (!isWindows) {
systemInfo['Load (avg)'] = `${os.loadavg().map(l => Math.round(l)).join(', ')}`;
}


return systemInfo;
}

function getProcessList(info: IMainProcessInfo, rootProcess: ProcessItem): ProcessInfo[] {
const mapPidToWindowTitle = new Map<number, string>();
info.windows.forEach(window => mapPidToWindowTitle.set(window.pid, window.title));
Expand Down
26 changes: 20 additions & 6 deletions src/vs/platform/issue/electron-main/issueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { parseArgs } from 'vs/platform/environment/node/argv';
import { IIssueService, IssueReporterData } from 'vs/platform/issue/common/issue';
import { BrowserWindow, ipcMain, screen } from 'electron';
import { ILaunchService } from 'vs/code/electron-main/launch';
import { buildDiagnostics, DiagnosticInfo } from 'vs/code/electron-main/diagnostics';
import { getPerformanceInfo, PerformanceInfo, getSystemInfo, SystemInfo } from 'vs/code/electron-main/diagnostics';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { isMacintosh } from 'vs/base/common/platform';

Expand All @@ -30,9 +30,15 @@ export class IssueService implements IIssueService {
) { }

openReporter(data: IssueReporterData): TPromise<void> {
ipcMain.on('issueInfoRequest', event => {
this.getStatusInfo().then(msg => {
event.sender.send('issueInfoResponse', msg);
ipcMain.on('issueSystemInfoRequest', event => {
this.getSystemInformation().then(msg => {
event.sender.send('issueSystemInfoResponse', msg);
});
});

ipcMain.on('issuePerformanceInfoRequest', event => {
this.getPerformanceInfo().then(msg => {
event.sender.send('issuePerformanceInfoResponse', msg);
});
});

Expand Down Expand Up @@ -100,10 +106,18 @@ export class IssueService implements IIssueService {
return state;
}

private getStatusInfo(): TPromise<DiagnosticInfo> {
private getSystemInformation(): TPromise<SystemInfo> {
return new Promise((resolve, reject) => {
this.launchService.getMainProcessInfo().then(info => {
resolve(getSystemInfo(info));
});
});
}

private getPerformanceInfo(): TPromise<PerformanceInfo> {
return new Promise((resolve, reject) => {
this.launchService.getMainProcessInfo().then(info => {
buildDiagnostics(info)
getPerformanceInfo(info)
.then(diagnosticInfo => {
resolve(diagnosticInfo);
})
Expand Down

0 comments on commit 004d668

Please sign in to comment.