@@ -23,13 +23,15 @@ import { initialize as initUtils } from "./utils";
2323import { KEY_SHOW_WHEN_USING_JAVA } from "./utils/globalState" ;
2424import { scheduleAction } from "./utils/scheduler" ;
2525import { showWelcomeWebview , WelcomeViewSerializer } from "./welcome" ;
26+ import { promisify } from "util" ;
2627
2728let cleanJavaWorkspaceIndicator : string ;
28- let activatedTimestamp : number ;
2929export let activatingTimestamp : number ;
3030
3131export async function activate ( context : vscode . ExtensionContext ) {
3232 activatingTimestamp = performance . now ( ) ;
33+ // monitor the startup time at very beginning in case we miss the activation of java extension.
34+ recordStartupTime ( ) ;
3335 syncState ( context ) ;
3436 initializeTelemetry ( context ) ;
3537 // initialize exp service ahead of activation operation to make sure exp context properties are set.
@@ -45,7 +47,6 @@ async function initializeExtension(_operationId: string, context: vscode.Extensi
4547 initRecommendations ( context ) ;
4648 initDaemon ( context ) ;
4749
48- activatedTimestamp = performance . now ( ) ;
4950 if ( context . storageUri ) {
5051 const javaWorkspaceStoragePath = path . join ( context . storageUri . fsPath , ".." , "redhat.java" ) ;
5152 cleanJavaWorkspaceIndicator = path . join ( javaWorkspaceStoragePath , "jdt_ws" , ".cleanWorkspace" ) ;
@@ -105,11 +106,36 @@ export async function deactivate() {
105106 const now = performance . now ( ) ;
106107 const data = {
107108 name : "sessionStatus" ,
108- time : Math . round ( now - activatedTimestamp )
109+ time : Math . round ( now - activatingTimestamp )
109110 }
110111 if ( cleanJavaWorkspaceIndicator && fs . existsSync ( cleanJavaWorkspaceIndicator ) ) {
111112 data . name = "cleanJavaLSWorkspace" ;
112113 }
113114 sendInfo ( "" , data ) ;
114115 await disposeTelemetryWrapper ( ) ;
115116}
117+
118+ async function recordStartupTime ( ) {
119+ const javaExt = vscode . extensions . getExtension ( "redhat.java" ) ;
120+ // only count the e2e time when java extension is not activated at the moment.
121+ // if it's already activated, we are not clear if it is activated with pack at
122+ // the same moment.
123+ if ( javaExt && ! javaExt . isActive ) {
124+ const delay = promisify ( setTimeout ) ;
125+ const timeout = 30 * 60 * 1000 ; // wait 30 min at most
126+ let count = 0 ;
127+ while ( ! javaExt . isActive && count < timeout ) {
128+ await delay ( 1000 ) ;
129+ count += 1000 ;
130+ }
131+ if ( javaExt . isActive && javaExt . exports ?. serverReady ) {
132+ javaExt . exports . serverReady ( ) . then ( ( ) => {
133+ const message = Math . round ( performance . now ( ) - activatingTimestamp ) . toString ( ) ;
134+ sendInfo ( "" , {
135+ name : "e2e-startup-time" ,
136+ message,
137+ } ) ;
138+ } ) ;
139+ }
140+ }
141+ }
0 commit comments