jprofiler使用

来源:互联网 发布:柏林 韩国电影 知乎 编辑:程序博客网 时间:2024/06/05 10:10

  • 1 安装
    • 1-1 windows和mac安装
    • 1-2 linux安装
  • 2 使用
    • 2-1 windowmac使用
      • 2-1-1 IDE集成
      • 2-1-2 已有jvm连接
      • 2-1-3 连接远程jvm进程
      • 2-1-4 拷贝配置文件
      • 2-1-5 offline启动
  • 3 设置
    • 3-1 过滤器设置
      • 3-1-1 class filter
      • 3-1-2 Ignored Methods
    • 3-2 profilering 设置
    • 3-3 配置导出
  • 快照
  • profiling视图最重要的部分
    • 5-1 内存视图
    • 5-2 堆视图
    • 5-3 cpu视图
      • 5-3-1 总体描述
      • 5-3-2 call tree view
      • 5-3-3 hot-spot view
    • 5-4 thread view

.1 安装

.1-1 windows和mac安装

直接下载官网最新版本安装,只有十天试用期

.1-2 linux安装

http://download-keycdn.ej-technologies.com/jprofiler/jprofiler_linux_10_0_1.tar.gz
http://download-keycdn.ej-technologies.com/jprofiler/jprofiler_linux_10_0_1.rpm
http://download-keycdn.ej-technologies.com/jprofiler/jprofiler_linux_10_0_1.sh
执行 sh jprofiler_linux_10_0_1.sh,安装过程中会让选择安装目录,这个目录要记录下来,远程连接要用到

.2 使用

.2-1 window/mac使用

.2-1-1 IDE集成

安装过程中会让选择集成的ide,选择ide安装目录即可

.2-1-2 已有jvm连接

连接本地jvm进程
session->integerate wisard

.2-1-3 连接远程jvm进程

session->integerate wisard->remote->on a remote computer(linux x86/amd64)->oracle:1.8.0:hotspot->profileoffline->remote address(linux ip)
->remote installation dir(1.2中的安装目录)->synchronize profiling settings(default)->获取sessionid

2-1-4 拷贝配置文件

在本地jprofiler的config目录下找到config.xml,打开,找到sessionid对应的session配置,拷贝到Linux安装目录的config.xml中

2-1-5 offline启动

在linux中,先启动服务进程,例如hermes启动三个jvm进程
然后,启动./bin/jpenable,会让选择attach到哪个进程,比如选择worker进程
然后让选择mode,
1)选择gui mode的话,会让确定端口,输入8849,回车;启动1.2.1中的session,进行连接(可能需要配置反向代理)
2)选择offlinemode的话,回车,粘贴配置文件目录名回车,选择1.2.1配置的sessioinid;启动jpcontroller,选择start recording->选择profile的项目,用逗号隔开->savesnapshot保存快照,导出快照文件,用jproviler打开

.3 设置

3-1 过滤器设置

如果不做过滤器设置,会统计出非常多不相关的类和方法信息,影响定位

3-1-1 class filter

  • profiled
    All methods of profiled packages are shown in the call tree. Start the filter list with this type to profile selected packages only.
  • compact
    The first call from a profiled class into a compact class is shown in the call tree, but further calls into compact classes are not measured separately. If the first filter is compact, no classes are profiled by default.
  • Ignored packages or classes are not profiled at all. If the first filter is ignored, all other classes are profiled by default.

3-1-2 Ignored Methods

这里会默认忽略很多方法,如果不配置一下,会在profiling时丢失信息

3-2 profilering 设置

可以配置dynamic instrumentation,即详细profiling,这样会导致统计过程非常慢;另外一种是sampling方式,即通过采样统计,比较快,对性能影响不大另外还可以配置cpu采样的时间等信息。

3-3 配置导出

选择session->export session settings,即可把这个session的配置导出成config.xml文件,可以用于offline模式

4 快照

可以把一个任何时间的profiling结果保存成snapshot,这样可以方便以后分析,也可以放到其他的机器上分析

5 profiling视图(最重要的部分)

5-1 内存视图

5-2 堆视图

5-3 cpu视图

5-3-1 总体描述

5-3-2 call tree view

The call tree doesn’t display all method calls in the JVM, it only displays

  • profiled classes
    Classes which are profiled according to your configured filter sets are used for the construction of the call tree.
  • first level calls into unprofiled classes
    Every call into a filtered class that originates from a profiled class is used for the construction of the call tree. Further calls into unprofiled classes are not resolved. This means that a filtered node can include information from other filtered calls. Filtered nodes are painted with a red marker in the top left corner.
  • thread entry methods
    The methods Runnable.run() and the main method are always displayed, regardless of the filter settings.

If enabled in the view settings, every node in the call tree has a size bar whose length is proportional to the total time spent in the current node including all descendant nodes and whose light-red part indicates the percentage of the self time of the current node.

5-3-3 hot-spot view

5-4 thread view

0 0