From 5dba5c71cd288789c67f11e0ac0afd4dc4c4d3d9 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Mon, 29 May 2023 11:15:15 +0800 Subject: [PATCH] Track e2e startup time Signed-off-by: Sheng Chen --- src/daemon/processWatcher.ts | 21 --------------------- src/extension.ts | 32 +++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/daemon/processWatcher.ts b/src/daemon/processWatcher.ts index 9e8c1b7f..ff1f580f 100644 --- a/src/daemon/processWatcher.ts +++ b/src/daemon/processWatcher.ts @@ -9,7 +9,6 @@ import { promisify } from "util"; import * as vscode from "vscode"; import { sendInfo } from "vscode-extension-telemetry-wrapper"; import { LSDaemon } from "./daemon"; -import { activatingTimestamp } from "../extension"; const execFile = promisify(cp.execFile); interface IJdtlsMetadata { @@ -60,9 +59,6 @@ export class ProcessWatcher { public monitor() { const id = setInterval(() => { this.upTime().then(seconds => { - if (!this.lastHeartbeat && seconds) { - this.sendClientInitializeTime(seconds); - } this.lastHeartbeat = seconds; }).catch(_e => { clearInterval(id); @@ -103,23 +99,6 @@ export class ProcessWatcher { }); this.daemon.logWatcher.sendErrorAndStackOnCrash(); } - - /** - * Send the time the client takes to initialize. This is the time between the - * activation and the JVM process is launched. - */ - private sendClientInitializeTime(seconds: string) { - const upTime = seconds.match(/\d+\.\d+/)?.toString(); - if (upTime) { - let interval = Math.round( - performance.now() - activatingTimestamp - parseFloat(upTime) * 1000 - ); - sendInfo("", { - name: "client-initialize-time", - message: interval.toString() - }); - } - } } diff --git a/src/extension.ts b/src/extension.ts index ddcbb1e0..834d11d1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -23,13 +23,15 @@ import { initialize as initUtils } from "./utils"; import { KEY_SHOW_WHEN_USING_JAVA } from "./utils/globalState"; import { scheduleAction } from "./utils/scheduler"; import { showWelcomeWebview, WelcomeViewSerializer } from "./welcome"; +import { promisify } from "util"; let cleanJavaWorkspaceIndicator: string; -let activatedTimestamp: number; export let activatingTimestamp: number; export async function activate(context: vscode.ExtensionContext) { activatingTimestamp = performance.now(); + // monitor the startup time at very beginning in case we miss the activation of java extension. + recordStartupTime(); syncState(context); initializeTelemetry(context); // 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 initRecommendations(context); initDaemon(context); - activatedTimestamp = performance.now(); if(context.storageUri) { const javaWorkspaceStoragePath = path.join(context.storageUri.fsPath, "..", "redhat.java"); cleanJavaWorkspaceIndicator = path.join(javaWorkspaceStoragePath, "jdt_ws", ".cleanWorkspace"); @@ -105,7 +106,7 @@ export async function deactivate() { const now = performance.now(); const data = { name: "sessionStatus", - time: Math.round(now - activatedTimestamp) + time: Math.round(now - activatingTimestamp) } if (cleanJavaWorkspaceIndicator && fs.existsSync(cleanJavaWorkspaceIndicator)) { data.name = "cleanJavaLSWorkspace"; @@ -113,3 +114,28 @@ export async function deactivate() { sendInfo("", data); await disposeTelemetryWrapper(); } + +async function recordStartupTime() { + const javaExt = vscode.extensions.getExtension("redhat.java"); + // only count the e2e time when java extension is not activated at the moment. + // if it's already activated, we are not clear if it is activated with pack at + // the same moment. + if (javaExt && !javaExt.isActive) { + const delay = promisify(setTimeout); + const timeout = 30 * 60 * 1000; // wait 30 min at most + let count = 0; + while(!javaExt.isActive && count < timeout) { + await delay(1000); + count += 1000; + } + if (javaExt.isActive && javaExt.exports?.serverReady) { + javaExt.exports.serverReady().then(() => { + const message = Math.round(performance.now() - activatingTimestamp).toString(); + sendInfo("", { + name: "e2e-startup-time", + message, + }); + }); + } + } +}