From 5e17ca85483c757c667477a63bac342741f389c8 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sat, 18 Jun 2022 22:47:36 +0000 Subject: [PATCH 1/5] Add `IORuntime#liveFiberSnapshot` --- core/shared/src/main/scala/cats/effect/unsafe/IORuntime.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/shared/src/main/scala/cats/effect/unsafe/IORuntime.scala b/core/shared/src/main/scala/cats/effect/unsafe/IORuntime.scala index d5b8b817c0..1f75b3422e 100644 --- a/core/shared/src/main/scala/cats/effect/unsafe/IORuntime.scala +++ b/core/shared/src/main/scala/cats/effect/unsafe/IORuntime.scala @@ -43,6 +43,10 @@ final class IORuntime private[unsafe] ( val config: IORuntimeConfig ) { + def liveFiberSnapshot(): Unit = liveFiberSnapshot(System.err.println(_)) + def liveFiberSnapshot(print: String => Unit): Unit = + fiberMonitor.liveFiberSnapshot(print) + private[effect] val fiberErrorCbs: StripedHashtable = new StripedHashtable() /* From 6ebafe980add58a679d0c5cbaf60dc3eb5892812 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Thu, 30 Jun 2022 01:46:13 +0000 Subject: [PATCH 2/5] Revert "Add `IORuntime#liveFiberSnapshot`" This reverts commit 5e17ca85483c757c667477a63bac342741f389c8. --- core/shared/src/main/scala/cats/effect/unsafe/IORuntime.scala | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/shared/src/main/scala/cats/effect/unsafe/IORuntime.scala b/core/shared/src/main/scala/cats/effect/unsafe/IORuntime.scala index 1f75b3422e..d5b8b817c0 100644 --- a/core/shared/src/main/scala/cats/effect/unsafe/IORuntime.scala +++ b/core/shared/src/main/scala/cats/effect/unsafe/IORuntime.scala @@ -43,10 +43,6 @@ final class IORuntime private[unsafe] ( val config: IORuntimeConfig ) { - def liveFiberSnapshot(): Unit = liveFiberSnapshot(System.err.println(_)) - def liveFiberSnapshot(print: String => Unit): Unit = - fiberMonitor.liveFiberSnapshot(print) - private[effect] val fiberErrorCbs: StripedHashtable = new StripedHashtable() /* From 339c7e14709f002672cebaa4028497cea3a9db6e Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Thu, 30 Jun 2022 01:51:04 +0000 Subject: [PATCH 3/5] Create `FiberInfo` and friends Co-authored-by: Daniel Spiewak --- .../main/scala/cats/effect/FiberInfo.scala | 37 +++++++++++++++++++ .../scala/cats/effect/tracing/Tracing.scala | 7 ++-- 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 core/shared/src/main/scala/cats/effect/FiberInfo.scala diff --git a/core/shared/src/main/scala/cats/effect/FiberInfo.scala b/core/shared/src/main/scala/cats/effect/FiberInfo.scala new file mode 100644 index 0000000000..4755e3e885 --- /dev/null +++ b/core/shared/src/main/scala/cats/effect/FiberInfo.scala @@ -0,0 +1,37 @@ +/* + * Copyright 2020-2022 Typelevel + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cats.effect + +import cats.effect.tracing.Tracing + +final case class FiberInfo(fiber: Fiber[IO, _, _], state: FiberState, trace: FiberTrace) + +sealed abstract class FiberState(override val toString: String) + extends Product + with Serializable + +object FiberState { + case object Running extends FiberState("RUNNING") + case object Blocked extends FiberState("BLOCKED") + case object Yielding extends FiberState("YIELDING") + case object Waiting extends FiberState("WAITING") + case object Active extends FiberState("ACTIVE") +} + +final case class FiberTrace(frames: List[StackTraceElement]) { + def pretty: String = Tracing.prettyPrint(frames) +} diff --git a/core/shared/src/main/scala/cats/effect/tracing/Tracing.scala b/core/shared/src/main/scala/cats/effect/tracing/Tracing.scala index d97c7fa968..d8a2286627 100644 --- a/core/shared/src/main/scala/cats/effect/tracing/Tracing.scala +++ b/core/shared/src/main/scala/cats/effect/tracing/Tracing.scala @@ -141,9 +141,10 @@ private[effect] object Tracing extends TracingPlatform { .collect { case ev: TracingEvent.StackTrace => getOpAndCallSite(ev.getStackTrace) } .filter(_ ne null) - def prettyPrint(events: RingBuffer): String = { - val frames = getFrames(events) + def prettyPrint(events: RingBuffer): String = + prettyPrint(getFrames(events)) + def prettyPrint(frames: List[StackTraceElement]): String = frames .zipWithIndex .map { @@ -152,5 +153,5 @@ private[effect] object Tracing extends TracingPlatform { s" $junc $frame" } .mkString(System.lineSeparator()) - } + } From 74069ae6e7e6340d8abf22e6b4df90026e2e406a Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Thu, 30 Jun 2022 01:52:44 +0000 Subject: [PATCH 4/5] Implement `FiberInfo#pretty` --- .../src/main/scala/cats/effect/FiberInfo.scala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/shared/src/main/scala/cats/effect/FiberInfo.scala b/core/shared/src/main/scala/cats/effect/FiberInfo.scala index 4755e3e885..b7ab41096b 100644 --- a/core/shared/src/main/scala/cats/effect/FiberInfo.scala +++ b/core/shared/src/main/scala/cats/effect/FiberInfo.scala @@ -18,7 +18,17 @@ package cats.effect import cats.effect.tracing.Tracing -final case class FiberInfo(fiber: Fiber[IO, _, _], state: FiberState, trace: FiberTrace) +final case class FiberInfo(fiber: Fiber[IO, _, _], state: FiberState, trace: FiberTrace) { + def pretty = { + val id = System.identityHashCode(fiber).toHexString + val trace = fiber match { + case ioFiber: IOFiber[_] => ioFiber.prettyPrintTrace() + case _ => "" + } + val prefixedTrace = if (trace.isEmpty) "" else "\n" + trace + s"cats.effect.IOFiber@$id $state$prefixedTrace" + } +} sealed abstract class FiberState(override val toString: String) extends Product From 4fe76a7309a204f05cc590bdeccb670738b2ad31 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Thu, 30 Jun 2022 02:18:16 +0000 Subject: [PATCH 5/5] Create `IORuntimeMetrics` and friend Co-authored-by: Daniel Spiewak --- .../scala/cats/effect/IORuntimeMetrics.scala | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 core/shared/src/main/scala/cats/effect/IORuntimeMetrics.scala diff --git a/core/shared/src/main/scala/cats/effect/IORuntimeMetrics.scala b/core/shared/src/main/scala/cats/effect/IORuntimeMetrics.scala new file mode 100644 index 0000000000..00b3c415bc --- /dev/null +++ b/core/shared/src/main/scala/cats/effect/IORuntimeMetrics.scala @@ -0,0 +1,25 @@ +/* + * Copyright 2020-2022 Typelevel + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cats.effect + +final case class IORuntimeMetrics( + enqueued: Int, + foreign: Int, + waiting: Int, + workers: List[IORuntimeWorkerMetrics]) + +final case class IORuntimeWorkerMetrics(index: Int, enqueued: Int)