Skip to content

Commit

Permalink
Track e2e startup time
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <[email protected]>
  • Loading branch information
jdneo committed May 29, 2023
1 parent 831aacd commit 0b1e0b4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
21 changes: 0 additions & 21 deletions src/daemon/processWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
});
}
}
}


Expand Down
32 changes: 29 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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");
Expand Down Expand Up @@ -105,11 +106,36 @@ 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";
}
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 = 1 * 60 * 1000; // wait 1 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,
});
});
}
}
}

0 comments on commit 0b1e0b4

Please sign in to comment.