diff options
| -rw-r--r-- | src/main/scala/main/Main.scala | 67 | ||||
| -rw-r--r-- | src/main/scala/main/services/Benchmark.scala | 2 | ||||
| -rw-r--r-- | src/main/scala/main/services/Stress.scala | 93 | ||||
| -rw-r--r-- | src/main/scala/main/view/View.scala | 60 |
4 files changed, 159 insertions, 63 deletions
diff --git a/src/main/scala/main/Main.scala b/src/main/scala/main/Main.scala index b2d73ef..eaca7ab 100644 --- a/src/main/scala/main/Main.scala +++ b/src/main/scala/main/Main.scala @@ -1,31 +1,70 @@ +/** + * __ + * _/ |_ ___________ ________ __ ____ + * \ __\/ _ \_ __ \/ ____/ | \_/ __ \ + * | | ( <_> ) | \< <_| | | /\ ___/ + * |__| \____/|__| \__ |____/ \___ > + * |__| \/ + */ + package main import main.domain._ import main.services._ import main.infrastructure._ +import main.view._ import oshi._ import zio.http._ import java.lang.foreign._ import zio._ -object Torque extends ZIOAppDefault { +object Torque extends ZIOAppDefault with Runner { + + + + def run: ZIO[Any, Throwable, Unit] = { + + handler() + + + /** + * In case the user needs a quick basic run without running through the DIY DUI + * */ + + // args(1) match { + // case "cpu" => lightCpuRun + // case "ram" => lightRamRun + // case _ => handler() + // } - def run = + } + + def serve = { Server.serve(routes) .provide(Server.default) .exitCode + } + + /** + * + * Stress the given target + * Capture the information + * and send that over an API + * + * => doing these steps in a handler to be a little more modular + * */ + + def handler(): ZIO[Any, Throwable, Unit] = { + + val v: View = new View + + for { + + _ <- ZIO.debug("started") + _ <- v.serveView.fork + _ <- ZIO.debug("finished") - // override def run: ZIO[ZIOAppArgs & Scope, Any, Any] = memoryExecution - // - // def memoryExecution: ZIO[Any, Throwable, Unit] = { - // - // - // for { - // _ <- ZIO.debug("started") - // f1 = MemoryAllocater.run() - // _ <- ZIO.debug("finished") - // - // } yield () - // } + } yield () + } } diff --git a/src/main/scala/main/services/Benchmark.scala b/src/main/scala/main/services/Benchmark.scala index 59c81e9..fbb4661 100644 --- a/src/main/scala/main/services/Benchmark.scala +++ b/src/main/scala/main/services/Benchmark.scala @@ -18,6 +18,8 @@ class Benchmark { // TODO: map this to an actual precision value def measurePrecision(work: => Boolean, expectedResult: Boolean): Unit = if work == expectedResult then println(true) else println(false) + + def measureStabililty(): Float = 1 / 10 } diff --git a/src/main/scala/main/services/Stress.scala b/src/main/scala/main/services/Stress.scala index 79cd041..d1d27c8 100644 --- a/src/main/scala/main/services/Stress.scala +++ b/src/main/scala/main/services/Stress.scala @@ -2,39 +2,42 @@ package main.services import main.domain._ import main.services._ +import main.infrastructure._ import oshi._ import zio._ - -enum Status: - case PASS - case FAIL - abstract class Stress { def runSequential: ZIO[Any, Throwable, Unit] def runParallel: ZIO[Any, Throwable, Unit] - def setStatus: Unit } class StressCpu() extends Stress { - var status: Status = Status.PASS - def setStatus: Unit = status = Status.PASS + def safety: Unit = { + val systemInfo = new SystemInfo + val sensors = systemInfo.getHardware.getSensors + while (true) do if sensors.getCpuTemperature > 80 then println("overheat") + } + def runCholeskyTest: ZIO[Any, Throwable, Unit] = { - ZIO.attempt { - //TODO: declare a randomized array to pass into the runner - // cd.run(matrix) - }.catchAll { error => Console.printError(s"failed: $error")} + ZIO + .attempt { + // TODO: declare a randomized array to pass into the runner + // cd.run(matrix) + } + .catchAll { error => Console.printError(s"failed: $error") } } def runPrimeTest: ZIO[Any, Throwable, Unit] = { - ZIO.attempt { - // p.run(390483094, true) - }.catchAll { error => Console.printError(s"failed: $error")} + ZIO + .attempt { + // p.run(390483094, true) + } + .catchAll { error => Console.printError(s"failed: $error") } } override def runSequential: ZIO[Any, Throwable, Unit] = { @@ -54,21 +57,61 @@ class StressCpu() extends Stress { class StressRam() extends Stress { - var status: Status = Status.PASS - - override def setStatus: Unit = status = Status.PASS override def runSequential: ZIO[Any, Throwable, Unit] = { - - ZIO.attempt { - // TODO: - }.catchAll { error => Console.printError(s"failed: $error")} + ZIO + .attempt { + // TODO: + } + .catchAll { error => Console.printError(s"failed: $error") } + + } + + override def runParallel: ZIO[Any, Throwable, Unit] = { + ZIO.attempt {}.catchAll { error => Console.printError(s"failed: $error") } + } +} + +trait Runner { + + val c: StressCpu = new StressCpu + val r: StressRam = new StressRam + + def heavyCpuRun: Task[Unit] = { + + for { + _ <- c.runParallel + _ <- c.runSequential + _ <- c.runParallel + } yield() } - override def runParallel : ZIO[Any, Throwable, Unit] = { - ZIO.attempt { + def lightCpuRun: Task[Unit] = { + + for { + + _ <- c.runSequential + + } yield() + } - }.catchAll { error => Console.printError(s"failed: $error")} + def heavyRamRun: Task[Unit] = { + + for { + _ <- r.runParallel + _ <- r.runSequential + _ <- r.runParallel + } yield() } + + + def lightRamRun: Task[Unit] = { + + for { + + _ <- r.runSequential + + } yield() + } } diff --git a/src/main/scala/main/view/View.scala b/src/main/scala/main/view/View.scala index fd931a8..5213865 100644 --- a/src/main/scala/main/view/View.scala +++ b/src/main/scala/main/view/View.scala @@ -1,5 +1,9 @@ package main.view +import zio._ +import main.infrastructure._ +import main.services._ +import java.lang.System /** * @@ -7,9 +11,17 @@ package main.view * **/ -class View { +/** + * + * Trying to make the passed methods runnable by the fibers + * + **/ + +class View extends Runner { + var resources: Resources = new Resources + /** * General utils that will be used a lot later * */ @@ -62,20 +74,10 @@ class View { } } - def checkInput(input: String): Unit = { - - toInt(input) match { - - case 1 => println("stressing cpu") - case 2 => println("stressing ram") - case 3 => System.exit(0) - - } -} - - def menu: Unit = { + def menu: ZIO[Any, Throwable, Unit] = { var continue = true + var target = "" while (continue) { @@ -87,28 +89,38 @@ class View { _/ |_ ___________ ________ __ ____ \ __\/ _ \_ __ \/ ____/ | \_/ __ \ | | ( <_> ) | \< <_| | | /\ ___/ - |__| \____/|__| \__ |____/ \___ > + |__| \____/|__| \__ |____/ \___ > |__| \/ |======= Select the stress test ========| - | 1: CPU | - | 2: Ram | - | 3: Exit | + | 1: light Cpu | + | 2: Heavy Cpu | + | 3: Light Ram | + | 4: Heavy Ram | + | 5: Exit | |=======================================| """ ) - - checkInput(scala.io.StdIn.readLine()) - } + target = scala.io.StdIn.readLine() + continue = false + } - } + clearScreen + toInt(target) match { + + case 1 => lightCpuRun <&> resources.getCpuInfo + case 2 => heavyCpuRun <&> resources.getCpuInfo + case 3 => lightCpuRun <&> resources.getRamInfo + case 4 => heavyCpuRun <&> resources.getRamInfo - def serveView: Unit = { - + + } + } + + def serveView: ZIO[Any, Throwable, Unit] = { clearScreen header menu - } } |
