使用jvisualvm了解scala非阻塞方法执行

时间:2017-12-17 00:53:21

标签: scala profiling jvisualvm

我在主线程中有一个非常简单的scala异步方法,我试图看看执行需要多少才能使用相同的知识来分析我的实际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
    }
  }

}

我进行分析的步骤

  • open jvisualvm
  • 我使用scalac scala ConcurrentTasks.scala
  • 在app上方运行
  • 转到jvisualvm中运行应用程序的“配置文件”选项卡,然后启动 CPU配置文件
  • 我在正在运行的应用程序中看到了以下日志跟踪。

微量

$ 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
  • 一旦完成,我会得到快照,我根本看不到我的申请方法。

scala_method_profiling

我尝试了Sampling and Profiling

没关系,我正在使用java 1.8.0_151

我的主要问题是如何在jvisualVM中测量异步scala方法执行?

0 个答案:

没有答案