Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track e2e startup time #1202

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Copy link
Contributor

@testforstephen testforstephen May 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition branch if (javaExt && !javaExt.isActive) should end at L130. Otherwise, the subsequent code won't be executed if the Java extension is already activated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was intended to do this, while not sure if this makes enough sense. What do you think about the follow case:

  1. In an empty workspace, user triggers some redhat.java specific command. such as
    image to open a webview.
  2. Then, redhat.java will be activated, while pack is not.

So the purpose here is to make sure that two extensions are almost activated at the same time.

if (javaExt.isActive && javaExt.exports?.serverReady) {
javaExt.exports.serverReady().then(() => {
const message = Math.round(performance.now() - activatingTimestamp).toString();
sendInfo("", {
name: "e2e-startup-time",
message,
});
});
}
}
}