mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
refactor: replace direct process.pid usage with getProcessId method (#213352)
* refactor: replace direct process.pid usage with getProcessId method * remove console.log
This commit is contained in:
parent
36d917472f
commit
c1ebab91fb
|
@ -12,11 +12,6 @@ import { IpcRenderer, ProcessMemoryInfo, WebFrame } from 'vs/base/parts/sandbox/
|
|||
*/
|
||||
export interface ISandboxNodeProcess extends INodeProcess {
|
||||
|
||||
/**
|
||||
* The process.pid property returns the process ID of the process.
|
||||
*/
|
||||
readonly pid: number;
|
||||
|
||||
/**
|
||||
* The process.platform property returns a string identifying the operating system platform
|
||||
* on which the Node.js process is running.
|
||||
|
|
|
@ -248,7 +248,6 @@
|
|||
* @type {ISandboxNodeProcess}
|
||||
*/
|
||||
process: {
|
||||
get pid() { return process.pid; },
|
||||
get platform() { return process.platform; },
|
||||
get arch() { return process.arch; },
|
||||
get env() { return { ...process.env }; },
|
||||
|
|
|
@ -142,6 +142,7 @@ export interface ICommonNativeHostService {
|
|||
hasWSLFeatureInstalled(): Promise<boolean>;
|
||||
|
||||
// Process
|
||||
getProcessId(): Promise<number | undefined>;
|
||||
killProcess(pid: number, code: string): Promise<void>;
|
||||
|
||||
// Clipboard
|
||||
|
|
|
@ -615,6 +615,11 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
|
|||
|
||||
//#region Process
|
||||
|
||||
async getProcessId(windowId: number | undefined): Promise<number | undefined> {
|
||||
const window = this.windowById(undefined, windowId);
|
||||
return window?.win?.webContents.getOSProcessId();
|
||||
}
|
||||
|
||||
async killProcess(windowId: number | undefined, pid: number, code: string): Promise<void> {
|
||||
process.kill(pid, code);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import { VSBuffer } from 'vs/base/common/buffer';
|
|||
import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/workspaceTrust';
|
||||
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite';
|
||||
import { StartupTimings } from 'vs/workbench/contrib/performance/browser/startupTimings';
|
||||
import { process } from 'vs/base/parts/sandbox/electron-sandbox/globals';
|
||||
import { coalesce } from 'vs/base/common/arrays';
|
||||
|
||||
interface ITracingData {
|
||||
|
@ -160,6 +159,7 @@ export class NativeStartupTimings extends StartupTimings implements IWorkbenchCo
|
|||
return undefined; // unexpected arguments for startup heap statistics
|
||||
}
|
||||
|
||||
const windowProcessId = await this._nativeHostService.getProcessId();
|
||||
const used = (performance as unknown as { memory?: { usedJSHeapSize?: number } }).memory?.usedJSHeapSize ?? 0; // https://developer.mozilla.org/en-US/docs/Web/API/Performance/memory
|
||||
|
||||
let minorGCs = 0;
|
||||
|
@ -170,7 +170,7 @@ export class NativeStartupTimings extends StartupTimings implements IWorkbenchCo
|
|||
try {
|
||||
const traceContents: { traceEvents: ITracingData[] } = JSON.parse((await this._fileService.readFile(URI.file(this._environmentService.args['trace-startup-file']))).value.toString());
|
||||
for (const event of traceContents.traceEvents) {
|
||||
if (event.pid !== process.pid) {
|
||||
if (event.pid !== windowProcessId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -121,6 +121,7 @@ export class TestNativeHostService implements INativeHostService {
|
|||
async getOSVirtualMachineHint(): Promise<number> { return 0; }
|
||||
async getOSColorScheme(): Promise<IColorScheme> { return { dark: true, highContrast: false }; }
|
||||
async hasWSLFeatureInstalled(): Promise<boolean> { return false; }
|
||||
async getProcessId(): Promise<number> { throw new Error('Method not implemented.'); }
|
||||
async killProcess(): Promise<void> { }
|
||||
async setDocumentEdited(edited: boolean): Promise<void> { }
|
||||
async openExternal(url: string): Promise<boolean> { return false; }
|
||||
|
|
Loading…
Reference in a new issue