在Eclipse中使用Java Flight Recorder和Java Mission Control对Java 8进行性能分析

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collection framework built into the Oracle JDK. It allows Java administrators and developers to gather detailed low level information about how the Java Virtual Machine (JVM) and the Java application are behaving. Java Mission Control is an advanced set of tools that enables efficient and detailed analysis of the extensive of data collected by Java Flight Recorder. The tool chain enables developers and administrators to collect and analyze data from Java applications running locally or deployed in production environments.
Java Flight Recorder和Java Mission Control共同创建了一个完整的工具链,以连续收集低水平和详细的运行时信息,从而进行事后事件分析。 Java Flight Recorder是Oracle JDK中内置的概要分析和事件收集框架。 它允许Java管理员和开发人员收集有关Java虚拟机(JVM)和Java应用程序行为方式的详细底层信息。 Java Mission Control是一组高级工具,可对Java Flight Recorder收集的大量数据进行高效,详细的分析。 该工具链使开发人员和管理员可以从本地运行或部署在生产环境中的Java应用程序收集和分析数据。

The Java Flight Recorder does not trace every function call that gets executed. Instead, it "samples" the application at regular intervals, collecting stack trace information about each thread being executed. So if you're looking for how many times a certain function is being called, or how much total time is spent executing a certain method, you're not going to find that kind of information. However, by analyzing the samples taken, you can still determine where your application is spending most of its time.

Java Flight Recorder不会跟踪每个执行的函数调用。 而是定期对应用程序进行“采样”,收集有关正在执行的每个线程的堆栈跟踪信息。 因此,如果要查找某个函数的调用次数或执行某个方法所花费的总时间,则不会找到这种信息。 但是,通过分析样本,您仍然可以确定应用程序大部分时间都花在了哪里。

We'll assume, at this point, that Java 8 and Eclipse are already installed. If they are not, they can be found at the following locations:

此时,我们假定已经安装了Java 8和Eclipse。 如果不是,则可以在以下位置找到它们:

Once that's complete, create a simple java application that could use some optimization:

完成后,创建一个可以使用一些优化的简单Java应用程序:

   public static void main(String[] args)
   {
      // These values may need to change depending upon the speed of your machine.
      // You want this app to run for approximately 60 seconds to get usable results
      final int outerIterations = 1000;
      final int innerIterations = 10000;

      for (int outer = 0; outer < outerIterations; outer++)
      {
         StringBuilder message = new StringBuilder();

         for (int inner = 0; inner < innerIterations; inner++)
         {
            message.append(inner);
         }

         System.out.println(message);
      }
   }

Create a Run Configuration for the java application:

为Java应用程序创建运行配置:

  • Run -> Run Configurations...
    • Java Application -> New

    运行->运行配置...
    • Java应用程序->新建

Make sure the following two options are checked:

确保选中以下两个选项:

  • Enable - This will create a flight recording of the running application

    启用
  • Open recording - This will automatically open the flight recording when the application completes

    打开录音

Now run the application using the Run configuration. Once the application is finished, and the flight recording is open, we can see a lot of information about the running application.

现在,使用“运行”配置运行应用程序。 一旦应用程序完成,并且飞行记录已打开,我们就可以看到有关正在运行的应用程序的许多信息。

  • Select the Code tab on the left.
    • From here we can see the packages and classes in which the application is spending its time.

    选择左侧的代码标签。
    • 从这里我们可以看到应用程序花费时间的包和类。
  • Select the "Hot Methods" tab on the bottom (still within the Code tab on the left)
    • Here we can see the methods in which the application is spending its time

    选择底部的“热方法”标签(仍在左侧的“代码”标签内)
    • 在这里,我们可以看到应用程序花费时间的方法
  • Select the "Call Tree" tab on the bottom
    • Here we can see the stack traces in which the application is spending most of its time

    选择底部的“呼叫树”标签
    • 在这里,我们可以看到应用程序花费大部分时间的堆栈跟踪
  • Select the Memory tab on the left

    选择左侧的“内存”选项卡
  • Select the Garbage Collections tab on the bottom (still within the Memory tab on the left)

    选择底部的“垃圾回收”标签(仍在左侧的“内存”标签内)

翻译自: https://www.experts-exchange.com/articles/17474/Profiling-Java-8-with-Java-Flight-Recorder-and-Java-Mission-Control-in-Eclipse.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值