Java性能分析工具&&JProfiler

释放双眼,带上耳机,听听看~!

程序性能分析的起点其实与Java无关,它是一组操作系统自带的基本监控工具。

Unix系统中:

vmstata、iostat、prstat、top等

Window系统中:

typeperf等

typeperf -si 1 "\System\Processor Queue Length 显示CPU队列当前长度

系统本身的监控,有很多方法和工具,不多说。

====================================

JProfile可以在window和unix使用,其安装都非常方便,但需要注意的是被监控的应用要修改其启动的JAVA_OPTS参数,其中核心的两个参数分别是:

angent.jar 与 config.xml及id指向

config.xml默认可以在系统用户目录中找到
agent.jar默认可在jprofile的安装bin目录中找到(可以拷到单独目录)
id要与config.xml配置session id的保持一致

set JAVA_OPTS=%JAVA_OPTS%
-agentlib:jprofilerti=port=8849,nowait,id=80,config=D:\usr\config.xml -Xbootclasspath/a:D:\usr\agent.jar

在Unix下程序运行的配置:

#DEFAULT_JAVA_DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$JAVA_DEBUG_PORT -agentpath:/opt/jprofiler/bin/linux-x64/libjprofilerti.so=port=8849"

下面以主流的开发工具Intelligent为例,介绍下工具的使用:

1.在IDE中进行代码编写,在运行时加入上面的配置,如图:

程序启动

打印以上信息,则配置基本正确。

2.打开Jprofier工具开始进行性能分析

选中程序test2,开始监控

下面通过程序简单介绍性能分担问题:

下图中,可以看到gc线程一直在频繁运行当中。说明垃圾回收一直在执行。

查看代码:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
1 private int a;
2    private double b;
3    private String abc="acbsfdsfdaaaaaaaaaaaaaaaaaaa";
4    private BigInteger bigInteger=new BigInteger("3232342222222222");
5    private int a1;
6    private double b1;
7    private String abc1="acbsfdsfdaaaaaaaaaaaaaaaaaaa";
8    private BigInteger bigInteger1=new BigInteger("3232342222222222");
9
10    public static List list = new ArrayList();
11
12    public static void main(String[] args) {
13        while (true) {
14            for (int i = 0; i < 10000; i++) {
15                list.add(new ZooKeeperTest());
16            }
17            try {
18                TimeUnit.MILLISECONDS.sleep(5);
19            } catch (InterruptedException e) {
20                e.printStackTrace();
21            }
22        }
23    }
24

1
2
1 是由于list集合在频繁的写入数据导致的
2

该工具还有许多其它的标签,如hot spots,来做性能分析,屡试不爽的。

给TA打赏
共{{data.count}}人
人已打赏
安全技术

Bootstrap 间隔 (Spacing)

2021-12-21 16:36:11

安全技术

从零搭建自己的SpringBoot后台框架(二十三)

2022-1-12 12:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索