Skip to content

Commit abc6cd8

Browse files
Feat: updated debugging coroutines in the documentation (#2191)
1 parent 9139c64 commit abc6cd8

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

coroutines-guide.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ The main coroutines guide has moved to the [docs folder](docs/coroutines-guide.m
3232
* <a name='dispatchers-and-threads'></a>[Dispatchers and threads](docs/coroutine-context-and-dispatchers.md#dispatchers-and-threads)
3333
* <a name='unconfined-vs-confined-dispatcher'></a>[Unconfined vs confined dispatcher](docs/coroutine-context-and-dispatchers.md#unconfined-vs-confined-dispatcher)
3434
* <a name='debugging-coroutines-and-threads'></a>[Debugging coroutines and threads](docs/coroutine-context-and-dispatchers.md#debugging-coroutines-and-threads)
35+
* <a name='debugging-with-idea'></a>[Debugging with IDEA](docs/coroutine-context-and-dispatchers.md#debugging-with-idea)
36+
* <a name='debugging-using-logging'></a>[Debugging using logging](docs/coroutine-context-and-dispatchers.md#debugging-using-logging)
3537
* <a name='jumping-between-threads'></a>[Jumping between threads](docs/coroutine-context-and-dispatchers.md#jumping-between-threads)
3638
* <a name='job-in-the-context'></a>[Job in the context](docs/coroutine-context-and-dispatchers.md#job-in-the-context)
3739
* <a name='children-of-a-coroutine'></a>[Children of a coroutine](docs/coroutine-context-and-dispatchers.md#children-of-a-coroutine)

docs/coroutine-context-and-dispatchers.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* [Dispatchers and threads](#dispatchers-and-threads)
99
* [Unconfined vs confined dispatcher](#unconfined-vs-confined-dispatcher)
1010
* [Debugging coroutines and threads](#debugging-coroutines-and-threads)
11+
* [Debugging with IDEA](#debugging-with-idea)
12+
* [Debugging using logging](#debugging-using-logging)
1113
* [Jumping between threads](#jumping-between-threads)
1214
* [Job in the context](#job-in-the-context)
1315
* [Children of a coroutine](#children-of-a-coroutine)
@@ -155,8 +157,35 @@ The unconfined dispatcher should not be used in general code.
155157

156158
Coroutines can suspend on one thread and resume on another thread.
157159
Even with a single-threaded dispatcher it might be hard to
158-
figure out what the coroutine was doing, where, and when. The common approach to debugging applications with
159-
threads is to print the thread name in the log file on each log statement. This feature is universally supported
160+
figure out what the coroutine was doing, where, and when if you don't have special tooling.
161+
162+
#### Debugging with IDEA
163+
164+
The Coroutine Debugger of the Kotlin plugin simplifies debugging coroutines in IntelliJ IDEA.
165+
166+
> Debugging works for versions 1.3.8 or later of `kotlinx-coroutines-core`.
167+
168+
The **Debug Tool Window** contains a **Coroutines** tab. In this tab, you can find information about both currently
169+
running and suspended coroutines. The coroutines are grouped by the dispatcher they are running on.
170+
171+
![Debugging coroutines](images/coroutine-debugger.png)
172+
173+
You can:
174+
* Easily check the state of each coroutine.
175+
* See the values of local and captured variables for both running and suspended coroutines.
176+
* See a full coroutine creation stack, as well as a call stack inside the coroutine. The stack includes all frames with
177+
variable values, even those that would be lost during standard debugging.
178+
179+
If you need a full report containing the state of each coroutine and its stack, right-click inside the **Coroutines** tab, and then
180+
click **Get Coroutines Dump**.
181+
182+
Learn more about debugging coroutines in [this blog post](https://blog.jetbrains.com/kotlin/2020/07/kotlin-1-4-rc-debugging-coroutines/)
183+
and [IntelliJ IDEA documentation](https://www.jetbrains.com/help/idea/debug-kotlin-coroutines.html).
184+
185+
#### Debugging using logging
186+
187+
Another approach to debugging applications with
188+
threads without Coroutine Debugger is to print the thread name in the log file on each log statement. This feature is universally supported
160189
by logging frameworks. When using coroutines, the thread name alone does not give much of a context, so
161190
`kotlinx.coroutines` includes debugging facilities to make it easier.
162191

docs/images/coroutine-debugger.png

382 KB
Loading

0 commit comments

Comments
 (0)