Skip to content

Commit

Permalink
Introduce DebugProbes.isInstalled method
Browse files Browse the repository at this point in the history
  • Loading branch information
qwwdfsad committed Dec 12, 2019
1 parent 1b378ba commit af9a201
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public final class kotlinx/coroutines/debug/DebugProbes {
public final fun dumpCoroutinesInfo ()Ljava/util/List;
public final fun getSanitizeStackTraces ()Z
public final fun install ()V
public final fun isInstalled ()Z
public final fun jobToString (Lkotlinx/coroutines/Job;)Ljava/lang/String;
public final fun printJob (Lkotlinx/coroutines/Job;Ljava/io/PrintStream;)V
public static synthetic fun printJob$default (Lkotlinx/coroutines/debug/DebugProbes;Lkotlinx/coroutines/Job;Ljava/io/PrintStream;ILjava/lang/Object;)V
Expand Down
6 changes: 6 additions & 0 deletions kotlinx-coroutines-debug/src/DebugProbes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import kotlin.coroutines.*
* Debug probes is a dynamic attach mechanism which installs multiple hooks into coroutines machinery.
* It slows down all coroutine-related code, but in return provides a lot of diagnostic information, including
* asynchronous stack-traces and coroutine dumps (similar to [ThreadMXBean.dumpAllThreads] and `jstack` via [DebugProbes.dumpCoroutines].
* All introspecting methods throw [IllegalStateException] if debug probes were not installed.
*
* Installed hooks:
*
Expand All @@ -41,6 +42,11 @@ public object DebugProbes {
*/
public var sanitizeStackTraces: Boolean = true

/**
* Determines whether debug probes were [installed][DebugProbes.install].
*/
public val isInstalled: Boolean get() = DebugProbesImpl.isInstalled

/**
* Installs a [DebugProbes] instead of no-op stdlib probes by redefining
* debug probes class using the same class loader as one loaded [DebugProbes] class.
Expand Down
2 changes: 1 addition & 1 deletion kotlinx-coroutines-debug/src/internal/DebugProbesImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal object DebugProbesImpl {
private val capturedCoroutines = HashSet<CoroutineOwner<*>>()
@Volatile
private var installations = 0
private val isInstalled: Boolean get() = installations > 0
internal val isInstalled: Boolean get() = installations > 0
// To sort coroutines by creation order, used as unique id
private var sequenceNumber: Long = 0

Expand Down

0 comments on commit af9a201

Please sign in to comment.