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:
Benjamin Pasero 2024-05-24 09:29:19 +02:00 committed by GitHub
parent 36d917472f
commit c1ebab91fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 9 additions and 8 deletions

View file

@ -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.

View file

@ -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 }; },

View file

@ -142,6 +142,7 @@ export interface ICommonNativeHostService {
hasWSLFeatureInstalled(): Promise<boolean>;
// Process
getProcessId(): Promise<number | undefined>;
killProcess(pid: number, code: string): Promise<void>;
// Clipboard

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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; }