33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { IMainProcessInfo } from 'vs/platform/launch/electron-main/launchService' ;
6+ import { IMainProcessInfo , ILaunchService } from 'vs/platform/launch/electron-main/launchService' ;
77import { ProcessItem , listProcesses } from 'vs/base/node/ps' ;
88import product from 'vs/platform/product/node/product' ;
99import pkg from 'vs/platform/product/node/package' ;
@@ -23,10 +23,9 @@ export const IDiagnosticsService = createDecorator<IDiagnosticsService>(ID);
2323export interface IDiagnosticsService {
2424 _serviceBrand : any ;
2525
26- formatEnvironment ( info : IMainProcessInfo ) : string ;
27- getPerformanceInfo ( info : IMainProcessInfo ) : Promise < PerformanceInfo > ;
28- getSystemInfo ( info : IMainProcessInfo ) : SystemInfo ;
29- getDiagnostics ( info : IMainProcessInfo ) : Promise < string > ;
26+ getPerformanceInfo ( launchService : ILaunchService ) : Promise < PerformanceInfo > ;
27+ getSystemInfo ( launchService : ILaunchService ) : Promise < SystemInfo > ;
28+ getDiagnostics ( launchService : ILaunchService ) : Promise < string > ;
3029}
3130
3231export interface VersionInfo {
@@ -83,55 +82,19 @@ export class DiagnosticsService implements IDiagnosticsService {
8382 return output . join ( '\n' ) ;
8483 }
8584
86- getPerformanceInfo ( info : IMainProcessInfo ) : Promise < PerformanceInfo > {
87- return listProcesses ( info . mainPID ) . then ( rootProcess => {
88- const workspaceInfoMessages : string [ ] = [ ] ;
89-
90- // Workspace Stats
91- const workspaceStatPromises : Promise < void > [ ] = [ ] ;
92- if ( info . windows . some ( window => window . folderURIs && window . folderURIs . length > 0 ) ) {
93- info . windows . forEach ( window => {
94- if ( window . folderURIs . length === 0 ) {
95- return ;
96- }
97-
98- workspaceInfoMessages . push ( `| Window (${ window . title } )` ) ;
99-
100- window . folderURIs . forEach ( uriComponents => {
101- const folderUri = URI . revive ( uriComponents ) ;
102- if ( folderUri . scheme === 'file' ) {
103- const folder = folderUri . fsPath ;
104- workspaceStatPromises . push ( collectWorkspaceStats ( folder , [ 'node_modules' , '.git' ] ) . then ( async stats => {
105-
106- let countMessage = `${ stats . fileCount } files` ;
107- if ( stats . maxFilesReached ) {
108- countMessage = `more than ${ countMessage } ` ;
109- }
110- workspaceInfoMessages . push ( `| Folder (${ basename ( folder ) } ): ${ countMessage } ` ) ;
111- workspaceInfoMessages . push ( this . formatWorkspaceStats ( stats ) ) ;
112- } ) ) ;
113- } else {
114- workspaceInfoMessages . push ( `| Folder (${ folderUri . toString ( ) } ): RPerformance stats not available.` ) ;
115- }
116- } ) ;
117- } ) ;
118- }
119-
120- return Promise . all ( workspaceStatPromises ) . then ( ( ) => {
121- return {
122- processInfo : this . formatProcessList ( info , rootProcess ) ,
123- workspaceInfo : workspaceInfoMessages . join ( '\n' )
124- } ;
125- } ) . catch ( error => {
126- return {
127- processInfo : this . formatProcessList ( info , rootProcess ) ,
128- workspaceInfo : `Unable to calculate workspace stats: ${ error } `
129- } ;
130- } ) ;
85+ async getPerformanceInfo ( launchService : ILaunchService ) : Promise < PerformanceInfo > {
86+ const info = await launchService . getMainProcessInfo ( ) ;
87+ return Promise . all < ProcessItem , string > ( [ listProcesses ( info . mainPID ) , this . formatWorkspaceMetadata ( info ) ] ) . then ( result => {
88+ const [ rootProcess , workspaceInfo ] = result ;
89+ return {
90+ processInfo : this . formatProcessList ( info , rootProcess ) ,
91+ workspaceInfo
92+ } ;
13193 } ) ;
13294 }
13395
134- getSystemInfo ( info : IMainProcessInfo ) : SystemInfo {
96+ async getSystemInfo ( launchService : ILaunchService ) : Promise < SystemInfo > {
97+ const info = await launchService . getMainProcessInfo ( ) ;
13598 const MB = 1024 * 1024 ;
13699 const GB = 1024 * MB ;
137100
@@ -152,13 +115,13 @@ export class DiagnosticsService implements IDiagnosticsService {
152115 systemInfo [ 'Load (avg)' ] = `${ os . loadavg ( ) . map ( l => Math . round ( l ) ) . join ( ', ' ) } ` ;
153116 }
154117
155-
156- return systemInfo ;
118+ return Promise . resolve ( systemInfo ) ;
157119 }
158120
159- getDiagnostics ( info : IMainProcessInfo ) : Promise < string > {
121+ async getDiagnostics ( launchService : ILaunchService ) : Promise < string > {
160122 const output : string [ ] = [ ] ;
161- return listProcesses ( info . mainPID ) . then ( rootProcess => {
123+ const info = await launchService . getMainProcessInfo ( ) ;
124+ return listProcesses ( info . mainPID ) . then ( async rootProcess => {
162125
163126 // Environment Info
164127 output . push ( '' ) ;
@@ -169,45 +132,16 @@ export class DiagnosticsService implements IDiagnosticsService {
169132 output . push ( this . formatProcessList ( info , rootProcess ) ) ;
170133
171134 // Workspace Stats
172- const workspaceStatPromises : Promise < void > [ ] = [ ] ;
173135 if ( info . windows . some ( window => window . folderURIs && window . folderURIs . length > 0 ) ) {
174136 output . push ( '' ) ;
175137 output . push ( 'Workspace Stats: ' ) ;
176- info . windows . forEach ( window => {
177- if ( window . folderURIs . length === 0 ) {
178- return ;
179- }
180-
181- output . push ( `| Window (${ window . title } )` ) ;
182-
183- window . folderURIs . forEach ( uriComponents => {
184- const folderUri = URI . revive ( uriComponents ) ;
185- if ( folderUri . scheme === 'file' ) {
186- const folder = folderUri . fsPath ;
187- workspaceStatPromises . push ( collectWorkspaceStats ( folder , [ 'node_modules' , '.git' ] ) . then ( async stats => {
188- let countMessage = `${ stats . fileCount } files` ;
189- if ( stats . maxFilesReached ) {
190- countMessage = `more than ${ countMessage } ` ;
191- }
192- output . push ( `| Folder (${ basename ( folder ) } ): ${ countMessage } ` ) ;
193- output . push ( this . formatWorkspaceStats ( stats ) ) ;
194-
195- } ) . catch ( error => {
196- output . push ( `| Error: Unable to collect workspace stats for folder ${ folder } (${ error . toString ( ) } )` ) ;
197- } ) ) ;
198- } else {
199- output . push ( `| Folder (${ folderUri . toString ( ) } ): Workspace stats not available.` ) ;
200- }
201- } ) ;
202- } ) ;
138+ output . push ( await this . formatWorkspaceMetadata ( info ) ) ;
203139 }
204140
205- return Promise . all ( workspaceStatPromises ) . then ( ( ) => {
206- output . push ( '' ) ;
207- output . push ( '' ) ;
141+ output . push ( '' ) ;
142+ output . push ( '' ) ;
208143
209- return output . join ( '\n' ) ;
210- } ) ;
144+ return output . join ( '\n' ) ;
211145 } ) ;
212146 }
213147
@@ -268,6 +202,43 @@ export class DiagnosticsService implements IDiagnosticsService {
268202 return Object . keys ( gpuFeatures ) . map ( feature => `${ feature } : ${ repeat ( ' ' , longestFeatureName - feature . length ) } ${ gpuFeatures [ feature ] } ` ) . join ( '\n ' ) ;
269203 }
270204
205+ private formatWorkspaceMetadata ( info : IMainProcessInfo ) : Promise < string > {
206+ const output : string [ ] = [ ] ;
207+ const workspaceStatPromises : Promise < void > [ ] = [ ] ;
208+
209+ info . windows . forEach ( window => {
210+ if ( window . folderURIs . length === 0 ) {
211+ return ;
212+ }
213+
214+ output . push ( `| Window (${ window . title } )` ) ;
215+
216+ window . folderURIs . forEach ( uriComponents => {
217+ const folderUri = URI . revive ( uriComponents ) ;
218+ if ( folderUri . scheme === 'file' ) {
219+ const folder = folderUri . fsPath ;
220+ workspaceStatPromises . push ( collectWorkspaceStats ( folder , [ 'node_modules' , '.git' ] ) . then ( stats => {
221+ let countMessage = `${ stats . fileCount } files` ;
222+ if ( stats . maxFilesReached ) {
223+ countMessage = `more than ${ countMessage } ` ;
224+ }
225+ output . push ( `| Folder (${ basename ( folder ) } ): ${ countMessage } ` ) ;
226+ output . push ( this . formatWorkspaceStats ( stats ) ) ;
227+
228+ } ) . catch ( error => {
229+ output . push ( `| Error: Unable to collect workspace stats for folder ${ folder } (${ error . toString ( ) } )` ) ;
230+ } ) ) ;
231+ } else {
232+ output . push ( `| Folder (${ folderUri . toString ( ) } ): Workspace stats not available.` ) ;
233+ }
234+ } ) ;
235+ } ) ;
236+
237+ return Promise . all ( workspaceStatPromises )
238+ . then ( _ => output . join ( '\n' ) )
239+ . catch ( e => `Unable to collect workspace stats: ${ e } ` ) ;
240+ }
241+
271242 private formatProcessList ( info : IMainProcessInfo , rootProcess : ProcessItem ) : string {
272243 const mapPidToWindowTitle = new Map < number , string > ( ) ;
273244 info . windows . forEach ( window => mapPidToWindowTitle . set ( window . pid , window . title ) ) ;
0 commit comments