I use Java Mission Control, jmc github pretty often and it’s really cool tool for analyzing and profiling JVM apps. I’m using it even for Scala projects, but reading Java stack-traces for Scala and mapping them back to original Scala code slows you down. Here is pretty simple Scala code (Example.scala):
import scala.util.Random
import scala.math
object Example {
val MaxRandomNumber: Int = 1000000
def main(args: Array[String]): Unit = {
val rnd = new Random()
val nums = Array.fill[Int](5*1024*1024)(rnd.nextInt(MaxRandomNumber))
val mapped = nums.map { x =>
Math.sqrt(x)
}
val odds = nums.filter(x => x % 2 == 1)
val collected = nums.collect { case x if x % 2 == 0 =>
Math.pow(x, 0.3)
}
println(s"mapped size: ${mapped.size}")
println(s"odds size: ${odds.size}")
println(s"collected size: ${collected.size}")
}
}
Compile via: scalac Example.scala
Run via: scala Example -J-XX:+UnlockCommercialFeatures -J-XX:+FlightRecorder -J-XX:FlightRecorderOptions=defaultrecording=true,disk=true,maxage=10h,dumponexit=true,loglevel=info
And here is how its stack-trace looks. It takes sometime to map back Java stack-trace to actual Scala code:
Does it make sense to make jmc
aware of Scala? Does community uses it?
Thanks.