I have a very simple scala async method within main Thread that I am trying to see how much it takes to execute so that I can use the same knowledge to profile my actual API.
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
object ConcurrentTasks {
  def main(args: Array[String]): Unit = {
    println("starting task")
    quickTask()
    println("waiting for 30 secs")
    Thread.sleep(30000)
  }
  private def quickTask(): Future[Int] = {
    for {
      x <- Future {
        Thread.sleep(2000) 
        100
      }
    } yield {
      println("finished computation " + x)
      x
    }
  }
}
The steps I followed for profiling,
- open jvisualvm
 - I run above app using scalac, 
scala ConcurrentTasks.scala - go to Profile tab of running application in jvisualvm and start CPU profile.
 - I see following log trace in my running app.
 
trace
$ scala ConcurrentTasks.scala 
starting task
waiting for 30 secs
finished computation 100
objc[26802]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home//bin/java (0x10899d4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x11041e4e0). One of the two will be used. Which one is undefined.
Profiler Agent: JNI OnLoad Initializing...
Profiler Agent: JNI OnLoad Initialized successfully
Profiler Agent: Waiting for connection on port 5140 (Protocol version: 15)
Profiler Agent: Established connection with the tool
Profiler Agent: Local accelerated session
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent: Redefining 100 classes at idx 0, out of total 106 
Profiler Agent: Redefining 6 classes at idx 100, out of total 106 
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent: Connection with agent closed
Profiler Agent: Connection with agent closed
- Once it is completed I get the snapshot where I don't see my application method at all.
 
I tried both Sampling and Profiling.
It should not matter, I'm using java 1.8.0_151.
My primary question is how do I measure the async scala method execution in jvisualVM?
