Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IORuntime#liveFiberSnapshot #3038

Draft
wants to merge 5 commits into
base: series/3.x
Choose a base branch
from

Conversation

armanbilge
Copy link
Member

Starting from the obvious 😂

Fixes #2580. Fixes #3025.

Comment on lines 46 to 48
def liveFiberSnapshot(): Unit = liveFiberSnapshot(System.err.println(_))
def liveFiberSnapshot(print: String => Unit): Unit =
fiberMonitor.liveFiberSnapshot(print)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should expose a method that returns a String (collection)? Something that can be called from the IDE/debugger easily.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I'm not sure how useful that is. I guess a test framework would call this method during its timeout hook on a test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't want to expose this here, we could make it a method in the testkit package. Then only test frameworks could use it.

@djspiewak
Copy link
Member

So I think that rolling it up in this way is probably unhelpful. I think what we want is something isomorphic to this:

final class IORuntime(...) { 
  // ...

  /**
   * We should have a warning here about memory leaks, since it contains hard references to Fiber(s)
   */
  def snapshot(): List[FiberInfo] = ???
  def metrics(): IORuntimeMetrics = ???
}

final case class IORuntimeMetrics(enqueued: Int, foreign: Int, waiting: Int, workers: List[IORuntimeWorkerMetrics])
final case class IORuntimeWorkerMetrics(index: Int, enqueued: Int)

final case class FiberInfo(fiber: Fiber[IO, _], state: FiberState, trace: FiberTrace)

sealed 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 = ???
}

We should gather the FiberInfos into a List at the last possible moment, keeping everything lazy up to that point. In this way, we can refactor liveFiberSnapshot itself to work in terms of these data structures without loss of generality or memory safety.

I believe the above should be sufficient for any external framework to implement the type of semantic they want. It's still an open question of what form that integration should take, but it's more of a problem for munit/specs/etc.

@djspiewak djspiewak marked this pull request as draft June 19, 2022 20:36
@Daenyth
Copy link
Contributor

Daenyth commented Apr 5, 2023

What work remains on this? Is there a clear spot where someone can come in and help?

@armanbilge
Copy link
Member Author

armanbilge commented Apr 5, 2023

@Daenyth

What work remains on this?

I think I've copied Daniel's proposed data structures into the PR. If I haven't yet, that's the first step.

Then, all existing fiber dump machinery should be migrated to those data structures. Currently it is just string manipulation.

Is there a clear spot where someone can come in and help?

Yep, someone can take over the PR (or start from scratch) proceeding with the above. I would appreciate it!!

@djspiewak djspiewak modified the milestones: v3.6.0, v3.7.0 May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Find a way to integrate fiber dumps with test frameworks Provide within-process "public" API for fiber dumps
3 participants