-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abdea68
commit 79a2867
Showing
6 changed files
with
100 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
zio-profiling-tagging-plugin-tests/src/main/scala/zio/profiling/ProfilerExamples.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package zio.profiling | ||
|
||
import zio._ | ||
import zio.stream.ZStream | ||
|
||
object ProfilerExamples { | ||
val fast: ZIO[Any, Nothing, Unit] = ZIO.succeed(Thread.sleep(400)) | ||
|
||
val slow: ZIO[Any, Nothing, Unit] = ZIO.succeed(Thread.sleep(200)) <&> ZIO.succeed(Thread.sleep(600)) | ||
|
||
val zioProgram: ZIO[Any, Nothing, Unit] = fast <&> slow | ||
|
||
val fastStream: ZStream[Any, Nothing, Unit] = ZStream.fromZIO(fast) | ||
|
||
val slowStream: ZStream[Any, Nothing, Unit] = ZStream.fromZIO(slow) | ||
|
||
val zioStreamProgram: ZIO[Any, Nothing, Unit] = (fastStream <&> slowStream).runDrain | ||
} |
41 changes: 41 additions & 0 deletions
41
...gging-plugin-tests/src/test/scala/zio/profiling/sampling/PluginSamplingProfilerSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package zio.profiling.sampling | ||
|
||
import zio.profiling.{CostCenter, ProfilerExamples} | ||
import zio.test.Assertion.{hasSize, isGreaterThanEqualTo} | ||
import zio.test._ | ||
import zio.Scope | ||
|
||
object PluginSamplingProfilerSpec extends ZIOSpecDefault { | ||
|
||
def spec: Spec[Environment with TestEnvironment with Scope, Any] = suite("PluginSamplingProfiler")( | ||
test("Should correctly profile simple example program") { | ||
Live.live(SamplingProfiler().profile(ProfilerExamples.zioProgram)).map { result => | ||
val sortedEntries = result.entries.sortBy(_.samples).reverse | ||
|
||
def isSlowEffect(location: CostCenter) = | ||
location.hasParentMatching("zio\\.profiling\\.ProfilerExamples\\.slow\\(.*\\)".r) | ||
def isFastEffect(location: CostCenter) = | ||
location.hasParentMatching("zio\\.profiling\\.ProfilerExamples\\.fast\\(.*\\)".r) | ||
|
||
assert(sortedEntries)(hasSize(isGreaterThanEqualTo(2))) && | ||
assertTrue(isSlowEffect(sortedEntries(0).costCenter)) && | ||
assertTrue(isFastEffect(sortedEntries(1).costCenter)) | ||
} | ||
}, | ||
test("Should correctly profile simple example streams program") { | ||
Live.live(SamplingProfiler().profile(ProfilerExamples.zioStreamProgram)).map { result => | ||
val sortedEntries = result.entries.sortBy(_.samples).reverse | ||
|
||
def isSlowEffect(location: CostCenter) = | ||
location.hasParentMatching("zio\\.profiling\\.ProfilerExamples\\.slowStream\\(.*\\)".r) | ||
def isFastEffect(location: CostCenter) = | ||
location.hasParentMatching("zio\\.profiling\\.ProfilerExamples\\.fastStream\\(.*\\)".r) | ||
|
||
assert(sortedEntries)(hasSize(isGreaterThanEqualTo(2))) && | ||
assertTrue(isSlowEffect(sortedEntries(0).costCenter)) && | ||
assertTrue(isFastEffect(sortedEntries(1).costCenter)) | ||
} | ||
} | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters