Skip to content

Commit 0b1e0b4

Browse files
committed
Track e2e startup time
Signed-off-by: Sheng Chen <[email protected]>
1 parent 831aacd commit 0b1e0b4

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

src/daemon/processWatcher.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { promisify } from "util";
99
import * as vscode from "vscode";
1010
import { sendInfo } from "vscode-extension-telemetry-wrapper";
1111
import { LSDaemon } from "./daemon";
12-
import { activatingTimestamp } from "../extension";
1312
const execFile = promisify(cp.execFile);
1413

1514
interface IJdtlsMetadata {
@@ -60,9 +59,6 @@ export class ProcessWatcher {
6059
public monitor() {
6160
const id = setInterval(() => {
6261
this.upTime().then(seconds => {
63-
if (!this.lastHeartbeat && seconds) {
64-
this.sendClientInitializeTime(seconds);
65-
}
6662
this.lastHeartbeat = seconds;
6763
}).catch(_e => {
6864
clearInterval(id);
@@ -103,23 +99,6 @@ export class ProcessWatcher {
10399
});
104100
this.daemon.logWatcher.sendErrorAndStackOnCrash();
105101
}
106-
107-
/**
108-
* Send the time the client takes to initialize. This is the time between the
109-
* activation and the JVM process is launched.
110-
*/
111-
private sendClientInitializeTime(seconds: string) {
112-
const upTime = seconds.match(/\d+\.\d+/)?.toString();
113-
if (upTime) {
114-
let interval = Math.round(
115-
performance.now() - activatingTimestamp - parseFloat(upTime) * 1000
116-
);
117-
sendInfo("", {
118-
name: "client-initialize-time",
119-
message: interval.toString()
120-
});
121-
}
122-
}
123102
}
124103

125104

src/extension.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ import { initialize as initUtils } from "./utils";
2323
import { KEY_SHOW_WHEN_USING_JAVA } from "./utils/globalState";
2424
import { scheduleAction } from "./utils/scheduler";
2525
import { showWelcomeWebview, WelcomeViewSerializer } from "./welcome";
26+
import { promisify } from "util";
2627

2728
let cleanJavaWorkspaceIndicator: string;
28-
let activatedTimestamp: number;
2929
export let activatingTimestamp: number;
3030

3131
export 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 = 1 * 60 * 1000; // wait 1 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

Comments
 (0)