Skip to content

Commit ea2bfe2

Browse files
committed
Debug agent cleanup
* Readme * Do not fail on Windows during signal handler installation * Do not warn about missing artificial stackframe
1 parent 7520c97 commit ea2bfe2

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

core/kotlinx-coroutines-debug/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ Debugging facilities for `kotlinx.coroutines` on JVM.
44

55
### Overview
66

7-
This module provides a debug JVM agent which allows to track and trace alive coroutines.
8-
Main entry point to debug facilities is [DebugProbes].
7+
This module provides a debug JVM agent which allows to track and trace existing coroutines.
8+
The main entry point to debug facilities is [DebugProbes] API.
99
Call to [DebugProbes.install] installs debug agent via ByteBuddy and starts to spy on coroutines when they are created, suspended or resumed.
1010

11-
After that you can use [DebugProbes.dumpCoroutines] to print all active (suspended or running) coroutines, including their state, creation and
11+
After that, you can use [DebugProbes.dumpCoroutines] to print all active (suspended or running) coroutines, including their state, creation and
1212
suspension stacktraces.
13-
Additionally, it is possible to process list of such coroutines via [DebugProbes.dumpCoroutinesState] or dump isolated parts
14-
of coroutines hierarchies referenced by [Job] instance using [DebugProbes.printHierarchy].
13+
Additionally, it is possible to process the list of such coroutines via [DebugProbes.dumpCoroutinesState] or dump isolated parts
14+
of coroutines hierarchy referenced by a [Job] instance using [DebugProbes.printHierarchy].
1515

1616
### Using as JVM agent
1717

18-
Additionally, it is possible to use this module as standalone JVM agent to enable debug probes on the application startup.
19-
You can run your application with additional argument: `-javaagent:kotlinx-coroutines-debug-1.1.0.jar`.
18+
It is possible to use this module as a standalone JVM agent to enable debug probes on the application startup.
19+
You can run your application with an additional argument: `-javaagent:kotlinx-coroutines-debug-1.1.0.jar`.
2020
Additionally, on Linux and Mac OS X you can use `kill -5 $pid` command in order to force your application to print all alive coroutines.
2121

2222

core/kotlinx-coroutines-debug/src/AgentPremain.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ internal object AgentPremain {
1919
}
2020

2121
private fun installSignalHandler() {
22-
Signal.handle(Signal("TRAP") ) { // kill -5
23-
DebugProbes.dumpCoroutines()
22+
try {
23+
Signal.handle(Signal("TRAP")) { // kill -5
24+
DebugProbes.dumpCoroutines()
25+
}
26+
} catch (t: Throwable) {
27+
System.err.println("Failed to install signal handler: $t")
2428
}
2529
}
2630
}

core/kotlinx-coroutines-debug/src/internal/DebugProbesImpl.kt

+1-10
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,7 @@ internal object DebugProbesImpl {
151151

152152
@Synchronized
153153
private fun updateState(owner: ArtificialStackFrame<*>?, frame: Continuation<*>, state: State) {
154-
val coroutineState = capturedCoroutines[owner]
155-
if (coroutineState == null) {
156-
warn(frame, state)
157-
return
158-
}
154+
val coroutineState = capturedCoroutines[owner] ?: return
159155
coroutineState.updateState(state, frame)
160156
}
161157

@@ -257,9 +253,4 @@ internal object DebugProbesImpl {
257253
}
258254

259255
private val StackTraceElement.isInternalMethod: Boolean get() = className.startsWith("kotlinx.coroutines")
260-
261-
private fun warn(frame: Continuation<*>, state: State) {
262-
// TODO make this warning configurable or not a warning at all
263-
System.err.println("Failed to find an owner of the frame $frame while transferring it to the state $state")
264-
}
265256
}

core/kotlinx-coroutines-debug/test/DebugProbesTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class DebugProbesTest : TestBase() {
6666

6767
@Test
6868
fun testAsyncWithSanitizedProbes() = DebugProbes.withDebugProbes {
69+
DebugProbes.sanitizeStackTraces = true
6970
runTest {
7071
val deferred = createDeferred()
7172
val traces = listOf(

0 commit comments

Comments
 (0)