Skip to content

Commit

Permalink
Track the case of language server OutOfMemory (#3273)
Browse files Browse the repository at this point in the history
  • Loading branch information
testforstephen authored Sep 6, 2023
1 parent 8dac160 commit 4352492
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ async function showOOMMessage(): Promise<void> {
}
}

function getMaxMemFromConfiguration(includeUnit?: boolean): string | undefined {
const jvmArgs: string = getJavaConfiguration().get('jdt.ls.vmargs');
const results = includeUnit ? MAX_HEAP_SIZE_EXTRACTOR_WITH_UNIT.exec(jvmArgs)
: MAX_HEAP_SIZE_EXTRACTOR.exec(jvmArgs);
return results && results[0] ? results[1] : undefined;
}

const HEAP_DUMP_FOLDER_EXTRACTOR = new RegExp(`${HEAP_DUMP_LOCATION}(?:'([^']+)'|"([^"]+)"|([^\\s]+))`);
const MAX_HEAP_SIZE_EXTRACTOR = new RegExp(`-Xmx([0-9]+)[kKmMgG]`);
const MAX_HEAP_SIZE_EXTRACTOR_WITH_UNIT = new RegExp(`-Xmx([0-9]+[kKmMgG])`);

/**
* Returns the heap dump folder defined in the user's preferences, or undefined if the user does not set the heap dump folder
Expand Down Expand Up @@ -980,6 +988,12 @@ function registerOutOfMemoryDetection(storagePath: string) {
if (heapDumpFolder === storagePath) {
fse.remove(path);
}
apiManager.fireTraceEvent({
name: "java.process.outofmemory",
properties: {
maxMem: getMaxMemFromConfiguration(true),
}
});
showOOMMessage();
serverStatusBarProvider.setError();
activationProgressNotification.hide();
Expand Down

0 comments on commit 4352492

Please sign in to comment.