@@ -9,54 +9,74 @@ export class ClientLogWatcher {
99 private context : vscode . ExtensionContext ;
1010 private javaExtensionRoot : vscode . Uri | undefined ;
1111 private logProcessedTimestamp : number = Date . now ( ) ;
12+ private interestedLspRequests : string [ ] = [ "textDocument\\/completion" ] ;
13+ private lspTracePatterns : Map < string , RegExp > = new Map ( ) ;
1214
1315 constructor ( daemon : LSDaemon ) {
1416 this . context = daemon . context ;
1517 if ( this . context . storageUri ) {
1618 this . javaExtensionRoot = vscode . Uri . joinPath ( this . context . storageUri , ".." , "redhat.java" ) ;
1719 }
20+ if ( this . interestedLspRequests . length > 0 ) {
21+ for ( const request of this . interestedLspRequests ) {
22+ this . lspTracePatterns . set ( request , new RegExp ( `\\[Trace.*\\] Received response \'${ request } .*\' in (\\d+)ms` ) ) ;
23+ }
24+ }
1825 }
1926
20- public async collectStartupInfo ( ) {
27+ public async collectInfoFromLog ( ) {
2128 const logs = await this . getLogs ( ) ;
2229 if ( logs ) {
23- const info : any = { } ;
30+ for ( const log of logs ) {
31+ if ( log . message ?. startsWith ( "Use the JDK from" ) && Date . parse ( log . timestamp ) > this . logProcessedTimestamp ) {
32+ const info : any = { } ;
33+ info . defaultProjectJdk = log ?. message . replace ( "Use the JDK from '" , "" ) . replace ( "' as the initial default project JDK." , "" ) ;
2434
25- const jdkLog = logs . find ( log => log . message ?. startsWith ( "Use the JDK from" ) ) ;
26- info . defaultProjectJdk = jdkLog ?. message . replace ( "Use the JDK from '" , "" ) . replace ( "' as the initial default project JDK." , "" ) ;
35+ const startupLog = logs . find ( log => log . message ?. startsWith ( "Starting Java server with:" ) && log . message . endsWith ( "jdt_ws" ) /* limit to standard server */ ) ;
36+ if ( startupLog ) {
37+ info . xmx = startupLog . message . match ( / - X m x [ 0 - 9 k m g K M G ] + / g) ?. [ 0 ] ;
38+ info . xms = startupLog . message . match ( / - X m s [ 0 - 9 k m g K M G ] + / g) ?. [ 0 ] ;
39+ info . lombok = startupLog . message . includes ( "lombok.jar" ) ? "true" : undefined ;
40+ info . workspaceType = startupLog . message . match ( / - X X : H e a p D u m p P a t h = .* ( v s c o d e s w s ) / ) ? "vscodesws" : "folder" ;
41+ }
2742
28- const startupLog = logs . find ( log => log . message ?. startsWith ( "Starting Java server with:" ) && log . message . endsWith ( "jdt_ws" ) /* limit to standard server */ ) ;
29- if ( startupLog ) {
30- info . xmx = startupLog . message . match ( / - X m x [ 0 - 9 k m g K M G ] + / g) ?. [ 0 ] ;
31- info . xms = startupLog . message . match ( / - X m s [ 0 - 9 k m g K M G ] + / g) ?. [ 0 ] ;
32- info . lombok = startupLog . message . includes ( "lombok.jar" ) ? "true" : undefined ;
33- info . workspaceType = startupLog . message . match ( / - X X : H e a p D u m p P a t h = .* ( v s c o d e s w s ) / ) ? "vscodesws" : "folder" ;
34- }
43+ const errorLog = logs . find ( log => log . level === "error" ) ;
44+ info . error = errorLog ? "true" : undefined ;
3545
36- const errorLog = logs . find ( log => log . level === "error" ) ;
37- info . error = errorLog ? "true" : undefined ;
46+ const missingJar = "Error opening zip file or JAR manifest missing" ; // lombok especially
47+ if ( logs . find ( log => log . message ?. startsWith ( missingJar ) ) ) {
48+ info . error = missingJar ;
49+ }
3850
39- const missingJar = "Error opening zip file or JAR manifest missing" ; // lombok especially
40- if ( logs . find ( log => log . message ?. startsWith ( missingJar ) ) ) {
41- info . error = missingJar ;
42- }
51+ const crashLog = logs . find ( log => log . message ?. startsWith ( "The Language Support for Java server crashed and will restart." ) ) ;
52+ info . crash = crashLog ? "true" : undefined ;
4353
44- const crashLog = logs . find ( log => log . message ?. startsWith ( "The Language Support for Java server crashed and will restart." ) ) ;
45- info . crash = crashLog ? "true" : undefined ;
46-
47- sendInfo ( "" , {
48- name : "client-log-startup-metadata" ,
49- ...info
50- } ) ;
54+ sendInfo ( "" , {
55+ name : "client-log-startup-metadata" ,
56+ ...info
57+ } ) ;
58+ } else {
59+ for ( const key of this . lspTracePatterns . keys ( ) ) {
60+ const regexp : RegExp = this . lspTracePatterns . get ( key ) ! ;
61+ const match = log . message ?. match ( regexp ) ;
62+ if ( match ?. length === 2 ) {
63+ sendInfo ( "" , {
64+ name : "perf-trace" ,
65+ kind : key . replace ( "\\" , "" ) ,
66+ time : match [ 1 ] ,
67+ } ) ;
68+ }
69+ }
70+ }
71+ }
5172 }
5273 }
5374
5475 public async getLogs ( ) {
5576 const rawBytes = await this . readLatestLogFile ( ) ;
5677 if ( rawBytes ) {
5778 const content = rawBytes . toString ( ) ;
58- const entries = parse ( content ) ;
59- return entries . filter ( elem => Date . parse ( elem [ "timestamp" ] ) > this . logProcessedTimestamp ) ;
79+ return parse ( content ) ;
6080 } else {
6181 return undefined ;
6282 }
0 commit comments