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

Add API to track lsp perf on language client level #2996

Merged
merged 4 commits into from
Mar 15, 2023

Conversation

testforstephen
Copy link
Collaborator

This PR provides an API to easily trace the lsp request performance.

  • Track initialize request on languageClient.start()
  • Track common requests on sendRequest(...)

Here is a sample code on how to use this API:

 const javaExt = vscode.extensions.getExtension("redhat.java");
 if (javaExt.exports.onDidRequestEnd) {
    javaExt.exports.onDidRequestEnd((traceEvent: any) => {
      console.log(`${traceEvent.type} - ${traceEvent.duration} ms - ${traceEvent.error}`);
    });
  }

@testforstephen
Copy link
Collaborator Author

testforstephen commented Mar 13, 2023

// @akaroml @Eskibear @CsCherrYY pls help a review on the API design as well.

src/TracingLanguageClient.ts Show resolved Hide resolved
src/TracingLanguageClient.ts Outdated Show resolved Hide resolved
src/TracingLanguageClient.ts Show resolved Hide resolved
@testforstephen testforstephen added this to the Mid March 2023 milestone Mar 14, 2023
sendRequest<R>(method: string, token?: CancellationToken): Promise<R>;
sendRequest<R>(method: string, param: any, token?: CancellationToken): Promise<R>;
sendRequest(method: any, ...args) {
const startAt: number = Date.now();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be better to use performance.now(). See: https://developer.mozilla.org/en-US/docs/Web/API/Performance/now

Also, Date.now() may have been impacted by system and user clock adjustments, clock skew, etc. as it is relative to the Unix epoch (1970-01-01T00:00:00Z) and dependent on the system clock. The performance.now() method on the other hand is relative to the timeOrigin property which is a monotonic clock: its current time never decreases and isn't subject to adjustments.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks. Good to know the new API.

The data will like textDocument/completion - 1359.5962999993935 ms with performance.now api. Then the downstream tracer can decide whether to convert the floating point number to integer.

Copy link
Collaborator

@jdneo jdneo left a comment

Choose a reason for hiding this comment

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

LGTM

@testforstephen testforstephen merged commit de77dc8 into redhat-developer:master Mar 15, 2023
@testforstephen testforstephen deleted the jinbo_trace branch March 15, 2023 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants