Skip to content
New issue

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

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

Already on GitHub? # to your account

Send the jvm statistics #1198

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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ typings/
# dotenv environment variables file
.env

# java compiled output
target/
server/*.jar

out/

.DS_Store
Expand Down
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
],
"preLaunchTask": "npm: watch"
},
{
"type": "java",
"name": "Attach to Plugin",
"request": "attach",
"hostName": "localhost",
"port": 1044
},
{
"name": "Extension Tests",
"type": "extensionHost",
Expand Down
Binary file added jdtls.ext/.mvn/wrapper/maven-wrapper.jar
Binary file not shown.
1 change: 1 addition & 0 deletions jdtls.ext/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
7 changes: 7 additions & 0 deletions jdtls.ext/com.microsoft.jdtls.daemon.core/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
45 changes: 45 additions & 0 deletions jdtls.ext/com.microsoft.jdtls.daemon.core/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.microsoft.jdtls.daemon.core</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1665551209562</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=11
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
11 changes: 11 additions & 0 deletions jdtls.ext/com.microsoft.jdtls.daemon.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: JDTLS Daemon Core
Bundle-SymbolicName: com.microsoft.jdtls.daemon.core;singleton:=true
Bundle-Version: 0.1.0
Bundle-Activator: com.microsoft.jdtls.daemon.core.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-11
Import-Package: org.osgi.framework;version="1.3.0"
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.jdt.ls.core
Bundle-ClassPath: .
5 changes: 5 additions & 0 deletions jdtls.ext/com.microsoft.jdtls.daemon.core/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
4 changes: 4 additions & 0 deletions jdtls.ext/com.microsoft.jdtls.daemon.core/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
</plugin>
15 changes: 15 additions & 0 deletions jdtls.ext/com.microsoft.jdtls.daemon.core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.microsoft.jdtls.daemon</groupId>
<artifactId>jdtls-daemon-parent</artifactId>
<version>0.1.0</version>
</parent>
<artifactId>com.microsoft.jdtls.daemon.core</artifactId>
<packaging>eclipse-plugin</packaging>
<name>${base.name} :: JDTLS Daemon Plugin</name>
<properties>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*******************************************************************************
* Copyright (c) 2023 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Microsoft Corporation - initial API and implementation
*******************************************************************************/
package com.microsoft.jdtls.daemon.core;

import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import com.sun.management.OperatingSystemMXBean;

import com.microsoft.jdtls.daemon.core.model.JvmReport;

public class Activator implements BundleActivator {

long startTime;

private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);

@Override
public void start(BundleContext bundleContext) throws Exception {
startTime = System.nanoTime();
final Runnable gcSampling = new GcSampling();
scheduler.scheduleAtFixedRate(gcSampling, 1, 1, TimeUnit.MINUTES);
}

@Override
public void stop(BundleContext bundleContext) throws Exception {
scheduler.shutdownNow();
}

private final class GcSampling implements Runnable {
private long lastGcTime = 0;
private long lastCpuTime = 0;

@Override
public void run() {
List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
long totalGcTime = gcBeans.stream().collect(Collectors.summingLong(GarbageCollectorMXBean::getCollectionTime));
long gcTime = totalGcTime - lastGcTime;
lastGcTime = totalGcTime;

OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(
OperatingSystemMXBean.class);

// get cpu time for process.
long totalCpuTime = osBean.getProcessCpuTime();
long cpuTime;
if (totalCpuTime < 0) {
cpuTime = -1;
} else {
cpuTime = totalCpuTime - lastCpuTime;
lastCpuTime = totalCpuTime;
}
cpuTime = TimeUnit.NANOSECONDS.toMillis(cpuTime);

// get swap load
double swapSize = (double) osBean.getTotalSwapSpaceSize();
int swapLoad = (int) (swapSize > 0 ? (1 - osBean.getFreeSwapSpaceSize() / swapSize) * 100 : 0);

JvmReport report = new JvmReport(gcTime, cpuTime, swapLoad);
JavaLanguageServerPlugin.getInstance()
.getClientConnection().executeClientCommand("_jdtls.daemon.jvmReport", report);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2023 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Microsoft Corporation - initial API and implementation
*******************************************************************************/
package com.microsoft.jdtls.daemon.core.model;

/**
* Basic statistics about JVM status.
*/
public class JvmReport {
/**
* Milliseconds used for GC in one time window.
*/
private long gcTime;

/**
* Milliseconds used for the process CPU time in one time window.
*/
private long cpuTime;
/**
* Swap load
*/
private int swapLoad;

public JvmReport(long gcTime, long cpuTime, int swapLoad) {
this.gcTime = gcTime;
this.cpuTime = cpuTime;
this.swapLoad = swapLoad;
}

public long getGcTime() {
return gcTime;
}

public void setGcTime(long gcTime) {
this.gcTime = gcTime;
}

public long getCpuTime() {
return cpuTime;
}

public void setCpuTime(long cpuTime) {
this.cpuTime = cpuTime;
}

public int getSwapLoad() {
return swapLoad;
}

public void setSwapLoad(int swapLoad) {
this.swapLoad = swapLoad;
}

@Override
public String toString() {
return "JvmReport [thisGcTime=" + gcTime + ", thisCpuTime=" + cpuTime + ", swapLoad=" + swapLoad + "]";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target name="JDTLS.EXT" sequenceNumber="39">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.apache.commons.lang3" version="3.1.0.v201403281430"/>
<repository location="https://download.eclipse.org/tools/orbit/R-builds/R20200529191137/repository"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.equinox.core.feature.feature.group" version="0.0.0"/>
<unit id="org.eclipse.equinox.core.sdk.feature.group" version="0.0.0"/>
<unit id="org.eclipse.equinox.executable.feature.group" version="0.0.0"/>
<unit id="org.eclipse.equinox.p2.core.feature.source.feature.group" version="0.0.0"/>
<unit id="org.eclipse.equinox.sdk.feature.group" version="0.0.0"/>
<unit id="org.eclipse.jdt.source.feature.group" version="0.0.0"/>
<unit id="org.eclipse.sdk.feature.group" version="0.0.0"/>
<repository location="https://download.eclipse.org/eclipse/updates/4.27/R-4.27-202303020300"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.xtext.xbase.lib" version="0.0.0"/>
<repository location="https://download.eclipse.org/releases/2022-12/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.jdt.ls.core" version="0.0.0"/>
<repository location="https://download.eclipse.org/jdtls/snapshots/repository/latest/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/lsp4j/updates/releases/0.20.0/"/>
<unit id="org.eclipse.lsp4j.sdk.feature.group" version="0.0.0"/>
</location>
</locations>
</target>
12 changes: 12 additions & 0 deletions jdtls.ext/com.microsoft.jdtls.daemon.target/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.microsoft.jdtls.daemon</groupId>
<artifactId>jdtls-daemon-parent</artifactId>
<version>0.1.0</version>
</parent>
<artifactId>com.microsoft.jdtls.daemon.tp</artifactId>
<name>${base.name} :: Target Platform</name>
<packaging>eclipse-target-definition</packaging>
</project>
Loading