You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want enable coroutine dump for Production.
I tried add DebugProbes.install() at main class but when I run mvn test, execution was blocked [2]
I cannot use javaagent due to limitation of our deploy system.
Also I am not sure if it will work with well with multiple classloaders (we have some apps deployed as webapps into stand-alone Tomcat server)
As all what DebugProbes.install() instrumentation do is replacing one class with another implementation, I created following class to enable functionality without instrumentation [1]. It is written on Java because Kotlin forbids compile kotlin* packages.
Could we create maven artifact in kotlinx.coroutines repo that can be placed at the beginning of the classpath to enable DebugProbes?
[1] Patch class:
package kotlin.coroutines.jvm.internal;
import kotlin.coroutines.Continuation;
import kotlinx.coroutines.debug.DebugProbes;
import kotlinx.coroutines.debug.internal.AgentInstallationType;
import java.lang.reflect.Method;
public class DebugProbesKt {
/**
* This class is defined at https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/jvm/src/kotlin/coroutines/jvm/internal/DebugProbes.kt
* DebugProbes.install will replace it with kotlin.coroutines.jvm.internal.DebugProbesKt (via instrumentation and attach api)
* <p>
* I found that instrumentation can (dead?)lock the tests.
* And I decide to change instrumentation to class path patch.
*/
private static final Method probeCoroutineCreatedMethod;
private static final Method probeCoroutineResumedMethod;
private static final Method probeCoroutineSuspended;
static {
try {
// mark that DebugProbes are installed and no instrumentation is needed
AgentInstallationType.INSTANCE.setInstalledStatically$kotlinx_coroutines_core(true);
DebugProbes.INSTANCE.install(); // start cleaner thread
Class<?> delegate = Class.forName("kotlinx.coroutines.debug.internal.DebugProbesKt");
probeCoroutineCreatedMethod = delegate.getDeclaredMethod("probeCoroutineCreated", Continuation.class);
probeCoroutineCreatedMethod.setAccessible(true);
probeCoroutineResumedMethod = delegate.getDeclaredMethod("probeCoroutineResumed", Continuation.class);
probeCoroutineResumedMethod.setAccessible(true);
probeCoroutineSuspended = delegate.getDeclaredMethod("probeCoroutineSuspended", Continuation.class);
probeCoroutineSuspended.setAccessible(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static <T> Continuation<T> probeCoroutineCreated(Continuation<T> completion) throws Exception {
return (Continuation<T>) probeCoroutineCreatedMethod.invoke(null, completion);
}
public static void probeCoroutineResumed(Continuation<?> frame) throws Exception {
probeCoroutineResumedMethod.invoke(null, frame);
}
public static void probeCoroutineSuspended(Continuation<?> frame) throws Exception {
probeCoroutineSuspended.invoke(null, frame);
}
}
Also I am not sure if it will work well with multiple classloaders (we have some apps deployed as webapps into stand-alone Tomcat server)
Should work unless these classloaders all have loaded coroutines/stdlib that are trying to communicate directly (e.g. call each other). In that case, though, a debugger is the least of the problems :)
Could we create maven artifact in kotlinx.coroutines repo that can be placed at the beginning of the classpath to enable DebugProbes?
Unfortunately, the answer is no. The burden of maintaining it, explaining to users why it exists in the first place and what is the difference from other artifacts is just too high for the problem that is being solved.
We of course change this if there will be a lot of demand (e.g. hypothetical $newBuildSystemThatIsSuperPopular will require that), but not for the sake of a single use-case. I would suggest you stick with your own hand-rolled solution for now.
Hi,
I want enable coroutine dump for Production.
I tried add DebugProbes.install() at main class but when I run
mvn test
, execution was blocked [2]I cannot use javaagent due to limitation of our deploy system.
Also I am not sure if it will work with well with multiple classloaders (we have some apps deployed as webapps into stand-alone Tomcat server)
As all what DebugProbes.install() instrumentation do is replacing one class with another implementation, I created following class to enable functionality without instrumentation [1]. It is written on Java because Kotlin forbids compile kotlin* packages.
Could we create maven artifact in kotlinx.coroutines repo that can be placed at the beginning of the classpath to enable DebugProbes?
[1] Patch class:
[2] Locked tests:
The text was updated successfully, but these errors were encountered: