Skip to content

Commit

Permalink
Fix compilation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
iRevive committed Sep 12, 2023
1 parent 2a6fb61 commit 62a72b4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
2 changes: 1 addition & 1 deletion core/js/src/main/scala/cats/effect/IOApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package cats.effect

import cats.effect.metrics.{CpuStarvationWarningMetrics, JsCpuStarvationMetrics}
import cats.effect.metrics.CpuStarvationWarningMetrics
import cats.effect.std.Console
import cats.effect.tracing.TracingConstants._

Expand Down
3 changes: 2 additions & 1 deletion core/jvm/src/main/scala/cats/effect/IOApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package cats.effect

import cats.effect.std.Console
import cats.effect.metrics.CpuStarvationWarningMetrics
import cats.effect.tracing.TracingConstants._
import cats.effect.unsafe.metrics.{CpuStarvationWarningMetrics, CpuStarvationSamplerMBean}
import cats.effect.unsafe.metrics.CpuStarvationSamplerMBean
import cats.syntax.all._

import scala.concurrent.{blocking, CancellationException, ExecutionContext}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ private[unsafe] abstract class IORuntimeMetricsCompanionPlatform {

private def computeMetrics(compute: ExecutionContext): Option[ComputeMetrics] =
compute match {
case wstp: WorkStealingThreadPool => Some(fromWSTP(wstp))
case wstp: WorkStealingThreadPool[_] => Some(fromWSTP(wstp))
case _ => None
}

private def fromWSTP(wstp: WorkStealingThreadPool): ComputeMetrics =
private def fromWSTP(wstp: WorkStealingThreadPool[_]): ComputeMetrics =
new ComputeMetrics {
def workerThreadCount(): Int = wstp.getWorkerThreadCount()
def activeThreadCount(): Int = wstp.getActiveThreadCount()
Expand Down
12 changes: 2 additions & 10 deletions core/native/src/main/scala/cats/effect/IOApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package cats.effect

import cats.effect.metrics.{CpuStarvationWarningMetrics, NativeCpuStarvationMetrics}
import cats.effect.metrics.CpuStarvationWarningMetrics
import cats.syntax.all._

import scala.concurrent.CancellationException
Expand Down Expand Up @@ -271,23 +271,15 @@ trait IOApp {
else Resource.unit[IO]

val starvationChecker = CpuStarvationCheck
.run(runtimeConfig, NativeCpuStarvationMetrics(), onCpuStarvationWarn)
.run(runtimeConfig, runtime.cpuStarvationSampler, onCpuStarvationWarn)
.background

Spawn[IO]
.raceOutcome[ExitCode, ExitCode](
CpuStarvationCheck
.run(runtimeConfig, runtime.cpuStarvationSampler)
.background
.surround(run(args.toList)),
keepAlive
/*
(fiberDumper *> starvationChecker).surround(run(args.toList)),
awaitInterruptOrStayAlive
)
.map(_.merge)
*/
)
.flatMap {
case Outcome.Canceled() =>
IO.raiseError(new CancellationException("IOApp main fiber was canceled"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

package cats.effect

import cats.effect.metrics.CpuStarvationWarningMetrics
import cats.effect.std.Console
import cats.effect.unsafe.IORuntimeConfig
import cats.effect.unsafe.metrics.CpuStarvationSampler
import cats.syntax.all._
import cats.syntax.all.*

import scala.concurrent.duration.{Duration, FiniteDuration}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cats.effect.metrics

import scala.concurrent.duration.FiniteDuration

final case class CpuStarvationWarningMetrics(
occurrenceTime: FiniteDuration,
clockDrift: FiniteDuration,
starvationThreshold: Double,
starvationInterval: FiniteDuration)
22 changes: 18 additions & 4 deletions core/shared/src/main/scala/cats/effect/unsafe/IORuntime.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ object IORuntime extends IORuntimeCompanionPlatform {
compute,
blocking,
scheduler,
pollers, fiberMonitor,
pollers,
fiberMonitor,
unregisterAndShutdown,
config,
cpuStarvationSampler,
Expand All @@ -109,8 +110,20 @@ object IORuntime extends IORuntimeCompanionPlatform {
scheduler: Scheduler,
fiberMonitor: FiberMonitor,
shutdown: () => Unit,
config: IORuntimeConfig): IORuntime =
new IORuntime(compute, blocking, scheduler, Nil, fiberMonitor, shutdown, config)
config: IORuntimeConfig): IORuntime = {
val cpuStarvationSampler = CpuStarvationSampler.create()
val metrics = IORuntimeMetrics.create(compute, cpuStarvationSampler)
new IORuntime(
compute,
blocking,
scheduler,
Nil,
fiberMonitor,
shutdown,
config,
cpuStarvationSampler,
metrics)
}

def builder(): IORuntimeBuilder =
IORuntimeBuilder()
Expand All @@ -120,7 +133,8 @@ object IORuntime extends IORuntimeCompanionPlatform {
ec,
ec,
scheduler,
Nil, new NoOpFiberMonitor(),
Nil,
new NoOpFiberMonitor(),
() => (),
IORuntimeConfig(),
CpuStarvationSampler.noop,
Expand Down

0 comments on commit 62a72b4

Please sign in to comment.