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 dump thread logic temporary #2124

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.runtime.api.values.BString;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.lang.management.ManagementFactory;

import static io.ballerina.stdlib.graphql.runtime.utils.ModuleUtils.getModule;

/**
Expand All @@ -36,6 +41,19 @@ public class Utils {
private Utils() {
}

static {
Thread.startVirtualThread(() -> {
try {
Thread.sleep(5 * 60 * 1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
}

public static final PrintStream OUT = System.out;
public static final PrintStream ERROR = System.err;

// Inter-op function names
private static final String EXECUTE_RESOURCE_FUNCTION = "executeQueryResource";
private static final String EXECUTE_INTERCEPTOR_FUNCTION = "executeInterceptor";
Expand Down Expand Up @@ -105,4 +123,33 @@ public static void handleBErrorAndExit(BError bError) {
// Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714
System.exit(1);
}

public static void dumpThreads() {
try {
// Get the current process ID (PID)
String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];

// Build the jcmd command
String command = "jcmd " + pid;

// Execute the jcmd command
Process process = Runtime.getRuntime().exec(command);

// Read the output of the command
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
OUT.println(line);
}
}

// Wait for the process to complete
int exitCode = process.waitFor();
if (exitCode != 0) {
ERROR.println("jcmd command failed with exit code: " + exitCode);
}
} catch (Exception error) {
error.printStackTrace();
}
}
}
1 change: 1 addition & 0 deletions native/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
requires io.ballerina.stdlib.graphql.commons;
requires io.ballerina.lang;
requires jdk.jshell;
requires java.management;
}
5 changes: 5 additions & 0 deletions spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@
<Bug pattern="DM_EXIT" />
</And>
</Match>
<Match>
<And>
<Class name="io.ballerina.stdlib.graphql.runtime.utils.Utils" />
</And>
</Match>
</FindBugsFilter>
Loading